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

New api/label package, common label set impl #651

Merged
merged 24 commits into from
Apr 23, 2020

Conversation

jmacd
Copy link
Contributor

@jmacd jmacd commented Apr 21, 2020

This extracts the sdk/metric label set implementation, the sdk/export/metric default label encoder, and moves them into api/label. The new type is *label.Set supports the same iterator interface, but with the removal of two interfaces Labels and LabelStorage are no longer needed, since the API uses structs and pointers.

The main support implemented by the SDK's label set was computing a distinct value for every unique set of labels, after de-duplication and last-value-wins semantics are applied. The internal map key used in the SDK is now exposed as label.Distinct, which is a struct wrapping a non-exported interface{}, wrapping a variable-size array.

This replaces partly replaces #640 and #641, in that it changes how uniqueness is exposed and resources are represented.

Note that the new label.Set type replaces both the metric label set and the resource struct in this PR. In a future PR it should also replace the correlation.Map (TODO).

The label.Set object manages a cache of encodings by label encoder. This support is expanded to >1 encoding per label set, so that multiple exporters can co-exist without harming performance. The number of encodings is limited to 3 in this PR, but can be expanded in the future.

@jmacd jmacd added the area:metrics Part of OpenTelemetry Metrics label Apr 21, 2020
Copy link
Member

@krnowak krnowak left a comment

Choose a reason for hiding this comment

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

I like it. Maybe some general problems:

  • other SDK's will be forced to use api's way of generating a unique representation of a label set
  • creating resources with duplicates used to use the first-wins mechanics, now it's last-wins.
  • we probably could drop label encoder use in more places and limit that to exporters only?

api/label/encoder.go Outdated Show resolved Hide resolved
api/label/encoder.go Outdated Show resolved Hide resolved
api/label/encoder.go Show resolved Hide resolved
api/label/encoder.go Outdated Show resolved Hide resolved
api/label/encoder.go Outdated Show resolved Hide resolved
sdk/metric/batcher/ungrouped/ungrouped.go Show resolved Hide resolved
sdk/metric/correct_test.go Outdated Show resolved Hide resolved
sdk/metric/sdk.go Outdated Show resolved Hide resolved
sdk/resource/resource.go Show resolved Hide resolved
sdk/resource/resource.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@jmacd jmacd left a comment

Choose a reason for hiding this comment

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

I will address all of @krnowak's feedback later today. Please register your objections, if you have any! Thanks.

sdk/resource/resource.go Show resolved Hide resolved
sdk/resource/resource.go Outdated Show resolved Hide resolved
sdk/metric/batcher/ungrouped/ungrouped.go Show resolved Hide resolved
Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Overall this looks like an improvement. The only things I see appear minor. The biggest thing seems to be the Resource changes. The change of Attributes -> Labels needs to be updated project wide and a Merge method added. Otherwise, this looks close to done.

api/label/encoder.go Outdated Show resolved Hide resolved
api/label/encoder.go Outdated Show resolved Hide resolved
api/label/set.go Outdated Show resolved Hide resolved
api/label/set.go Outdated Show resolved Hide resolved
api/label/set.go Outdated Show resolved Hide resolved
sdk/resource/resource.go Outdated Show resolved Hide resolved
sdk/resource/resource.go Show resolved Hide resolved
sdk/resource/resource.go Show resolved Hide resolved
sdk/trace/trace_test.go Outdated Show resolved Hide resolved
sdk/metric/sdk.go Outdated Show resolved Hide resolved
@jmacd
Copy link
Contributor Author

jmacd commented Apr 22, 2020

PTAL. Note that this includes as a prerequisite the changes from #654

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

This looks awesome, thanks for the hard work!

All these review comments are minor or plain nits. They can be addressed at a later time if you want to ignore them.

sdk/resource/resource.go Outdated Show resolved Hide resolved
sdk/resource/resource.go Outdated Show resolved Hide resolved
sdk/resource/resource.go Outdated Show resolved Hide resolved
sdk/resource/iterator_test.go Show resolved Hide resolved
exporters/otlp/otlp_metric_test.go Outdated Show resolved Hide resolved
sdk/metric/correct_test.go Outdated Show resolved Hide resolved
exporters/otlp/internal/transform/span.go Outdated Show resolved Hide resolved
api/label/iterator.go Show resolved Hide resolved
@jmacd
Copy link
Contributor Author

jmacd commented Apr 23, 2020

(I added more tests.)

Copy link
Member

@krnowak krnowak left a comment

Choose a reason for hiding this comment

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

This looks great!

But I see that you have left the resource mostly as is, including the api dependency on sdk resource. I suppose this is something to be cleaned up in a future PR then.

What I found are mostly documentation issues, thus I'm going to approve the PR, so you can merge the PR right after fixing those.

api/label/set.go Outdated Show resolved Hide resolved
api/label/set_test.go Outdated Show resolved Hide resolved
Comment on lines 95 to 104
// No other String values are equal to this.
for _, distinct := range s2d {
if distinct[0] == d {
continue
}
for _, otherDistinct := range distinct {
require.NotEqual(t, otherDistinct, d)
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Same confusion here, but with strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

api/label/set.go Outdated Show resolved Hide resolved
api/label/set.go Outdated Show resolved Hide resolved
api/label/set.go Outdated Show resolved Hide resolved
exporters/trace/jaeger/jaeger.go Outdated Show resolved Hide resolved
sdk/metric/sdk.go Outdated Show resolved Hide resolved
sdk/metric/sdk.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants