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

            
3
#include "source/common/common/assert.h"
4
#include "source/common/common/thread.h"
5

            
6
namespace Envoy {
7
namespace Stats {
8

            
9
33
bool CustomStatNamespacesImpl::registered(const absl::string_view name) const {
10
33
  ASSERT_IS_MAIN_OR_TEST_THREAD();
11
33
  return namespaces_.find(name) != namespaces_.end();
12
33
}
13

            
14
119
void CustomStatNamespacesImpl::registerStatNamespace(const absl::string_view name) {
15
119
  ASSERT_IS_MAIN_OR_TEST_THREAD();
16
119
  namespaces_.insert(std::string(name));
17
119
};
18

            
19
absl::optional<absl::string_view>
20
2901
CustomStatNamespacesImpl::stripRegisteredPrefix(const absl::string_view stat_name) const {
21
2901
  ASSERT_IS_MAIN_OR_TEST_THREAD();
22
2901
  if (!namespaces_.empty()) {
23
20
    const auto pos = stat_name.find_first_of('.');
24
20
    if (pos != std::string::npos && registered(stat_name.substr(0, pos))) {
25
      // Trim the custom namespace.
26
6
      return stat_name.substr(pos + 1);
27
6
    }
28
20
  }
29
2895
  return absl::nullopt;
30
2901
};
31

            
32
} // namespace Stats
33
} // namespace Envoy