LCOV - code coverage report
Current view: top level - envoy/stats - sink.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 1 3 33.3 %
Date: 2024-01-05 06:35:25 Functions: 1 3 33.3 %

          Line data    Source code
       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         111 :   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           0 :   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             :    * Note that this is used only if runtime flag envoy.reloadable_features.enable_include_histograms
      87             :    * (which is false by default) is set to true.
      88             :    */
      89             :   virtual bool includeHistogram(const Histogram& histogram) PURE;
      90             : };
      91             : 
      92             : /**
      93             :  * A sink for stats. Each sink is responsible for writing stats to a backing store.
      94             :  */
      95             : class Sink {
      96             : public:
      97           0 :   virtual ~Sink() = default;
      98             : 
      99             :   /**
     100             :    * Periodic metric flush to the sink.
     101             :    * @param snapshot interface through which the sink can access all metrics being flushed.
     102             :    */
     103             :   virtual void flush(MetricSnapshot& snapshot) PURE;
     104             : 
     105             :   /**
     106             :    * Flush a single histogram sample. Note: this call is called synchronously as a part of recording
     107             :    * the metric, so implementations must be thread-safe.
     108             :    * @param histogram the histogram that this sample applies to.
     109             :    * @param value the value of the sample.
     110             :    */
     111             :   virtual void onHistogramComplete(const Histogram& histogram, uint64_t value) PURE;
     112             : };
     113             : 
     114             : using SinkPtr = std::unique_ptr<Sink>;
     115             : 
     116             : } // namespace Stats
     117             : } // namespace Envoy

Generated by: LCOV version 1.15