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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <chrono>
       4             : #include <cstdint>
       5             : #include <functional>
       6             : #include <list>
       7             : #include <memory>
       8             : #include <string>
       9             : #include <vector>
      10             : 
      11             : #include "envoy/common/pure.h"
      12             : #include "envoy/stats/stats.h"
      13             : #include "envoy/stats/tag.h"
      14             : 
      15             : #include "absl/strings/string_view.h"
      16             : 
      17             : namespace Envoy {
      18             : namespace Stats {
      19             : 
      20             : class Sink;
      21             : class SinkPredicates;
      22             : 
      23             : /**
      24             :  * Abstract interface for allocating statistics. Implementations can
      25             :  * be created utilizing a single fixed-size block suitable for
      26             :  * shared-memory, or in the heap, allowing for pointers and sharing of
      27             :  * substrings, with an opportunity for reduced memory consumption.
      28             :  */
      29             : class Allocator {
      30             : public:
      31       21460 :   virtual ~Allocator() = default;
      32             : 
      33             :   /**
      34             :    * @param name the full name of the stat.
      35             :    * @param tag_extracted_name the name of the stat with tag-values stripped out.
      36             :    * @param tags the tag values.
      37             :    * @return CounterSharedPtr a counter.
      38             :    */
      39             :   virtual CounterSharedPtr makeCounter(StatName name, StatName tag_extracted_name,
      40             :                                        const StatNameTagVector& stat_name_tags) PURE;
      41             : 
      42             :   /**
      43             :    * @param name the full name of the stat.
      44             :    * @param tag_extracted_name the name of the stat with tag-values stripped out.
      45             :    * @param stat_name_tags the tag values.
      46             :    * @return GaugeSharedPtr a gauge.
      47             :    */
      48             :   virtual GaugeSharedPtr makeGauge(StatName name, StatName tag_extracted_name,
      49             :                                    const StatNameTagVector& stat_name_tags,
      50             :                                    Gauge::ImportMode import_mode) PURE;
      51             : 
      52             :   /**
      53             :    * @param name the full name of the stat.
      54             :    * @param tag_extracted_name the name of the stat with tag-values stripped out.
      55             :    * @param tags the tag values.
      56             :    * @return TextReadoutSharedPtr a text readout.
      57             :    */
      58             :   virtual TextReadoutSharedPtr makeTextReadout(StatName name, StatName tag_extracted_name,
      59             :                                                const StatNameTagVector& stat_name_tags) PURE;
      60             :   virtual const SymbolTable& constSymbolTable() const PURE;
      61             :   virtual SymbolTable& symbolTable() PURE;
      62             : 
      63             :   /**
      64             :    * Mark rejected stats as deleted by moving them to a different vector, so they don't show up
      65             :    * when iterating over stats, but prevent crashes when trying to access references to them.
      66             :    * Note that allocating a stat with the same name after calling this will
      67             :    * return a new stat. Hence callers should seek to avoid this situation, as is
      68             :    * done in ThreadLocalStore.
      69             :    */
      70             :   virtual void markCounterForDeletion(const CounterSharedPtr& counter) PURE;
      71             :   virtual void markGaugeForDeletion(const GaugeSharedPtr& gauge) PURE;
      72             :   virtual void markTextReadoutForDeletion(const TextReadoutSharedPtr& text_readout) PURE;
      73             : 
      74             :   /**
      75             :    * Iterate over all stats. Note, that implementations can potentially hold on to a mutex that
      76             :    * will deadlock if the passed in functors try to create or delete a stat.
      77             :    * @param f_size functor that is provided the current number of all stats. Note that this is
      78             :    * called only once, prior to any calls to f_stat.
      79             :    * @param f_stat functor that is provided one stat at a time from the stats container.
      80             :    */
      81             :   virtual void forEachCounter(SizeFn f_size, StatFn<Counter> f_stat) const PURE;
      82             :   virtual void forEachGauge(SizeFn f_size, StatFn<Gauge> f_stat) const PURE;
      83             :   virtual void forEachTextReadout(SizeFn f_size, StatFn<TextReadout> f_stat) const PURE;
      84             : 
      85             :   /**
      86             :    * Iterate over all stats that need to be flushed to sinks. Note, that implementations can
      87             :    * potentially hold on to a mutex that will deadlock if the passed in functors try to create
      88             :    * or delete a stat.
      89             :    * @param f_size functor that is provided the number of all stats that will be flushed to sinks.
      90             :    * Note that this is called only once, prior to any calls to f_stat.
      91             :    * @param f_stat functor that is provided one stat that will be flushed to sinks, at a time.
      92             :    */
      93             :   virtual void forEachSinkedCounter(SizeFn f_size, StatFn<Counter> f_stat) const PURE;
      94             :   virtual void forEachSinkedGauge(SizeFn f_size, StatFn<Gauge> f_stat) const PURE;
      95             :   virtual void forEachSinkedTextReadout(SizeFn f_size, StatFn<TextReadout> f_stat) const PURE;
      96             : 
      97             :   /**
      98             :    * Set the predicates to filter stats for sink.
      99             :    */
     100             :   virtual void setSinkPredicates(std::unique_ptr<SinkPredicates>&& sink_predicates) PURE;
     101             : 
     102             :   // TODO(jmarantz): create a parallel mechanism to instantiate histograms. At
     103             :   // the moment, histograms don't fit the same pattern of counters and gauges
     104             :   // as they are not actually created in the context of a stats allocator.
     105             : };
     106             : 
     107             : } // namespace Stats
     108             : } // namespace Envoy

Generated by: LCOV version 1.15