3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef GRPC_INTERNAL_CPP_EXT_FILTERS_CENSUS_SERVER_FILTER_H
20 #define GRPC_INTERNAL_CPP_EXT_FILTERS_CENSUS_SERVER_FILTER_H
22 #include <grpc/support/port_platform.h>
24 #include "absl/strings/string_view.h"
25 #include "absl/time/clock.h"
26 #include "absl/time/time.h"
28 #include <grpc/grpc_security.h>
30 #include "src/cpp/ext/filters/census/channel_filter.h"
31 #include "src/cpp/ext/filters/census/context.h"
35 // A CallData class will be created for every grpc call within a channel. It is
36 // used to store data and methods specific to that call. CensusServerCallData is
37 // thread-compatible, however typically only 1 thread should be interacting with
39 class CensusServerCallData : public CallData {
41 // Maximum size of server stats that are sent on the wire.
42 static constexpr uint32_t kMaxServerStatsLen = 16;
44 CensusServerCallData()
46 auth_context_(nullptr),
47 recv_initial_metadata_(nullptr),
48 initial_on_done_recv_initial_metadata_(nullptr),
49 initial_on_done_recv_message_(nullptr),
50 recv_message_(nullptr),
51 recv_message_count_(0),
52 sent_message_count_(0) {
53 memset(&census_bin_, 0, sizeof(grpc_linked_mdelem));
54 memset(&path_, 0, sizeof(grpc_slice));
55 memset(&on_done_recv_initial_metadata_, 0, sizeof(grpc_closure));
56 memset(&on_done_recv_message_, 0, sizeof(grpc_closure));
59 grpc_error_handle Init(grpc_call_element* elem,
60 const grpc_call_element_args* args) override;
62 void Destroy(grpc_call_element* elem, const grpc_call_final_info* final_info,
63 grpc_closure* then_call_closure) override;
65 void StartTransportStreamOpBatch(grpc_call_element* elem,
66 TransportStreamOpBatch* op) override;
68 static void OnDoneRecvInitialMetadataCb(void* user_data,
69 grpc_error_handle error);
71 static void OnDoneRecvMessageCb(void* user_data, grpc_error_handle error);
74 CensusContext context_;
76 absl::string_view method_;
77 std::string qualified_method_;
79 // Pointer to the grpc_call element
81 // Authorization context for the call.
82 grpc_auth_context* auth_context_;
83 // Metadata element for census stats.
84 grpc_linked_mdelem census_bin_;
86 grpc_metadata_batch* recv_initial_metadata_;
87 grpc_closure* initial_on_done_recv_initial_metadata_;
88 grpc_closure on_done_recv_initial_metadata_;
90 grpc_closure* initial_on_done_recv_message_;
91 grpc_closure on_done_recv_message_;
92 absl::Time start_time_;
93 absl::Duration elapsed_time_;
94 grpc_core::OrphanablePtr<grpc_core::ByteStream>* recv_message_;
95 uint64_t recv_message_count_;
96 uint64_t sent_message_count_;
97 // Buffer needed for grpc_slice to reference it when adding metatdata to
99 char stats_buf_[kMaxServerStatsLen];
104 #endif /* GRPC_INTERNAL_CPP_EXT_FILTERS_CENSUS_SERVER_FILTER_H */