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

Attributes rule based sampler #70

Merged
merged 15 commits into from
Sep 2, 2021
Merged

Conversation

iNikem
Copy link
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
Contributor

Choose a reason for hiding this comment

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

bold

Copy link
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
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
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
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
Contributor

Choose a reason for hiding this comment

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

dependencyManagement/build.gradle.kts Outdated Show resolved Hide resolved
final Sampler delegate;
final Pattern pattern;

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

settings.gradle.kts Outdated Show resolved Hide resolved
public RuleBasedRoutingSamplerBuilder drop(AttributeKey<String> attributeKey, String pattern) {
rules.add(
new SamplingRule(
requireNonNull(attributeKey), requireNonNull(pattern), Sampler.alwaysOff()));
Copy link
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.

settings.gradle.kts Outdated Show resolved Hide resolved
@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