-
Notifications
You must be signed in to change notification settings - Fork 388
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
impl(otel): copy service resource labels into metric labels #14825
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the copying is necessary. Can we check for the known service labels and do the manipulations here:
google-cloud-cpp/google/cloud/opentelemetry/internal/time_series.cc
Lines 174 to 177 in 912533c
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
7c4f06b
to
a5e0212
Compare
a5e0212
to
1775a3e
Compare
/gcbrun |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚨 Try these New Features:
|
ef964b2
to
b17d474
Compare
Thanks; we indeed want the labels to end up getting added to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
||
namespace google { | ||
namespace cloud { | ||
namespace otel_internal { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
struct OTelKeyMatch { | ||
std::vector<std::string> otel_keys; | ||
absl::optional<std::string> fallback = absl::nullopt; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I recommended that this struct change in #14923. So maybe wait for that PR and then rebase.
@@ -34,6 +38,15 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | |||
// See: https://cloud.google.com/monitoring/quotas | |||
auto constexpr kMaxTimeSeriesPerRequest = 200; | |||
|
|||
std::unordered_map<std::string, OTelKeyMatch> const kExtraLabelsLookup = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Google style guide frowns upon static variables that are not trivially destructible.
We have to use:
auto const* const kExtraLabelsLookup = new std::unordered_map<...> { ... };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()
for (auto const& kv : kExtraLabelsLookup) { | ||
auto const& oks = kv.second.otel_keys; | ||
if (oks.empty()) { | ||
continue; | ||
} | ||
for (auto const& ts : tss) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid logical branches and stuff in tests. Let's try to make them as simple as possible.
auto const& labels = ts.metric().labels(); | ||
ASSERT_TRUE(labels.find(kv.first) != labels.end()); | ||
EXPECT_EQ(labels.at(kv.first), kv.first); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to use GMock's container matchers.
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) == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
s in tests kind of scare me.
@@ -215,6 +217,7 @@ std::vector<google::monitoring::v3::TimeSeries> ToTimeSeries( | |||
} | |||
} | |||
} | |||
WithExtraLabels(data, tss); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
fixed #14823
This change is