// Copyright 2023 gRPC authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "observability_util.h" #include #include #include #include #include "absl/status/statusor.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "client_call_tracer.h" #include "constants.h" #include "python_observability_context.h" #include "server_call_tracer.h" namespace grpc_observability { std::queue* g_census_data_buffer; std::mutex g_census_data_buffer_mutex; std::condition_variable g_census_data_buffer_cv; // TODO(xuanwn): Change below to a more appropriate number. // Assume buffer will store 100 CensusData and start export when buffer is 70% // full. constexpr float kExportThreshold = 0.7; constexpr int kMaxExportBufferSize = 10000; namespace { float GetExportThreadHold() { const char* value = std::getenv("GRPC_PYTHON_CENSUS_EXPORT_THRESHOLD"); if (value != nullptr) { return std::stof(value); } return kExportThreshold; } int GetMaxExportBufferSize() { const char* value = std::getenv("GRPC_PYTHON_CENSUS_MAX_EXPORT_BUFFER_SIZE"); if (value != nullptr) { return std::stoi(value); } return kMaxExportBufferSize; } } // namespace void RecordIntMetric(MetricsName name, int64_t value, const std::vector