/proc/self/cwd/source/extensions/filters/common/ratelimit/stat_names.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "source/common/common/empty_string.h" |
4 | | #include "source/common/stats/symbol_table.h" |
5 | | |
6 | | namespace Envoy { |
7 | | namespace Extensions { |
8 | | namespace Filters { |
9 | | namespace Common { |
10 | | namespace RateLimit { |
11 | | |
12 | | // Captures a set of stat-names needed for recording during rate-limit |
13 | | // filters. These should generally be initialized once per process, and |
14 | | // not per-request, to avoid lock contention. |
15 | | struct StatNames { |
16 | | explicit StatNames(Stats::SymbolTable& symbol_table, |
17 | | const std::string& stat_prefix = EMPTY_STRING) |
18 | | : pool_(symbol_table), ok_(pool_.add(createPoolStatName(stat_prefix, "ok"))), |
19 | | error_(pool_.add(createPoolStatName(stat_prefix, "error"))), |
20 | | failure_mode_allowed_(pool_.add(createPoolStatName(stat_prefix, "failure_mode_allowed"))), |
21 | 15 | over_limit_(pool_.add(createPoolStatName(stat_prefix, "over_limit"))) {} |
22 | | |
23 | | // This generates ratelimit.<optional stat_prefix>.name |
24 | 60 | const std::string createPoolStatName(const std::string& stat_prefix, const std::string& name) { |
25 | 60 | return absl::StrCat("ratelimit", |
26 | 60 | stat_prefix.empty() ? EMPTY_STRING : absl::StrCat(".", stat_prefix), ".", |
27 | 60 | name); |
28 | 60 | } |
29 | | Stats::StatNamePool pool_; |
30 | | Stats::StatName ok_; |
31 | | Stats::StatName error_; |
32 | | Stats::StatName failure_mode_allowed_; |
33 | | Stats::StatName over_limit_; |
34 | | }; |
35 | | |
36 | | } // namespace RateLimit |
37 | | } // namespace Common |
38 | | } // namespace Filters |
39 | | } // namespace Extensions |
40 | | } // namespace Envoy |