xds_client_stats.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18 
20 
22 
23 #include <grpc/support/log.h>
24 
28 
29 namespace grpc_core {
30 
31 namespace {
32 
33 uint64_t GetAndResetCounter(std::atomic<uint64_t>* from) {
34  return from->exchange(0, std::memory_order_relaxed);
35 }
36 
37 } // namespace
38 
39 //
40 // XdsClusterDropStats
41 //
42 
44  RefCountedPtr<XdsClient> xds_client,
48  ? "XdsClusterDropStats"
49  : nullptr),
50  xds_client_(std::move(xds_client)),
51  lrs_server_(lrs_server),
55  gpr_log(GPR_INFO, "[xds_client %p] created drop stats %p for {%s, %s, %s}",
56  xds_client_.get(), this, lrs_server_.server_uri.c_str(),
57  std::string(cluster_name_).c_str(),
59  }
60 }
61 
65  "[xds_client %p] destroying drop stats %p for {%s, %s, %s}",
66  xds_client_.get(), this, lrs_server_.server_uri.c_str(),
67  std::string(cluster_name_).c_str(),
69  }
70  xds_client_->RemoveClusterDropStats(lrs_server_, cluster_name_,
71  eds_service_name_, this);
72  xds_client_.reset(DEBUG_LOCATION, "DropStats");
73 }
74 
76  Snapshot snapshot;
77  snapshot.uncategorized_drops = GetAndResetCounter(&uncategorized_drops_);
78  MutexLock lock(&mu_);
79  snapshot.categorized_drops = std::move(categorized_drops_);
80  return snapshot;
81 }
82 
84  uncategorized_drops_.fetch_add(1);
85 }
86 
88  MutexLock lock(&mu_);
89  ++categorized_drops_[category];
90 }
91 
92 //
93 // XdsClusterLocalityStats
94 //
95 
97  RefCountedPtr<XdsClient> xds_client,
101  ? "XdsClusterLocalityStats"
102  : nullptr),
103  xds_client_(std::move(xds_client)),
104  lrs_server_(lrs_server),
107  name_(std::move(name)) {
110  "[xds_client %p] created locality stats %p for {%s, %s, %s, %s}",
111  xds_client_.get(), this, lrs_server_.server_uri.c_str(),
112  std::string(cluster_name_).c_str(),
114  name_->AsHumanReadableString().c_str());
115  }
116 }
117 
121  "[xds_client %p] destroying locality stats %p for {%s, %s, %s, %s}",
122  xds_client_.get(), this, lrs_server_.server_uri.c_str(),
123  std::string(cluster_name_).c_str(),
125  name_->AsHumanReadableString().c_str());
126  }
127  xds_client_->RemoveClusterLocalityStats(lrs_server_, cluster_name_,
128  eds_service_name_, name_, this);
129  xds_client_.reset(DEBUG_LOCATION, "LocalityStats");
130 }
131 
134  Snapshot snapshot = {
135  GetAndResetCounter(&total_successful_requests_),
136  // Don't reset total_requests_in_progress because it's
137  // not related to a single reporting interval.
138  total_requests_in_progress_.load(std::memory_order_relaxed),
139  GetAndResetCounter(&total_error_requests_),
140  GetAndResetCounter(&total_issued_requests_),
141  {}};
143  snapshot.backend_metrics = std::move(backend_metrics_);
144  return snapshot;
145 }
146 
148  total_issued_requests_.fetch_add(1, std::memory_order_relaxed);
149  total_requests_in_progress_.fetch_add(1, std::memory_order_relaxed);
150 }
151 
153  std::atomic<uint64_t>& to_increment =
155  to_increment.fetch_add(1, std::memory_order_relaxed);
156  total_requests_in_progress_.fetch_add(-1, std::memory_order_acq_rel);
157 }
158 
159 } // namespace grpc_core
trace.h
GPR_INFO
#define GPR_INFO
Definition: include/grpc/impl/codegen/log.h:56
grpc_core::XdsClusterDropStats::AddCallDropped
void AddCallDropped(const std::string &category)
Definition: xds_client_stats.cc:87
log.h
xds_client_stats.h
grpc_core::XdsClusterDropStats::eds_service_name_
absl::string_view eds_service_name_
Definition: xds_client_stats.h:148
grpc_core
Definition: call_metric_recorder.h:31
cluster_name
std::string cluster_name
Definition: xds_cluster_resolver.cc:91
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
grpc_core::XdsClusterDropStats::cluster_name_
absl::string_view cluster_name_
Definition: xds_client_stats.h:147
grpc_core::XdsClusterLocalityStats::AddCallFinished
void AddCallFinished(bool fail=false)
Definition: xds_client_stats.cc:152
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::XdsClusterLocalityStats::~XdsClusterLocalityStats
~XdsClusterLocalityStats() override
Definition: xds_client_stats.cc:118
cluster_name_
std::string cluster_name_
Definition: xds_cluster_impl.cc:176
grpc_core::XdsClusterLocalityStats::lrs_server_
const XdsBootstrap::XdsServer & lrs_server_
Definition: xds_client_stats.h:221
setup.name
name
Definition: setup.py:542
name_
const std::string name_
Definition: priority.cc:233
grpc_core::XdsClusterDropStats::Snapshot::uncategorized_drops
uint64_t uncategorized_drops
Definition: xds_client_stats.h:110
GRPC_TRACE_FLAG_ENABLED
#define GRPC_TRACE_FLAG_ENABLED(f)
Definition: debug/trace.h:114
grpc_core::grpc_xds_client_trace
TraceFlag grpc_xds_client_trace(false, "xds_client")
Definition: xds_client.h:57
grpc_core::XdsClusterDropStats::AddUncategorizedDrops
void AddUncategorizedDrops()
Definition: xds_client_stats.cc:83
grpc_core::XdsClusterLocalityStats::XdsClusterLocalityStats
XdsClusterLocalityStats(RefCountedPtr< XdsClient > xds_client, const XdsBootstrap::XdsServer &lrs_server_, absl::string_view cluster_name, absl::string_view eds_service_name, RefCountedPtr< XdsLocalityName > name)
Definition: xds_client_stats.cc:96
grpc_core::XdsClusterDropStats::Snapshot::categorized_drops
CategorizedDropsMap categorized_drops
Definition: xds_client_stats.h:113
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
DEBUG_LOCATION
#define DEBUG_LOCATION
Definition: debug_location.h:41
grpc_core::XdsClusterDropStats::XdsClusterDropStats
XdsClusterDropStats(RefCountedPtr< XdsClient > xds_client, const XdsBootstrap::XdsServer &lrs_server, absl::string_view cluster_name, absl::string_view eds_service_name)
Definition: xds_client_stats.cc:43
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::XdsClusterLocalityStats::Snapshot
Definition: xds_client_stats.h:176
xds_client.h
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
grpc_core::grpc_xds_client_refcount_trace
TraceFlag grpc_xds_client_refcount_trace(false, "xds_client_refcount")
Definition: xds_client.h:58
grpc_core::XdsClusterDropStats::Snapshot
Definition: xds_client_stats.h:109
grpc_core::fail
Poll< absl::StatusOr< std::tuple< T... > > > fail()
Definition: try_join_test.cc:45
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
grpc_core::XdsClusterLocalityStats::total_successful_requests_
std::atomic< uint64_t > total_successful_requests_
Definition: xds_client_stats.h:226
grpc_core::XdsClusterLocalityStats::Snapshot::backend_metrics
std::map< std::string, BackendMetric > backend_metrics
Definition: xds_client_stats.h:181
grpc_core::XdsClusterLocalityStats::total_issued_requests_
std::atomic< uint64_t > total_issued_requests_
Definition: xds_client_stats.h:229
grpc_core::XdsClusterLocalityStats::name_
RefCountedPtr< XdsLocalityName > name_
Definition: xds_client_stats.h:224
grpc_core::RefCounted
Definition: ref_counted.h:280
eds_service_name_
std::string eds_service_name_
Definition: xds_cluster_impl.cc:177
grpc_core::XdsClusterLocalityStats::AddCallStarted
void AddCallStarted()
Definition: xds_client_stats.cc:147
grpc_core::XdsClusterLocalityStats::total_requests_in_progress_
std::atomic< uint64_t > total_requests_in_progress_
Definition: xds_client_stats.h:227
grpc_core::XdsClusterDropStats::GetSnapshotAndReset
Snapshot GetSnapshotAndReset()
Definition: xds_client_stats.cc:75
debug_location.h
grpc_core::XdsBootstrap::XdsServer
Definition: xds_bootstrap.h:52
eds_service_name
std::string eds_service_name
Definition: xds_cluster_resolver.cc:99
grpc_core::XdsClusterDropStats::mu_
Mutex mu_
Definition: xds_client_stats.h:153
grpc_core::XdsBootstrap::XdsServer::server_uri
std::string server_uri
Definition: xds_bootstrap.h:53
xds_client_
RefCountedPtr< XdsClient > xds_client_
Definition: cds.cc:197
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc_core::XdsClusterDropStats::xds_client_
RefCountedPtr< XdsClient > xds_client_
Definition: xds_client_stats.h:145
grpc_core::XdsClusterLocalityStats::cluster_name_
absl::string_view cluster_name_
Definition: xds_client_stats.h:222
grpc_core::XdsClusterLocalityStats::eds_service_name_
absl::string_view eds_service_name_
Definition: xds_client_stats.h:223
grpc_core::XdsClusterDropStats::lrs_server_
const XdsBootstrap::XdsServer & lrs_server_
Definition: xds_client_stats.h:146
grpc_core::XdsClusterDropStats::~XdsClusterDropStats
~XdsClusterDropStats() override
Definition: xds_client_stats.cc:62
grpc_core::XdsClusterLocalityStats::backend_metrics_mu_
Mutex backend_metrics_mu_
Definition: xds_client_stats.h:235
grpc_core::XdsClusterLocalityStats::GetSnapshotAndReset
Snapshot GetSnapshotAndReset()
Definition: xds_client_stats.cc:133
grpc_core::XdsClusterDropStats::uncategorized_drops_
std::atomic< uint64_t > uncategorized_drops_
Definition: xds_client_stats.h:149
grpc_core::XdsClusterLocalityStats::total_error_requests_
std::atomic< uint64_t > total_error_requests_
Definition: xds_client_stats.h:228
grpc_core::XdsClusterLocalityStats::xds_client_
RefCountedPtr< XdsClient > xds_client_
Definition: xds_client_stats.h:220
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:57