orca_interceptor.cc
Go to the documentation of this file.
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 
18 
19 #include <algorithm>
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <type_traits>
24 #include <utility>
25 #include <vector>
26 
27 #include "absl/memory/memory.h"
28 #include "absl/strings/string_view.h"
29 #include "absl/types/optional.h"
30 
32 #include <grpcpp/server_builder.h>
33 #include <grpcpp/server_context.h>
34 #include <grpcpp/support/config.h>
35 
37 
38 namespace grpc {
39 namespace experimental {
40 
42  if (methods->QueryInterceptionHookPoint(
44  auto context = info_->server_context();
45  context->CreateCallMetricRecorder();
46  } else if (methods->QueryInterceptionHookPoint(
48  auto trailers = methods->GetSendTrailingMetadata();
49  if (trailers != nullptr) {
50  auto context = info_->server_context();
51  auto* recorder = context->call_metric_recorder_;
52  auto serialized = recorder->CreateSerializedReport();
53  if (serialized.has_value() && !serialized->empty()) {
56  trailers->emplace(
57  std::make_pair(std::move(key), std::move(serialized.value())));
58  }
59  }
60  }
61  methods->Proceed();
62 }
63 
65  ServerRpcInfo* info) {
66  return new OrcaServerInterceptor(info);
67 }
68 
70  builder->internal_interceptor_creators_.push_back(
71  absl::make_unique<OrcaServerInterceptorFactory>());
72 }
73 
76 }
77 
78 } // namespace experimental
79 } // namespace grpc
metadata_batch.h
grpc
Definition: grpcpp/alarm.h:33
grpc::experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA
@ POST_RECV_INITIAL_METADATA
The following two are for all clients and servers.
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::experimental::ServerRpcInfo::server_context
ServerContextBase * server_context()
Definition: impl/codegen/server_interceptor.h:81
grpc::experimental::InterceptorBatchMethods::QueryInterceptionHookPoint
virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type)=0
grpc::experimental::InterceptionHookPoints::PRE_SEND_STATUS
@ PRE_SEND_STATUS
profile_analyzer.builder
builder
Definition: profile_analyzer.py:159
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc::ServerBuilder
A builder class for the creation and startup of grpc::Server instances.
Definition: grpcpp/server_builder.h:86
grpc::experimental::InterceptorBatchMethods::GetSendTrailingMetadata
virtual std::multimap< std::string, std::string > * GetSendTrailingMetadata()=0
grpc::experimental::OrcaServerInterceptor
Definition: orca_interceptor.h:30
grpc_core::EndpointLoadMetricsBinMetadata::key
static absl::string_view key()
Definition: metadata_batch.h:234
call_metric_recorder.h
grpc::experimental::OrcaServerInterceptorFactory::Register
static void Register(ServerBuilder *builder)
Definition: orca_interceptor.cc:69
config.h
grpc::experimental::InterceptorBatchMethods
Definition: impl/codegen/interceptor.h:98
grpc::experimental::OrcaServerInterceptor::info_
ServerRpcInfo * info_
Definition: orca_interceptor.h:37
grpc::experimental::OrcaServerInterceptorFactory::CreateServerInterceptor
Interceptor * CreateServerInterceptor(ServerRpcInfo *info) override
Definition: orca_interceptor.cc:64
key
const char * key
Definition: hpack_parser_table.cc:164
grpc::experimental::EnableCallMetricRecording
void EnableCallMetricRecording(ServerBuilder *)
Definition: orca_interceptor.cc:74
grpc::experimental::Interceptor
Definition: impl/codegen/interceptor.h:221
server_context.h
grpc::experimental::ServerRpcInfo
Definition: impl/codegen/server_interceptor.h:58
grpc::experimental::OrcaServerInterceptor::Intercept
void Intercept(InterceptorBatchMethods *methods) override
Definition: orca_interceptor.cc:41
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
grpc::experimental::InterceptorBatchMethods::Proceed
virtual void Proceed()=0
orca_interceptor.h
server_builder.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:46