1 // 2 // Copyright 2022 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_LOAD_BALANCING_OOB_BACKEND_METRIC_H 18 #define GRPC_SRC_CORE_LOAD_BALANCING_OOB_BACKEND_METRIC_H 19 20 #include <grpc/support/port_platform.h> 21 22 #include <memory> 23 24 #include "src/core/lib/gprpp/time.h" 25 #include "src/core/load_balancing/backend_metric_data.h" 26 #include "src/core/load_balancing/subchannel_interface.h" 27 28 namespace grpc_core { 29 30 // Interface for LB policies to access out-of-band backend metric data 31 // from a subchannel. The data is reported from via an ORCA stream 32 // established on the subchannel whenever an LB policy registers a 33 // watcher. 34 // 35 // To use this, an LB policy will implement its own subclass of 36 // OobBackendMetricWatcher, which will receive backend metric data as it 37 // is sent by the server. It will then register that watcher with the 38 // subchannel like this: 39 // subchannel->AddDataWatcher( 40 // MakeOobBackendMetricWatcher( 41 // std::make_unique<MyOobBackendMetricWatcherSubclass>(...))); 42 43 class OobBackendMetricWatcher { 44 public: 45 virtual ~OobBackendMetricWatcher() = default; 46 47 virtual void OnBackendMetricReport( 48 const BackendMetricData& backend_metric_data) = 0; 49 }; 50 51 std::unique_ptr<SubchannelInterface::DataWatcherInterface> 52 MakeOobBackendMetricWatcher(Duration report_interval, 53 std::unique_ptr<OobBackendMetricWatcher> watcher); 54 55 } // namespace grpc_core 56 57 #endif // GRPC_SRC_CORE_LOAD_BALANCING_OOB_BACKEND_METRIC_H 58