Skip to content

Attributes rule based sampler#70

Merged
anuraaga merged 15 commits intoopen-telemetry:mainfrom
iNikem:url-sampler
Sep 2, 2021
Merged

Attributes rule based sampler#70
anuraaga merged 15 commits intoopen-telemetry:mainfrom
iNikem:url-sampler

Conversation

@iNikem
Copy link
Copy Markdown
Contributor

@iNikem iNikem commented Aug 26, 2021

Closes #65

Supersedes #66

@iNikem iNikem requested a review from a team August 26, 2021 08:34
Comment on lines +14 to +16
final AttributeKey<String> attributeKey;
final Sampler delegate;
final Pattern pattern;
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.

bold

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.

WDYM? :)

final Sampler delegate;
final Pattern pattern;

SamplingRule(AttributeKey<String> attributeKey, String pattern, Sampler delegate) {
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.

what would you think about only accepting pre-compiled Patterns here, so bad patterns are the responsibility of the user?

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.

The user is calling the builder so we would need to make the API change there. But we have a goal to optimize exact-match / prefix-match cases by not using Pattern (which Java Pattern itself should do, but doesn't...). I think String is fine

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.

Bad patterns are user's responsibility anyway

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.

final Sampler delegate;
final Pattern pattern;

SamplingRule(AttributeKey<String> attributeKey, String pattern, Sampler delegate) {
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.

The user is calling the builder so we would need to make the API change there. But we have a goal to optimize exact-match / prefix-match cases by not using Pattern (which Java Pattern itself should do, but doesn't...). I think String is fine


@Test
public void testThatDelegatesIfNoPatternsGiven() {
RuleBasedRoutingSampler sampler = new RuleBasedRoutingSampler(emptyList(), SPAN_KIND, delegate);
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.

Use public API (builder) as much as possible in tests unless specific reason not too. For example, to catch a non-static builder method :)

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 did and I think the end result is much worse :( What was one-liners, now is a longer line plus a 5-line method. Confirms my opinion that builders are oftentimes overrated :(

iNikem and others added 2 commits August 27, 2021 09:59
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
public RuleBasedRoutingSamplerBuilder drop(AttributeKey<String> attributeKey, String pattern) {
rules.add(
new SamplingRule(
requireNonNull(attributeKey), requireNonNull(pattern), Sampler.alwaysOff()));
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.

Put requireNonNull on their own line and add the name parameter. This provides better stack traces. The main reason to have the checks in the first place is to provide a good error experience to the users so we care about those details.

It's why it's not as important in the SamplingRule class since it's an implementation detail. It doesn't hurt, but it's redundant when making sure checks are on the public API, which is what we aim for.

Applies to some of the other methods in this PR too.

@anuraaga anuraaga merged commit b26bb07 into open-telemetry:main Sep 2, 2021
@iNikem iNikem deleted the url-sampler branch September 7, 2021 19:35
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.

http.url based Sampler

5 participants