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 Http2 {
12

            
13
/**
14
 * All stats for the HTTP/2 codec. @see stats_macros.h
15
 */
16
#define ALL_HTTP2_CODEC_STATS(COUNTER, GAUGE)                                                      \
17
25612
  COUNTER(dropped_headers_with_underscores)                                                        \
18
25612
  COUNTER(goaway_sent)                                                                             \
19
25612
  COUNTER(header_overflow)                                                                         \
20
25612
  COUNTER(headers_cb_no_stream)                                                                    \
21
25612
  COUNTER(inbound_empty_frames_flood)                                                              \
22
25612
  COUNTER(inbound_priority_frames_flood)                                                           \
23
25612
  COUNTER(inbound_window_update_frames_flood)                                                      \
24
25612
  COUNTER(keepalive_timeout)                                                                       \
25
25612
  COUNTER(metadata_empty_frames)                                                                   \
26
25612
  COUNTER(outbound_control_flood)                                                                  \
27
25612
  COUNTER(outbound_flood)                                                                          \
28
25612
  COUNTER(requests_rejected_with_underscores_in_headers)                                           \
29
25612
  COUNTER(rx_messaging_error)                                                                      \
30
25612
  COUNTER(rx_reset)                                                                                \
31
25612
  COUNTER(stream_refused_errors)                                                                   \
32
25612
  COUNTER(trailers)                                                                                \
33
25612
  COUNTER(tx_flush_timeout)                                                                        \
34
25612
  COUNTER(tx_reset)                                                                                \
35
25612
  GAUGE(streams_active, Accumulate)                                                                \
36
25612
  GAUGE(pending_send_bytes, Accumulate)                                                            \
37
25612
  GAUGE(deferred_stream_close, Accumulate)                                                         \
38
25612
  GAUGE(outbound_frames_active, Accumulate)                                                        \
39
25612
  GAUGE(outbound_control_frames_active, Accumulate)
40
/**
41
 * Wrapper struct for the HTTP/2 codec stats. @see stats_macros.h
42
 */
43
struct CodecStats : public ::Envoy::Http::HeaderValidatorStats {
44
  using AtomicPtr = Thread::AtomicPtr<CodecStats, Thread::AtomicPtrAllocMode::DeleteOnDestruct>;
45

            
46
  CodecStats(ALL_HTTP2_CODEC_STATS(GENERATE_CONSTRUCTOR_COUNTER_PARAM,
47
                                   GENERATE_CONSTRUCTOR_GAUGE_PARAM)...)
48
25612
      : ::Envoy::Http::HeaderValidatorStats()
49
25612
            ALL_HTTP2_CODEC_STATS(GENERATE_CONSTRUCTOR_INIT_LIST, GENERATE_CONSTRUCTOR_INIT_LIST) {}
50

            
51
30435
  static CodecStats& atomicGet(AtomicPtr& ptr, Stats::Scope& scope) {
52
30435
    return *ptr.get([&scope]() -> CodecStats* {
53
25612
      return new CodecStats{ALL_HTTP2_CODEC_STATS(POOL_COUNTER_PREFIX(scope, "http2."),
54
25612
                                                  POOL_GAUGE_PREFIX(scope, "http2."))};
55
25612
    });
56
30435
  }
57

            
58
12
  void incDroppedHeadersWithUnderscores() override { dropped_headers_with_underscores_.inc(); }
59
10
  void incRequestsRejectedWithUnderscoresInHeaders() override {
60
10
    requests_rejected_with_underscores_in_headers_.inc();
61
10
  }
62
  void incMessagingError() override { rx_messaging_error_.inc(); }
63

            
64
  ALL_HTTP2_CODEC_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT)
65
};
66

            
67
} // namespace Http2
68
} // namespace Http
69
} // namespace Envoy