1
#pragma once
2

            
3
#include <cstdint>
4
#include <memory>
5

            
6
#include "envoy/common/pure.h"
7
#include "envoy/common/time.h"
8
#include "envoy/stats/histogram.h"
9
#include "envoy/stats/primitive_stats.h"
10
#include "envoy/stats/stats.h"
11

            
12
namespace Envoy {
13
namespace Stats {
14

            
15
class Histogram;
16

            
17
class MetricSnapshot {
18
public:
19
  struct CounterSnapshot {
20
    uint64_t delta_;
21
    std::reference_wrapper<const Counter> counter_;
22
  };
23

            
24
11959
  virtual ~MetricSnapshot() = default;
25

            
26
  /**
27
   * @return a snapshot of all counters with pre-latched deltas.
28
   */
29
  virtual const std::vector<CounterSnapshot>& counters() PURE;
30

            
31
  /**
32
   * @return a snapshot of all gauges.
33
   */
34
  virtual const std::vector<std::reference_wrapper<const Gauge>>& gauges() PURE;
35

            
36
  /**
37
   * @return a snapshot of all histograms.
38
   */
39
  virtual const std::vector<std::reference_wrapper<const ParentHistogram>>& histograms() PURE;
40

            
41
  /**
42
   * @return a snapshot of all text readouts.
43
   */
44
  virtual const std::vector<std::reference_wrapper<const TextReadout>>& textReadouts() PURE;
45

            
46
  /**
47
   * @return a snapshot of all host/endpoint-specific primitive counters.
48
   */
49
  virtual const std::vector<Stats::PrimitiveCounterSnapshot>& hostCounters() PURE;
50

            
51
  /**
52
   * @return a snapshot of all host/endpoint-specific primitive gauges.
53
   */
54
  virtual const std::vector<Stats::PrimitiveGaugeSnapshot>& hostGauges() PURE;
55

            
56
  /**
57
   * @return the time in UTC since epoch when the snapshot was created.
58
   */
59
  virtual SystemTime snapshotTime() const PURE;
60
};
61

            
62
/**
63
 * A class to define predicates to filter counters, gauges and text readouts for flushing to sinks.
64
 */
65
class SinkPredicates {
66
public:
67
12
  virtual ~SinkPredicates() = default;
68

            
69
  /**
70
   * @return true if @param counter needs to be flushed to sinks.
71
   */
72
  virtual bool includeCounter(const Counter& counter) PURE;
73

            
74
  /**
75
   * @return true if @param gauge needs to be flushed to sinks.
76
   */
77
  virtual bool includeGauge(const Gauge& gauge) PURE;
78

            
79
  /**
80
   * @return true if @param text_readout needs to be flushed to sinks.
81
   */
82
  virtual bool includeTextReadout(const TextReadout& text_readout) PURE;
83

            
84
  /*
85
   * @return true if @param histogram needs to be flushed to sinks.
86
   */
87
  virtual bool includeHistogram(const Histogram& histogram) PURE;
88
};
89

            
90
/**
91
 * A sink for stats. Each sink is responsible for writing stats to a backing store.
92
 */
93
class Sink {
94
public:
95
219
  virtual ~Sink() = default;
96

            
97
  /**
98
   * Periodic metric flush to the sink.
99
   * @param snapshot interface through which the sink can access all metrics being flushed.
100
   */
101
  virtual void flush(MetricSnapshot& snapshot) PURE;
102

            
103
  /**
104
   * Flush a single histogram sample. Note: this call is called synchronously as a part of recording
105
   * the metric, so implementations must be thread-safe.
106
   * @param histogram the histogram that this sample applies to.
107
   * @param value the value of the sample.
108
   */
109
  virtual void onHistogramComplete(const Histogram& histogram, uint64_t value) PURE;
110
};
111

            
112
using SinkPtr = std::unique_ptr<Sink>;
113

            
114
} // namespace Stats
115
} // namespace Envoy