1
#pragma once
2

            
3
#include <string>
4

            
5
#include "envoy/common/optref.h"
6
#include "envoy/config/metrics/v3/stats.pb.h"
7
#include "envoy/stats/stats_matcher.h"
8

            
9
#include "source/common/common/matchers.h"
10
#include "source/common/protobuf/protobuf.h"
11
#include "source/common/stats/symbol_table.h"
12

            
13
#include "absl/strings/string_view.h"
14

            
15
namespace Envoy {
16
namespace Stats {
17

            
18
/**
19
 * Supplies a stats matcher.
20
 */
21
class StatsMatcherImpl : public StatsMatcher {
22
public:
23
  StatsMatcherImpl(const envoy::config::metrics::v3::StatsConfig& config, SymbolTable& symbol_table,
24
                   Server::Configuration::CommonFactoryContext& context);
25

            
26
  // Default constructor simply allows everything.
27
10800
  StatsMatcherImpl() = default;
28

            
29
  // StatsMatcher
30
317
  bool rejects(StatName name) const override {
31
317
    FastResult fast_result = fastRejects(name);
32
317
    return fast_result == FastResult::Rejects || slowRejects(fast_result, name);
33
317
  }
34
  FastResult fastRejects(StatName name) const override;
35
  bool slowRejects(FastResult, StatName name) const override;
36
5466650
  bool acceptsAll() const override {
37
5466650
    return is_inclusive_ && matchers_.empty() && prefixes_.empty();
38
5466650
  }
39
11920140
  bool rejectsAll() const override {
40
11920140
    return !is_inclusive_ && matchers_.empty() && prefixes_.empty();
41
11920140
  }
42

            
43
private:
44
  void optimizeLastMatcher();
45
  bool fastRejectMatch(StatName name) const;
46
  bool slowRejectMatch(StatName name) const;
47

            
48
  // Bool indicating whether or not the StatsMatcher is including or excluding stats by default. See
49
  // StatsMatcherImpl::rejects() for much more detail.
50
  bool is_inclusive_{true};
51

            
52
  OptRef<SymbolTable> symbol_table_;
53
  std::unique_ptr<StatNamePool> stat_name_pool_;
54

            
55
  std::vector<Matchers::StringMatcherImpl> matchers_;
56
  std::vector<StatName> prefixes_;
57
};
58

            
59
} // namespace Stats
60
} // namespace Envoy