FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

impl(otel): copy service resource labels into metric labels by IcySteam · Pull Request #14825 · googleapis/google-cloud-cpp · GitHub

impl(otel): copy service resource labels into metric labels - #14825

Closed
IcySteam wants to merge 3 commits into
googleapis:mainfrom
IcySteam:otel-servicelabels
Closed

impl(otel): copy service resource labels into metric labels#14825
IcySteam wants to merge 3 commits into
googleapis:mainfrom
IcySteam:otel-servicelabels

Conversation

IcySteam commented Nov 6, 2024
edited by scotthart
Loading

Copy link
Copy Markdown

fixed #14823


This change is 

IcySteam requested a review from a team November 6, 2024 03:09
IcySteam marked this pull request as draft November 12, 2024 04:14

dbolduc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't think the copying is necessary. Can we check for the known service labels and do the manipulations here:

for (auto& label : mr.labels) {
(*resource.mutable_labels())[std::move(label.first)] =
std::move(label.second);
}

and add a TEST(ToMonitoredResource, AddsServiceLabels) { ... } in time_series_test.cc ?

scope_metrics.metric_data_) {
for (opentelemetry::sdk::metrics::PointDataAttributes& pda :
metric.point_data_attr_) {
auto& attributes = pda.attributes;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sorry, I am confused. Do we want the labels to end up getting added to the google.api.Metric https://github.com/googleapis/googleapis/blob/2d05911be5a468b556236bee537c91922f9c23a3/google/api/metric.proto#L286

... or to the google.api.MonitoredResource https://github.com/googleapis/googleapis/blob/2d05911be5a468b556236bee537c91922f9c23a3/google/api/monitored_resource.proto#L106

... or both?

unit tests would help clarify the intended behavior that we want.

dbolduc commented Nov 22, 2024

Copy link
Copy Markdown
Member

/gcbrun

codecov Bot commented Nov 22, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.06%. Comparing base (aa062cf) to head (1775a3e).
Report is 27 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14825   +/-   ##
=======================================
  Coverage   93.06%   93.06%           
=======================================
  Files        2319     2319           
  Lines      209023   209023           
=======================================
+ Hits       194529   194530    +1     
+ Misses      14494    14493    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

IcySteam marked this pull request as ready for review November 25, 2024 06:35

Copy link
Copy Markdown
Author

Thanks; we indeed want the labels to end up getting added to the google.api.Metric class. I've refactored the PR and added some unit tests in the latest commit, PTAL.

dbolduc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the PR. Sorry it took me so long to review it. I have been splitting time between google-cloud-cpp and another team.

I feel like I owe you one, so I made the review changes in #14930. Hopefully that can cut out some review iterations and unblock y'all faster.


struct OTelKeyMatch {
std::vector<std::string> otel_keys;
absl::optional<std::string> fallback = absl::nullopt;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

FYI: I recommended that this struct change in #14923. So maybe wait for that PR and then rebase.

// See: https://cloud.google.com/monitoring/quotas
auto constexpr kMaxTimeSeriesPerRequest = 200;

std::unordered_map<std::string, OTelKeyMatch> const kExtraLabelsLookup = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Google style guide frowns upon static variables that are not trivially destructible.

We have to use:

auto const* const kExtraLabelsLookup = new std::unordered_map<...> { ... };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

On second thought, I don't think this struct is buying us much of anything. It seems kind of misapplied, in that the things like "service_name" are supposed to represent monitored resources.

I think we will be better off just iterating over the 3 labels we care about, and reuse the name changing logic from ToMetric()

Comment on lines +735 to +740
for (auto const& kv : kExtraLabelsLookup) {
auto const& oks = kv.second.otel_keys;
if (oks.empty()) {
continue;
}
for (auto const& ts : tss) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We should avoid logical branches and stuff in tests. Let's try to make them as simple as possible.

Comment on lines +741 to +743
auto const& labels = ts.metric().labels();
ASSERT_TRUE(labels.find(kv.first) != labels.end());
EXPECT_EQ(labels.at(kv.first), kv.first);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We probably want to use GMock's container matchers.

https://google.github.io/googletest/reference/matchers.html

for (auto const& ts : tss) {
auto const& labels = ts.metric().labels();
ASSERT_TRUE(labels.find(kv.first) != labels.end());
if (existing_labels.GetAttributes().find(kv.first) ==

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ifs in tests kind of scare me.

}
}
}
WithExtraLabels(data, tss);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think it would make sense to build this into ToMetric(...) which deals specifically with the google.api.Metric. It also has logic for changing strings from service.name -> service_name which we can reuse.

dbolduc commented Jan 10, 2025

Copy link
Copy Markdown
Member

I am closing this PR in favor of #14930

Thank you @IcySteam for the hard work on this PR. I copied a lot of it in #14930.

dbolduc closed this Jan 10, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTel "service.*" resource labels are not exported to Google Cloud Monitoring

2 participants


Back | FazBrowse Home | New Git URL