1
#include "source/common/stats/tag_utility.h"
2

            
3
#include <regex>
4

            
5
#include "source/common/config/well_known_names.h"
6
#include "source/common/stats/symbol_table.h"
7

            
8
namespace Envoy {
9
namespace Stats {
10
namespace TagUtility {
11

            
12
TagStatNameJoiner::TagStatNameJoiner(StatName prefix, StatName stat_name,
13
                                     StatNameTagVectorOptConstRef stat_name_tags,
14
59784905
                                     SymbolTable& symbol_table) {
15
59784905
  prefix_storage_ = symbol_table.join({prefix, stat_name});
16
59784905
  tag_extracted_name_ = StatName(prefix_storage_.get());
17

            
18
59784905
  if (stat_name_tags) {
19
3877
    full_name_storage_ =
20
3877
        joinNameAndTags(StatName(prefix_storage_.get()), *stat_name_tags, symbol_table);
21
3877
    name_with_tags_ = StatName(full_name_storage_.get());
22
59781029
  } else {
23
59781028
    name_with_tags_ = StatName(prefix_storage_.get());
24
59781028
  }
25
59784905
}
26

            
27
SymbolTable::StoragePtr TagStatNameJoiner::joinNameAndTags(StatName name,
28
                                                           const StatNameTagVector& tags,
29
3877
                                                           SymbolTable& symbol_table) {
30
3877
  StatNameVec stat_names;
31
3877
  stat_names.reserve(1 + 2 * tags.size());
32
3877
  stat_names.emplace_back(name);
33

            
34
5773
  for (const auto& tag : tags) {
35
5672
    stat_names.emplace_back(tag.first);
36
5672
    stat_names.emplace_back(tag.second);
37
5672
  }
38

            
39
3877
  return symbol_table.join(stat_names);
40
3877
}
41

            
42
7
bool isTagValueValid(absl::string_view name) {
43
7
  return Config::doesTagNameValueMatchInvalidCharRegex(name);
44
7
}
45

            
46
8
bool isTagNameValid(absl::string_view value) {
47
23
  for (const auto& token : value) {
48
23
    if (!absl::ascii_isalnum(token)) {
49
1
      return false;
50
1
    }
51
23
  }
52
7
  return true;
53
8
}
54

            
55
} // namespace TagUtility
56
} // namespace Stats
57
} // namespace Envoy