Skip to content

fix:Add factories for SamplingResult #3354#3360

Closed
Rocksnake wants to merge 8 commits intoopen-telemetry:mainfrom
Rocksnake:fix/add_factories_for_samplingResult
Closed

fix:Add factories for SamplingResult #3354#3360
Rocksnake wants to merge 8 commits intoopen-telemetry:mainfrom
Rocksnake:fix/add_factories_for_samplingResult

Conversation

@Rocksnake
Copy link
Copy Markdown
Contributor

  • Add three methods to get the factory to replace the original create

  • Modify all the places where SamplingResult.create is used in the project

  • Write unit test and pass the test

Remarks:since the create method with parameters is used in RateLimitingSampler, I keep the versions with Attributes

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Jul 1, 2021

CLA Signed

The committers are authorized under a signed CLA.

@Rocksnake
Copy link
Copy Markdown
Contributor Author

Could anybody help to approve running these workflows, great thanks!
This PR resolves #3354

@Oberon00 Oberon00 linked an issue Jul 1, 2021 that may be closed by this pull request
@Oberon00
Copy link
Copy Markdown
Member

Oberon00 commented Jul 1, 2021

For the future: Please also mention the ticket number in the description as "Fixes #3354". GitHub does not link issues from the title.

Could anybody help to approve running these workflows, great thanks!

I have an "Approve and run" button and clicked it and it seemed to have started but now it seems stuck. Probably an actual maintainer needs to approve the run. EDIT: Oh, it seems to have worked. Probably each new push has to be re-approved.

* @return A {@link SamplingResult} with the attributes equivalent to {@code attributes} and the
* {@link SamplingDecision#RECORD_AND_SAMPLE}
*/
static SamplingResult recordAndSample(Attributes attributes) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wouldn't create these overloads with attributes. As @anuraaga mentioned, the existing method works fine for that, and actually does create a new object when being called.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, but in the project, RateLimitingSampler calls the method with parameters. I think the method with parameters is necessary when we need specific sampling. I'm a first-time contributor, I hope you can give me some guidance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Rocksnake Thanks for the help - as per the below comment, we won't be (can't) removing the create methods. We should continue to use create for creating the results with attributes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, thanks. And in my last commit, I have restored the original create method.

static final SamplingResult EMPTY_RECORDED_SAMPLING_RESULT =
ImmutableSamplingResult.createWithoutAttributes(SamplingDecision.RECORD_ONLY);

static SamplingResult getEmptyRecordedAndSampledSamplingResult() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

small thing, but I might just call this recordAndSample(). It's much easier to read and there's fewer words to parse through to get to what it's doing. I know this isn't public, but I think it would be more readable to have a shorter, less wordy method name. Same for the other methods.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

actually...do we even need these methods at all? The things that need them can just use the fields like they are today. I think we should stick with that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, let's get rid of these methods and just let the package access the package-protected constants like it has been.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Rocksnake please get rid of these methods. thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Rocksnake I think you missed this comment

* @param decision The decision made on the span.
* @return A {@link SamplingResult} with empty attributes and the provided {@code decision}.
*/
static SamplingResult create(SamplingDecision decision) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can't delete this public method. That would be a breaking change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is it too early to deprecate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's fine to keep it here. we could deprecate at some point, but it's not harmful or bad to use this method, just slightly confusing since it won't actually create anything.

@jkwatson
Copy link
Copy Markdown
Contributor

jkwatson commented Jul 1, 2021

@Rocksnake please run the ./gradlew build task and make sure to add any changes in the docs/apidiffs directory to this PR, since it is a change to the public APIs in the SDK. Thanks!

@Rocksnake Rocksnake requested a review from a user July 2, 2021 02:53
***! MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.trace.samplers.SamplingResult (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++! NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.samplers.SamplingResult drop()
+++! NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.samplers.SamplingResult drop(io.opentelemetry.api.common.Attributes)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we'd still like to get rid of these overloads that have attributes as a parameter. Thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

image
I think this kind of call case is also necessary.

But I will try my best to think about how to replace these calls with attributes as parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Based on all the above, I feel that we should keep the old calls with attributes, and use the new short method in the future development process. I have achieved this idea and hope you approve.

@Rocksnake Rocksnake requested a review from jkwatson July 2, 2021 05:02
@Rocksnake
Copy link
Copy Markdown
Contributor Author

I have resolve all the problems, could anyone help to approve running these workflows and merge in main branch, great thanks!

* @param decision The decision made on the span.
* @return A {@link SamplingResult} with empty attributes and the provided {@code decision}.
*/
@SuppressWarnings("UngroupedOverloads")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think you need this suppress warnings

* @param decision The decision made on the span.
* @return A {@link SamplingResult} with empty attributes and the provided {@code decision}.
*/
static SamplingResult create(SamplingDecision decision) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is it too early to deprecate?

* @return A {@link SamplingResult} with the attributes equivalent to {@code attributes} and the
* provided {@code decision}.
*/
@SuppressWarnings("UngroupedOverloads")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be better if we can make sure we group the overloads so we don't need this warning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have removed them, could you please trigger the check for me again. Thanks~

@Rocksnake Rocksnake requested a review from jkwatson July 4, 2021 01:58
Copy link
Copy Markdown
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Thanks! Just @jkwatson's coment for removing the unnecessary private methods and a small suggestion to the javadocs

Comment on lines +74 to +76
* <p>This is meant for use by custom {@link Sampler} implementations.
*
* @return A {@link SamplingResult} with empty attributes and the provided {@code decision}.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* <p>This is meant for use by custom {@link Sampler} implementations.
*
* @return A {@link SamplingResult} with empty attributes and the provided {@code decision}.
* <p>This is meant for use by custom {@link Sampler} implementations and is equivalent to calling
* {@code SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE)}.
*
* @return A {@link SamplingResult} with empty attributes and the provided {@code decision}.

Let's add something like this to the three methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added them, could you check for me and merge it please. Thanks.

@Rocksnake Rocksnake requested a review from anuraaga July 5, 2021 17:13
@Rocksnake
Copy link
Copy Markdown
Contributor Author

截屏2021-07-06 10 46 30

Does anyone know the reason for this problem, I need you help to solve it. The last check is no-error, I only modify three lines of annotation this time.

@Rocksnake
Copy link
Copy Markdown
Contributor Author

Could anyone merge this branch into main, I have solved all above problem, great thanks.

@jkwatson
Copy link
Copy Markdown
Contributor

jkwatson commented Jul 7, 2021

Could anyone merge this branch into main, I have solved all above problem, great thanks.

You still haven't removed the methods I asked you to. Please do so.

@Rocksnake
Copy link
Copy Markdown
Contributor Author

Could anyone merge this branch into main, I have solved all above problem, great thanks.

You still haven't removed the methods I asked you to. Please do so.

I haved removed these methods, please check again, thank you!

@jkwatson
Copy link
Copy Markdown
Contributor

This PR needs to be rebased against the main branch before we can merge it.

@jkwatson
Copy link
Copy Markdown
Contributor

@Rocksnake this needs a rebase. Will you be able to get to it soon?

@Rocksnake
Copy link
Copy Markdown
Contributor Author

@Rocksnake this needs a rebase. Will you be able to get to it soon?

Ok, I will rebased it this day.

@Rocksnake Rocksnake closed this Jul 20, 2021
@Rocksnake Rocksnake deleted the fix/add_factories_for_samplingResult branch July 20, 2021 01:49
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.

Add factories for SamplingResult

5 participants