-
Notifications
You must be signed in to change notification settings - Fork 458
feat(storage): add stream open latency metrics and trace annotations #16316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kalragauri
wants to merge
4
commits into
googleapis:feat/storage-experimental-metrics
Choose a base branch
from
kalragauri:feat/storage-experimental-metrics
base: feat/storage-experimental-metrics
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d54ed9f
feat(storage): add stream open latency metrics and trace annotations
kalragauri 73bfe50
Address feedback from code assistant
kalragauri 68e2792
Address reviewer feedback about using a dedicated class for metrics
kalragauri e3106e4
Address feedback about decoupling tracing from metrics
kalragauri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
google/cloud/storage/internal/async/open_object_metrics.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // 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 | ||
| // | ||
| // https://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 "google/cloud/storage/internal/async/open_object_metrics.h" | ||
|
|
||
| #ifdef GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS | ||
| #include <opentelemetry/metrics/provider.h> | ||
| #endif | ||
|
|
||
| namespace google { | ||
| namespace cloud { | ||
| namespace storage_internal { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
|
||
| #ifdef GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS | ||
| namespace { | ||
| struct StreamOpenMetrics { | ||
| opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Histogram<double>> | ||
| network_handshake; | ||
| opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Histogram<double>> | ||
| server_metadata_latency; | ||
| opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Histogram<double>> | ||
| stream_open_latency; | ||
|
|
||
| static StreamOpenMetrics const& Instance() { | ||
| static auto const metrics = [] { | ||
| auto meter = | ||
| opentelemetry::metrics::Provider::GetMeterProvider()->GetMeter( | ||
| "storage", "v1"); | ||
| return StreamOpenMetrics{ | ||
| meter->CreateDoubleHistogram("gl-cpp.latency.network_handshake", | ||
| "Network Handshake", "us"), | ||
| meter->CreateDoubleHistogram("gl-cpp.latency.server_metadata", | ||
| "Server Metadata Latency", "us"), | ||
| meter->CreateDoubleHistogram("gl-cpp.latency.stream_open", | ||
| "End-to-End Stream Open", "us")}; | ||
| }(); | ||
| return metrics; | ||
| } | ||
| }; | ||
| } // namespace | ||
| #endif | ||
|
|
||
| void OpenObjectMetrics::RecordCall() { | ||
| #if defined(GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS) || \ | ||
| defined(GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY) | ||
| t0_ = std::chrono::steady_clock::now(); | ||
| #endif | ||
| } | ||
|
|
||
| void OpenObjectMetrics::RecordStart() { | ||
| #if defined(GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS) || \ | ||
| defined(GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY) | ||
| t1_ = std::chrono::steady_clock::now(); | ||
| #endif | ||
| } | ||
|
|
||
| void OpenObjectMetrics::RecordWrite() { | ||
| #if defined(GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS) || \ | ||
| defined(GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY) | ||
| t2_ = std::chrono::steady_clock::now(); | ||
| #endif | ||
| } | ||
|
kalragauri marked this conversation as resolved.
|
||
|
|
||
| #ifdef GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS | ||
| void OpenObjectMetrics::RecordMetrics( | ||
| std::string const& bucket, std::chrono::steady_clock::time_point t3) { | ||
| auto const& metrics = StreamOpenMetrics::Instance(); | ||
| auto p1 = static_cast<double>( | ||
| std::chrono::duration_cast<std::chrono::microseconds>(t1_ - t0_).count()); | ||
| auto p2 = static_cast<double>( | ||
| std::chrono::duration_cast<std::chrono::microseconds>(t3 - t2_).count()); | ||
| auto p3 = static_cast<double>( | ||
| std::chrono::duration_cast<std::chrono::microseconds>(t3 - t0_).count()); | ||
|
|
||
| metrics.network_handshake->Record(p1, {{"gcp.storage.bucket", bucket}}, | ||
| opentelemetry::context::Context{}); | ||
| metrics.server_metadata_latency->Record(p2, {{"gcp.storage.bucket", bucket}}, | ||
| opentelemetry::context::Context{}); | ||
| metrics.stream_open_latency->Record(p3, {{"gcp.storage.bucket", bucket}}, | ||
| opentelemetry::context::Context{}); | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY | ||
| void OpenObjectMetrics::RecordRead( | ||
| std::string const& bucket, | ||
| opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> const& span) { | ||
| auto t3 = std::chrono::steady_clock::now(); | ||
| #ifdef GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS | ||
| RecordMetrics(bucket, t3); | ||
| #else | ||
| (void)bucket; | ||
| #endif | ||
|
|
||
| if (span && span->GetContext().IsValid()) { | ||
| auto p1 = static_cast<double>( | ||
| std::chrono::duration_cast<std::chrono::microseconds>(t1_ - t0_) | ||
| .count()); | ||
| auto p2 = static_cast<double>( | ||
| std::chrono::duration_cast<std::chrono::microseconds>(t3 - t2_) | ||
| .count()); | ||
| auto p3 = static_cast<double>( | ||
| std::chrono::duration_cast<std::chrono::microseconds>(t3 - t0_) | ||
| .count()); | ||
| span->AddEvent("gl-cpp.stream_open.latency", | ||
| {{"gl-cpp.latency.network_handshake", p1}, | ||
| {"gl-cpp.latency.server_metadata", p2}, | ||
| {"gl-cpp.latency.stream_open", p3}}); | ||
| } | ||
| } | ||
|
kalragauri marked this conversation as resolved.
|
||
| #else | ||
| void OpenObjectMetrics::RecordRead(std::string const& bucket) { | ||
| #ifdef GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS | ||
| RecordMetrics(bucket, std::chrono::steady_clock::now()); | ||
| #else | ||
| (void)bucket; | ||
| #endif | ||
| } | ||
| #endif | ||
|
|
||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
| } // namespace storage_internal | ||
| } // namespace cloud | ||
| } // namespace google | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright 2024 Google LLC | ||
| // | ||
| // 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 | ||
| // | ||
| // https://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. | ||
|
|
||
| #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_ASYNC_OPEN_OBJECT_METRICS_H | ||
| #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_ASYNC_OPEN_OBJECT_METRICS_H | ||
|
|
||
| #include "google/cloud/version.h" | ||
| #include <chrono> | ||
| #include <string> | ||
|
|
||
| #ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY | ||
| #include <opentelemetry/trace/span.h> | ||
| #endif | ||
|
|
||
| namespace google { | ||
| namespace cloud { | ||
| namespace storage_internal { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
|
||
| class OpenObjectMetrics { | ||
| public: | ||
| void RecordCall(); | ||
| void RecordStart(); | ||
| void RecordWrite(); | ||
|
|
||
| #ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY | ||
| void RecordRead( | ||
| std::string const& bucket, | ||
| opentelemetry::nostd::shared_ptr<opentelemetry::trace::Span> const& span); | ||
| #else | ||
| void RecordRead(std::string const& bucket); | ||
| #endif | ||
|
|
||
| private: | ||
| #ifdef GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS | ||
| void RecordMetrics(std::string const& bucket, | ||
| std::chrono::steady_clock::time_point t3); | ||
| #endif | ||
|
|
||
| #if defined(GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS) || \ | ||
| defined(GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY) | ||
| std::chrono::steady_clock::time_point t0_; | ||
| std::chrono::steady_clock::time_point t1_; | ||
| std::chrono::steady_clock::time_point t2_; | ||
| #endif | ||
|
kalragauri marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
| } // namespace storage_internal | ||
| } // namespace cloud | ||
| } // namespace google | ||
|
|
||
| #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_ASYNC_OPEN_OBJECT_METRICS_H | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.