Skip to content
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

fix(metrics): ostream exporter should print out resource attributes #1523

Merged

Conversation

bsarden
Copy link
Contributor

@bsarden bsarden commented Jul 28, 2022

While debugging my Resource definition for a metrics exporter, I realized
the OStreamExporter did not support printing out Resource contents.

I plan on expanding upon the existing unit(s) for checking the resource
attributes, but wanted to "test the waters" first.

My goal was to attach git branch/sha information to metrics that are collected
for easier A/B testing, and a Resource seemed like a natural place for that.

For example, using the attributes:

service.git.branch
service.git.commit_sha
service.git.commit_sha_short

However, there seems to be some debate around using resources and metrics
with prometheus
, which is what led me down my debugging path of using the ostream exporter first.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 28, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@bsarden bsarden force-pushed the dev/metrics-resources-ostream-exporter branch from 64f6ab5 to cccc5b4 Compare July 28, 2022 00:25
@bsarden bsarden force-pushed the dev/metrics-resources-ostream-exporter branch from 6fbe315 to a5e10f1 Compare July 28, 2022 17:19
@codecov
Copy link

codecov bot commented Jul 28, 2022

Codecov Report

Merging #1523 (672354b) into main (73a51cf) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1523      +/-   ##
==========================================
+ Coverage   83.74%   83.81%   +0.08%     
==========================================
  Files         156      156              
  Lines        4850     4873      +23     
==========================================
+ Hits         4061     4084      +23     
  Misses        789      789              
Impacted Files Coverage Δ
exporters/ostream/src/metric_exporter.cc 92.93% <100.00%> (+1.09%) ⬆️
exporters/ostream/test/ostream_metric_test.cc 100.00% <100.00%> (ø)

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM. Just a side note, there may be conflict resolution needed if #1507 is merged first.

@bsarden bsarden marked this pull request as ready for review July 29, 2022 12:32
@bsarden bsarden requested a review from a team July 29, 2022 12:32
@bsarden bsarden force-pushed the dev/metrics-resources-ostream-exporter branch from 603b7eb to 79124bb Compare July 31, 2022 13:53
@@ -151,6 +156,11 @@ TEST(OStreamMetricsExporter, ExportHistogramPointData)
"\n counts : [200, 300, 400, 500, ]"
"\n attributes\t\t: "
"\n\ta1: b1"
"\n resources\t:"
"\n\tservice.name: unknown_service"
"\n\ttelemetry.sdk.version: 1.5.0"
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the macro OPENTELEMETRY_SDK_VERSION instead of the hardcoding version? This way, we don't need to modify this part of the code with every new release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done. There are some strange cmake failures that I'm having difficulties reproducing on my ubuntu 20.04 machine locally, but they are also not marked as "required" on the CI stages...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lalitb: What are the next steps I need to take here in order to debug? It's not clear to me what the next debugging steps are (or how some of these CI failures are relevant to a largely NFC patch like this one).

@lalitb
Copy link
Member

lalitb commented Aug 2, 2022

@bsarden - I see these two failing tests are running on Windows with OTLP exporter enabled, would it be possible to test your changes on Windows? Else, I can test it sometime this week.

@bsarden
Copy link
Contributor Author

bsarden commented Aug 2, 2022

@lalitb Thanks for the quick response! Unfortunately, I don't have access to a windows host for testing ;(. If you could test on your end sometime this week, that would be great.

const std::unordered_map<std::string, sdk::common::OwnedAttributeValue> &map,
const std::string prefix)
{
for (const auto &kv : map)
Copy link
Member

@lalitb lalitb Aug 3, 2022

Choose a reason for hiding this comment

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

@bsarden - Looks like this part of the code is causing problem. As it's unordered_map, the order of printing of resource elements is implementation specific (so different in Windows and Linux). Can we ensure to print them in the given order - maybe move resource data to std::map first and then print, and then also ensure that the same order is used for comparison in unit-test? Or else do some smart comparison for resource data in unit-test.

Copy link
Member

Choose a reason for hiding this comment

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

@bsarden - Just wondering if you have a plan to fix CI as mentioned above? Else, I can do it on top of your repo if you are fine :)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing it. CI looks good now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the ping and reproducing the error on a windows box!

@lalitb lalitb merged commit 22f07a0 into open-telemetry:main Aug 5, 2022
yxue pushed a commit to yxue/opentelemetry-cpp that referenced this pull request Dec 5, 2022
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.

3 participants