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

Add support for Resources in the SDK #552

Merged
merged 16 commits into from
Mar 20, 2020

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Mar 14, 2020

Add Config types for the push Controller and the SDK. Included with this are helper functions to configure the ErrorHandler and Resource.

Add a Resource to the Descriptor. The choice to add the Resource here (instead of say a Record or the Instrument itself) was motivated by the definition of the Descriptor as the way to
uniquely describe a metric instrument.

Update the push Controller and default SDK to pass down their configured Resource from instantiation to the metric instruments.

Resolves #515

Add `Config` types for the push `Controller` and the `SDK`. Included
with this are helper functions to configure the `ErrorHandler` and
`Resource`.

Add a `Resource` to the Meter `Descriptor`. The choice to add the
`Resource` here (instead of say a `Record` or the `Instrument` itself)
was motivated by the definition of the `Descriptor` as the way to
uniquely describe a metric instrument.

Update the push `Controller` and default `SDK` to pass down their configured
`Resource` from instantiation to the metric instruments.
@rghetia
Copy link
Contributor

rghetia commented Mar 14, 2020

Add a Resource to the Meter Descriptor. The choice to add the Resource here (instead of say a Record or the Instrument itself) was motivated by the definition of the Descriptor as the way to
uniquely describe a metric instrument.

How about WithResource as an option? I guess same could be applied to unit, description, and labels as well.

@MrAlias
Copy link
Contributor Author

MrAlias commented Mar 16, 2020

How about WithResource as an option? I guess same could be applied to unit, description, and labels as well.

I think this is a good direction. It would follow our other design patterns as well. I'll refactor.

Add DescriptorConfig and DescriptorOption to configure the metric
Descriptor with the description, unit, keys, and resource.

Update all function calls to NewDescriptor to use new function
signature.
Copy link
Contributor

@rghetia rghetia left a comment

Choose a reason for hiding this comment

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

LG. Minor nits.

sdk/export/metric/descriptor.go Outdated Show resolved Hide resolved
sdk/export/metric/descriptor.go Outdated Show resolved Hide resolved
sdk/export/metric/descriptor.go Outdated Show resolved Hide resolved
sdk/export/metric/descriptor.go Outdated Show resolved Hide resolved
@jmacd
Copy link
Contributor

jmacd commented Mar 16, 2020

I have a selfish favor to ask. Would you mind waiting until #560 merges? (If it merges.)

This PR will cause a lot of conflicts with #560, which I'm nearly finished with. #560 was a really difficult refactoring, and I'm worried about conflicts. The cause of the conflict is that I needed a Descriptor type in the API to organize the two new constructors (NewSynchronousInstrument, ...), so I removed export.Descriptor and moved it into api/metric. I suspect you'll have a much easier time resolving these conflicts in here than I will have in #560.

I am self-reviewing #560 now and adding comments and cleanups, but it's building and passing tests.

@MrAlias
Copy link
Contributor Author

MrAlias commented Mar 16, 2020

Would you mind waiting until #560 merges?

Yeah, no problem.

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.

Looks good. I mostly had the questions around options being interfaces vs function. In api package we usually use functions I think (with the exception of options passed to the instrument constructors since they seem to be a bit more complicated case).

sdk/export/metric/descriptor.go Outdated Show resolved Hide resolved
sdk/export/metric/descriptor.go Outdated Show resolved Hide resolved
sdk/metric/config.go Show resolved Hide resolved
sdk/metric/config.go Outdated Show resolved Hide resolved
sdk/metric/controller/push/config.go Show resolved Hide resolved
sdk/metric/controller/push/config.go Outdated Show resolved Hide resolved
sdk/metric/controller/push/push.go Outdated Show resolved Hide resolved
@krnowak
Copy link
Member

krnowak commented Mar 19, 2020

I think that the discussion about option as interface vs function can be moved to #536, so no need to block this PR on it. Still there was one issue about forwarding the error handler to address.

Tyler Yahn added 4 commits March 19, 2020 14:29
Pass the configured ErrorHandler for the controller to the SDK.
Add back the Resource field to the Descriptor that was moved in the
last merge with master.

Add a resource.Provider interface.

Have the default SDK implement the new resource.Provider interface and
integrate the new interface into the newSync/newAsync workflows. Now, if
the SDK has a Resource defined it will be passed to all Descriptors
created for the instruments it creates.
Tyler Yahn added 6 commits March 19, 2020 21:02
Add an `Equal` method to the Resource so it can be compared with
github.com/google/go-cmp/cmp.

Add additional test of the API Option unit tests to ensure WithResource
correctly sets a new resource.
Move the interface to where it is used.

Fix spelling.
@MrAlias MrAlias requested review from krnowak and rghetia March 20, 2020 04:38
@MrAlias
Copy link
Contributor Author

MrAlias commented Mar 20, 2020

I re-requested review from you @krnowak and @rghetia due to how much this changed in strategy now that #560 was merged. PTAL

Copy link
Contributor

@rghetia rghetia left a comment

Choose a reason for hiding this comment

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

Couple of minor nits.

sdk/metric/sdk.go Outdated Show resolved Hide resolved
sdk/resource/resource.go Outdated Show resolved Hide resolved
@rghetia rghetia merged commit f7df68b into open-telemetry:master Mar 20, 2020
@MrAlias MrAlias deleted the metric-resources branch March 20, 2020 16:12
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.

Default SDK support for resources (Metrics)
5 participants