1
#pragma once
2

            
3
#include "envoy/http/header_validator.h"
4
#include "envoy/stats/scope.h"
5
#include "envoy/stats/stats_macros.h"
6

            
7
#include "source/common/common/thread.h"
8

            
9
namespace Envoy {
10
namespace Http {
11
namespace Http3 {
12

            
13
/**
14
 * All stats for the HTTP/3 codec. @see stats_macros.h
15
 */
16
#define ALL_HTTP3_CODEC_STATS(COUNTER, GAUGE)                                                      \
17
4837
  COUNTER(dropped_headers_with_underscores)                                                        \
18
4837
  COUNTER(requests_rejected_with_underscores_in_headers)                                           \
19
4837
  COUNTER(rx_reset)                                                                                \
20
4837
  COUNTER(tx_reset)                                                                                \
21
4837
  COUNTER(metadata_not_supported_error)                                                            \
22
4837
  COUNTER(quic_version_h3_29)                                                                      \
23
4837
  COUNTER(quic_version_rfc_v1)                                                                     \
24
4837
  COUNTER(tx_flush_timeout)
25

            
26
/**
27
 * Wrapper struct for the HTTP/3 codec stats. @see stats_macros.h
28
 */
29
struct CodecStats : public ::Envoy::Http::HeaderValidatorStats {
30
  using AtomicPtr = Thread::AtomicPtr<CodecStats, Thread::AtomicPtrAllocMode::DeleteOnDestruct>;
31

            
32
  CodecStats(ALL_HTTP3_CODEC_STATS(GENERATE_CONSTRUCTOR_COUNTER_PARAM,
33
                                   GENERATE_CONSTRUCTOR_GAUGE_PARAM)...)
34
4837
      : ::Envoy::Http::HeaderValidatorStats()
35
4837
            ALL_HTTP3_CODEC_STATS(GENERATE_CONSTRUCTOR_INIT_LIST, GENERATE_CONSTRUCTOR_INIT_LIST) {}
36

            
37
5857
  static CodecStats& atomicGet(AtomicPtr& ptr, Stats::Scope& scope) {
38
5857
    return *ptr.get([&scope]() -> CodecStats* {
39
4626
      return new CodecStats{ALL_HTTP3_CODEC_STATS(POOL_COUNTER_PREFIX(scope, "http3."),
40
4626
                                                  POOL_GAUGE_PREFIX(scope, "http3."))};
41
4626
    });
42
5857
  }
43

            
44
6
  void incDroppedHeadersWithUnderscores() override { dropped_headers_with_underscores_.inc(); }
45
2
  void incRequestsRejectedWithUnderscoresInHeaders() override {
46
2
    requests_rejected_with_underscores_in_headers_.inc();
47
2
  }
48
  // TODO(yanavlasov): add corresponding counter for H/3 codec.
49
  void incMessagingError() override {}
50

            
51
  ALL_HTTP3_CODEC_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT)
52
};
53

            
54
} // namespace Http3
55
} // namespace Http
56
} // namespace Envoy