1 // 2 // Copyright 2024 gRPC authors. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef GRPC_SRC_CORE_XDS_XDS_CLIENT_XDS_BACKEND_METRIC_PROPAGATION_H 18 #define GRPC_SRC_CORE_XDS_XDS_CLIENT_XDS_BACKEND_METRIC_PROPAGATION_H 19 20 #include <string> 21 22 #include "absl/container/flat_hash_set.h" 23 #include "src/core/util/ref_counted.h" 24 #include "src/core/util/ref_counted_ptr.h" 25 26 namespace grpc_core { 27 28 struct BackendMetricPropagation : public RefCounted<BackendMetricPropagation> { 29 static constexpr uint8_t kCpuUtilization = 1; 30 static constexpr uint8_t kMemUtilization = 2; 31 static constexpr uint8_t kApplicationUtilization = 4; 32 static constexpr uint8_t kNamedMetricsAll = 8; 33 34 uint8_t propagation_bits = 0; 35 absl::flat_hash_set<std::string> named_metric_keys; 36 37 std::string AsString() const; 38 39 bool operator==(const BackendMetricPropagation& other) const { 40 return propagation_bits == other.propagation_bits && 41 named_metric_keys == other.named_metric_keys; 42 } 43 44 bool operator<(const BackendMetricPropagation& other) const; 45 46 // Sorting functor for RefCountedPtr<const BackendMetricPropagation>. 47 struct Less { operatorBackendMetricPropagation::Less48 bool operator()( 49 const RefCountedPtr<const BackendMetricPropagation>& p1, 50 const RefCountedPtr<const BackendMetricPropagation>& p2) const { 51 if (p1 == nullptr || p2 == nullptr) return p1.get() < p2.get(); 52 return *p1 < *p2; 53 } 54 }; 55 }; 56 57 } // namespace grpc_core 58 59 #endif // GRPC_SRC_CORE_XDS_XDS_CLIENT_XDS_BACKEND_METRIC_PROPAGATION_H 60