Skip to content

Commit 079bbf1

Browse files
Merge branch 'main' into otel_traces_for_parallel_upload_file
2 parents 036fdb3 + 855ac89 commit 079bbf1

10 files changed

Lines changed: 1200 additions & 94 deletions

File tree

ci/gha/builds/lib/cmake.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function cmake::common_args() {
5858
if [[ -n "${VCPKG_TRIPLET:-}" ]]; then
5959
args+=("-DVCPKG_TARGET_TRIPLET=${VCPKG_TRIPLET}")
6060
fi
61+
args+=("-DVCPKG_OVERLAY_PORTS=ci/gha/builds/vcpkg-overlays")
6162
printf "%s\n" "${args[@]}"
6263
}
6364

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
if (VCPKG_TARGET_IS_WINDOWS)
2+
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
3+
endif ()
4+
5+
vcpkg_from_github(
6+
OUT_SOURCE_PATH
7+
SOURCE_PATH
8+
REPO
9+
open-telemetry/opentelemetry-cpp
10+
REF
11+
"v${VERSION}"
12+
SHA512
13+
c93005c9b24b358a9998141f6c7fd9675778731775dacaad18f0e81117fd00aaabff371c04cf96688a9c86117727181052a141d961d4db28fc457b454351c570
14+
HEAD_REF
15+
main
16+
PATCHES
17+
# Missing find_dependency for Abseil
18+
add-missing-find-dependency.patch)
19+
20+
vcpkg_check_features(
21+
OUT_FEATURE_OPTIONS
22+
FEATURE_OPTIONS
23+
FEATURES
24+
etw
25+
WITH_ETW
26+
zipkin
27+
WITH_ZIPKIN
28+
prometheus
29+
WITH_PROMETHEUS
30+
elasticsearch
31+
WITH_ELASTICSEARCH
32+
otlp-http
33+
WITH_OTLP_HTTP
34+
otlp-grpc
35+
WITH_OTLP_GRPC
36+
geneva
37+
WITH_GENEVA
38+
user-events
39+
WITH_USER_EVENTS
40+
INVERTED_FEATURES
41+
user-events
42+
BUILD_TRACEPOINTS)
43+
44+
# opentelemetry-proto is a third party submodule and opentelemetry-cpp release
45+
# did not pack it.
46+
if (WITH_OTLP_GRPC OR WITH_OTLP_HTTP)
47+
set(OTEL_PROTO_VERSION "1.3.1")
48+
vcpkg_download_distfile(
49+
ARCHIVE
50+
URLS
51+
"https://github.com/open-telemetry/opentelemetry-proto/archive/v${OTEL_PROTO_VERSION}.tar.gz"
52+
FILENAME
53+
"opentelemetry-proto-${OTEL_PROTO_VERSION}.tar.gz"
54+
SHA512
55+
8c75e4ff79c4b5b251e0ec8ece92ec901d70ec601644505ffdd137fb728daac91fd9203e1f448500124906737d91d80f10b694977688c655418b94f61c828d06
56+
)
57+
58+
vcpkg_extract_source_archive(src ARCHIVE "${ARCHIVE}")
59+
file(REMOVE_RECURSE "${SOURCE_PATH}/third_party/opentelemetry-proto")
60+
file(COPY "${src}/."
61+
DESTINATION "${SOURCE_PATH}/third_party/opentelemetry-proto")
62+
# Create empty .git directory to prevent opentelemetry from cloning it
63+
# during build time
64+
file(MAKE_DIRECTORY "${SOURCE_PATH}/third_party/opentelemetry-proto/.git")
65+
list(APPEND FEATURE_OPTIONS -DCMAKE_CXX_STANDARD=14)
66+
list(
67+
APPEND
68+
FEATURE_OPTIONS
69+
"-DgRPC_CPP_PLUGIN_EXECUTABLE=${CURRENT_HOST_INSTALLED_DIR}/tools/grpc/grpc_cpp_plugin${VCPKG_HOST_EXECUTABLE_SUFFIX}"
70+
)
71+
endif ()
72+
73+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS "OFF")
74+
75+
if (WITH_GENEVA OR WITH_USER_EVENTS)
76+
# Geneva and user events exporters from opentelemetry-cpp-contrib are
77+
# tightly coupled with opentelemetry-cpp repo, so they should be ported as a
78+
# feature under opentelemetry-cpp.
79+
clone_opentelemetry_cpp_contrib(CONTRIB_SOURCE_PATH)
80+
81+
if (WITH_GENEVA)
82+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
83+
"${CONTRIB_SOURCE_PATH}/exporters/geneva")
84+
if (VCPKG_TARGET_IS_WINDOWS)
85+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
86+
"${OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS}\;${CONTRIB_SOURCE_PATH}/exporters/geneva-trace"
87+
)
88+
else ()
89+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
90+
"${OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS}\;${CONTRIB_SOURCE_PATH}/exporters/fluentd"
91+
)
92+
endif ()
93+
endif ()
94+
95+
if (WITH_USER_EVENTS)
96+
if (WITH_GENEVA)
97+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
98+
"${OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS}\;${CONTRIB_SOURCE_PATH}/exporters/user_events"
99+
)
100+
else ()
101+
set(OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS
102+
"${CONTRIB_SOURCE_PATH}/exporters/user_events")
103+
endif ()
104+
endif ()
105+
endif ()
106+
107+
vcpkg_cmake_configure(
108+
SOURCE_PATH
109+
"${SOURCE_PATH}"
110+
OPTIONS
111+
-DBUILD_TESTING=OFF
112+
-DWITH_EXAMPLES=OFF
113+
-DOPENTELEMETRY_INSTALL=ON
114+
-DWITH_STL=CXX14
115+
-DWITH_ABSEIL=ON
116+
-DWITH_BENCHMARK=OFF
117+
-DOPENTELEMETRY_EXTERNAL_COMPONENT_PATH=${OPENTELEMETRY_CPP_EXTERNAL_COMPONENTS}
118+
${FEATURE_OPTIONS}
119+
MAYBE_UNUSED_VARIABLES
120+
WITH_GENEVA
121+
WITH_USER_EVENTS
122+
BUILD_TRACEPOINTS)
123+
124+
vcpkg_cmake_install()
125+
vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/${PORT}")
126+
vcpkg_copy_pdbs()
127+
128+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
129+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
130+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

google/cloud/bigtable/internal/metrics.cc

Lines changed: 166 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,59 @@
1616

1717
#include "google/cloud/bigtable/internal/metrics.h"
1818
#include "google/cloud/bigtable/version.h"
19+
#include <algorithm>
20+
#include <map>
21+
#include <set>
1922

2023
namespace google {
2124
namespace cloud {
2225
namespace bigtable_internal {
2326
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
27+
namespace {
28+
auto constexpr kMeterInstrumentationScopeVersion = "v1";
29+
} // namespace
2430

25-
LabelMap IntoLabelMap(ResourceLabels const& r, DataLabels const& d) {
26-
return {
27-
{"project_id", r.project_id},
28-
{"instance", r.instance},
29-
{"table", r.table},
30-
{"cluster", r.cluster},
31-
{"zone", r.zone},
31+
// TODO(#15329): Refactor how we're handling different data labels for
32+
// the various RPCs. Adding a function to each metric type to add its DataLabels
33+
// to the map should be more performant than performing a set_difference every
34+
// time.
35+
LabelMap IntoLabelMap(ResourceLabels const& r, DataLabels const& d,
36+
std::set<std::string> const& filtered_data_labels) {
37+
LabelMap labels = {{"project_id", r.project_id},
38+
{"instance", r.instance},
39+
{"table", r.table},
40+
{"cluster", r.cluster},
41+
{"zone", r.zone}};
42+
std::map<std::string, std::string> data = {{
3243
{"method", d.method},
3344
{"streaming", d.streaming},
3445
{"client_name", d.client_name},
3546
{"client_uid", d.client_uid},
3647
{"app_profile", d.app_profile},
3748
{"status", d.status},
49+
}};
50+
51+
if (filtered_data_labels.empty()) {
52+
labels.insert(data.begin(), data.end());
53+
return labels;
54+
}
55+
56+
struct Compare {
57+
bool operator()(std::pair<std::string const, std::string> const& a,
58+
std::string const& b) {
59+
return a.first < b;
60+
}
61+
62+
bool operator()(std::string const& a,
63+
std::pair<std::string const, std::string> const& b) {
64+
return a < b.first;
65+
}
3866
};
67+
68+
std::set_difference(data.begin(), data.end(), filtered_data_labels.begin(),
69+
filtered_data_labels.end(),
70+
std::inserter(labels, labels.begin()), Compare());
71+
return labels;
3972
}
4073

4174
absl::optional<google::bigtable::v2::ResponseParams>
@@ -54,6 +87,132 @@ GetResponseParamsFromTrailingMetadata(
5487

5588
Metric::~Metric() = default;
5689

90+
OperationLatency::OperationLatency(
91+
std::string const& instrumentation_scope,
92+
opentelemetry::nostd::shared_ptr<
93+
opentelemetry::metrics::MeterProvider> const& provider)
94+
: operation_latencies_(provider
95+
->GetMeter(instrumentation_scope,
96+
kMeterInstrumentationScopeVersion)
97+
->CreateDoubleHistogram("operation_latencies")
98+
.release()) {}
99+
100+
void OperationLatency::PreCall(opentelemetry::context::Context const&,
101+
PreCallParams const& p) {
102+
if (p.first_attempt) {
103+
operation_start_ = p.attempt_start;
104+
}
105+
}
106+
107+
void OperationLatency::PostCall(opentelemetry::context::Context const&,
108+
grpc::ClientContext const& client_context,
109+
PostCallParams const&) {
110+
auto response_params = GetResponseParamsFromTrailingMetadata(client_context);
111+
if (response_params) {
112+
resource_labels_.cluster = response_params->cluster_id();
113+
resource_labels_.zone = response_params->zone_id();
114+
}
115+
}
116+
117+
void OperationLatency::OnDone(opentelemetry::context::Context const& context,
118+
OnDoneParams const& p) {
119+
data_labels_.status = StatusCodeToString(p.operation_status.code());
120+
auto operation_elapsed = std::chrono::duration_cast<LatencyDuration>(
121+
p.operation_end - operation_start_);
122+
operation_latencies_->Record(operation_elapsed.count(),
123+
IntoLabelMap(resource_labels_, data_labels_),
124+
context);
125+
}
126+
127+
std::unique_ptr<Metric> OperationLatency::clone(ResourceLabels resource_labels,
128+
DataLabels data_labels) const {
129+
auto m = std::make_unique<OperationLatency>(*this);
130+
m->resource_labels_ = std::move(resource_labels);
131+
m->data_labels_ = std::move(data_labels);
132+
return m;
133+
}
134+
135+
AttemptLatency::AttemptLatency(
136+
std::string const& instrumentation_scope,
137+
opentelemetry::nostd::shared_ptr<
138+
opentelemetry::metrics::MeterProvider> const& provider)
139+
: attempt_latencies_(provider
140+
->GetMeter(instrumentation_scope,
141+
kMeterInstrumentationScopeVersion)
142+
->CreateDoubleHistogram("attempt_latencies")) {}
143+
144+
void AttemptLatency::PreCall(opentelemetry::context::Context const&,
145+
PreCallParams const& p) {
146+
attempt_start_ = std::move(p.attempt_start);
147+
}
148+
149+
void AttemptLatency::PostCall(opentelemetry::context::Context const& context,
150+
grpc::ClientContext const& client_context,
151+
PostCallParams const& p) {
152+
auto response_params = GetResponseParamsFromTrailingMetadata(client_context);
153+
if (response_params) {
154+
resource_labels_.cluster = response_params->cluster_id();
155+
resource_labels_.zone = response_params->zone_id();
156+
}
157+
data_labels_.status = StatusCodeToString(p.attempt_status.code());
158+
auto attempt_elapsed = std::chrono::duration_cast<LatencyDuration>(
159+
p.attempt_end - attempt_start_);
160+
auto m = IntoLabelMap(resource_labels_, data_labels_);
161+
attempt_latencies_->Record(attempt_elapsed.count(), std::move(m), context);
162+
}
163+
164+
std::unique_ptr<Metric> AttemptLatency::clone(ResourceLabels resource_labels,
165+
DataLabels data_labels) const {
166+
auto m = std::make_unique<AttemptLatency>(*this);
167+
m->resource_labels_ = std::move(resource_labels);
168+
m->data_labels_ = std::move(data_labels);
169+
return m;
170+
}
171+
172+
RetryCount::RetryCount(
173+
std::string const& instrumentation_scope,
174+
opentelemetry::nostd::shared_ptr<
175+
opentelemetry::metrics::MeterProvider> const& provider)
176+
: retry_count_(provider
177+
->GetMeter(instrumentation_scope,
178+
kMeterInstrumentationScopeVersion)
179+
->CreateUInt64Counter("retry_count")
180+
.release()) {}
181+
182+
void RetryCount::PreCall(opentelemetry::context::Context const&,
183+
PreCallParams const& p) {
184+
if (!p.first_attempt) {
185+
++num_retries_;
186+
}
187+
}
188+
189+
void RetryCount::PostCall(opentelemetry::context::Context const&,
190+
grpc::ClientContext const& client_context,
191+
PostCallParams const&) {
192+
auto response_params = GetResponseParamsFromTrailingMetadata(client_context);
193+
if (response_params) {
194+
resource_labels_.cluster = response_params->cluster_id();
195+
resource_labels_.zone = response_params->zone_id();
196+
}
197+
}
198+
199+
void RetryCount::OnDone(opentelemetry::context::Context const& context,
200+
OnDoneParams const& p) {
201+
data_labels_.status = StatusCodeToString(p.operation_status.code());
202+
retry_count_->Add(num_retries_,
203+
IntoLabelMap(resource_labels_, data_labels_,
204+
std::set<std::string>{"streaming"}),
205+
context);
206+
}
207+
208+
std::unique_ptr<Metric> RetryCount::clone(ResourceLabels resource_labels,
209+
DataLabels data_labels) const {
210+
auto m = std::make_unique<RetryCount>(*this);
211+
m->resource_labels_ = std::move(resource_labels);
212+
m->data_labels_ = std::move(data_labels);
213+
return m;
214+
}
215+
57216
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
58217
} // namespace bigtable_internal
59218
} // namespace cloud

0 commit comments

Comments
 (0)