]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright The OpenTelemetry Authors |
2 | // SPDX-License-Identifier: Apache-2.0 | |
3 | ||
4 | #pragma once | |
5 | #include "opentelemetry/nostd/string_view.h" | |
6 | #include "opentelemetry/sdk/metrics/view/predicate.h" | |
7 | #ifndef ENABLE_METRICS_PREVIEW | |
8 | OPENTELEMETRY_BEGIN_NAMESPACE | |
9 | namespace sdk | |
10 | { | |
11 | namespace metrics | |
12 | { | |
13 | ||
14 | enum class PredicateType : uint8_t | |
15 | { | |
16 | kPattern, | |
17 | kExact | |
18 | }; | |
19 | ||
20 | class PredicateFactory | |
21 | { | |
22 | public: | |
23 | static std::unique_ptr<Predicate> GetPredicate(opentelemetry::nostd::string_view pattern, | |
24 | PredicateType type) | |
25 | { | |
26 | if ((type == PredicateType::kPattern && pattern == "*") || | |
27 | (type == PredicateType::kExact && pattern == "")) | |
28 | { | |
29 | return std::move(std::unique_ptr<Predicate>(new MatchEverythingPattern())); | |
30 | } | |
31 | if (type == PredicateType::kPattern) | |
32 | { | |
33 | return std::move(std::unique_ptr<Predicate>(new PatternPredicate(pattern))); | |
34 | } | |
35 | if (type == PredicateType::kExact) | |
36 | { | |
37 | return std::move(std::unique_ptr<Predicate>(new ExactPredicate(pattern))); | |
38 | } | |
39 | return std::move(std::unique_ptr<Predicate>(new MatchNothingPattern())); | |
40 | } | |
41 | }; | |
42 | } // namespace metrics | |
43 | } // namespace sdk | |
44 | OPENTELEMETRY_END_NAMESPACE | |
45 | #endif |