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

feat(metrics-api): use common attributes definitions #3038

Merged
merged 7 commits into from
Jul 20, 2022

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Jun 14, 2022

Which problem is this PR solving?

Use common attributes definitions.

Fixes #2585
Fixes #2587
Fixes #1482

Short description of the changes

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • hashAttributes
  • PrometheusSerializer
  • OTLP transformer

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@codecov
Copy link

codecov bot commented Jun 14, 2022

Codecov Report

Merging #3038 (2bd0e24) into main (18dce78) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 2bd0e24 differs from pull request most recent head 43acd77. Consider uploading reports for the commit 43acd77 to get more accurate results

@@            Coverage Diff             @@
##             main    #3038      +/-   ##
==========================================
- Coverage   93.08%   93.08%   -0.01%     
==========================================
  Files         188      188              
  Lines        6246     6243       -3     
  Branches     1313     1313              
==========================================
- Hits         5814     5811       -3     
  Misses        432      432              
Impacted Files Coverage Δ
...ages/opentelemetry-api-metrics/src/types/Metric.ts 100.00% <ø> (ø)
...ry-exporter-prometheus/src/PrometheusSerializer.ts 95.16% <100.00%> (ø)
...ckages/opentelemetry-sdk-metrics-base/src/utils.ts 97.72% <100.00%> (-0.15%) ⬇️

@legendecas legendecas force-pushed the metrics-ff/attributes branch from c97d58a to a9c9eb9 Compare June 21, 2022 16:07
@legendecas legendecas marked this pull request as ready for review June 21, 2022 16:08
@legendecas legendecas requested a review from a team June 21, 2022 16:08
Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

LGTM I just want to make sure I und

@@ -34,7 +34,7 @@ export function hashAttributes(attributes: MetricAttributes): string {
keys = keys.sort();
return keys.reduce((result, key) => {
if (result.length > 2) {
result += ',';
result += '|#';
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure it is safe to use this as a separator if we're allowing string values? I think it is possible to collide hashes, but do we think it is sufficiently unlikely?

Copy link
Member Author

Choose a reason for hiding this comment

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

For string values, it is always possible to collide before or after this change, like:

  • key1 = value1, and key2 = value2, results in |#key1:value1,key2:value2,
  • key1 = value1,key2=value2, also results in |#key1:value1,key2:value2.

The change here is mainly to circumvent the string value of an array of strings, like ["value1", "value2"].toString() is value1,value2 in which values are separated with ",".

Copy link
Member

Choose a reason for hiding this comment

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

Do we want to consider trying to make it impossible to collide? Or is this good enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

For what is in my mind now, it can be costly to do so. This hashing is very common across the operations in metrics SDK. I would be open to any improvements to this function but I'd be hesitant to make it a relatively costly one.

Copy link
Member Author

Choose a reason for hiding this comment

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

@dyladan I've updated the hash function to support arbitrary attribute values with JSON.stringify. PTAL :)

@legendecas legendecas marked this pull request as draft June 21, 2022 17:15
@legendecas
Copy link
Member Author

legendecas commented Jun 21, 2022

Just forgot to update the OTLP exporter tests 😅. Marking this as a draft again.

Done.

@legendecas legendecas force-pushed the metrics-ff/attributes branch from a9c9eb9 to c4a10c0 Compare June 21, 2022 17:30
@legendecas legendecas force-pushed the metrics-ff/attributes branch from c4a10c0 to 0545596 Compare June 21, 2022 17:34
@legendecas legendecas marked this pull request as ready for review June 21, 2022 17:39
@legendecas legendecas requested a review from a team June 22, 2022 15:06
@legendecas legendecas added this to the Metrics GA milestone Jun 28, 2022
# Conflicts:
#	experimental/packages/otlp-transformer/test/metrics.test.ts
@dyladan dyladan removed this from the Metrics GA milestone Jul 13, 2022
@legendecas legendecas force-pushed the metrics-ff/attributes branch from d1116a9 to ab01df7 Compare July 18, 2022 14:58
@legendecas
Copy link
Member Author

@dyladan I noticed that you removed this PR from the metrics GA milestone. Is there any specific reason to exclude this from metrics GA?

@dyladan
Copy link
Member

dyladan commented Jul 18, 2022

@dyladan I noticed that you removed this PR from the metrics GA milestone. Is there any specific reason to exclude this from metrics GA?

I excluded all PRs from the milestone since they already have issues. It was distorting the %completion number

@legendecas
Copy link
Member Author

Thank you for the explanation. Make sense to me.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Looks good 🙂
Thanks for working on this!

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

Thanks. I prefer the more robust hash even if it is slightly more costly.

@legendecas
Copy link
Member Author

Fixed tests introduced on the main branch which need to be updated accordingly in this PR.

@legendecas legendecas merged commit 1a0e0c4 into open-telemetry:main Jul 20, 2022
@legendecas legendecas deleted the metrics-ff/attributes branch July 20, 2022 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants