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

Support question mark in wildcard #2875

Merged
merged 10 commits into from
Feb 10, 2022

Conversation

reyang
Copy link
Member

@reyang reyang commented Feb 8, 2022

Previously we only support * in wildcards, not ?.
This PR added ? support.

"Indirectly" related to open-telemetry/opentelemetry-specification#2325 (this PR only touches the provider/source part, not the View part).

@reyang reyang requested a review from a team February 8, 2022 20:45
Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

  1. Need changelog entry
  2. I suppose we didn't have unit test for tracing's AddSource with wildcard?

@codecov
Copy link

codecov bot commented Feb 8, 2022

Codecov Report

Merging #2875 (1b91fb0) into main (b1d57e9) will decrease coverage by 0.02%.
The diff coverage is 93.75%.

❗ Current head 1b91fb0 differs from pull request most recent head ad683fd. Consider uploading reports for the commit ad683fd to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2875      +/-   ##
==========================================
- Coverage   84.22%   84.20%   -0.03%     
==========================================
  Files         250      251       +1     
  Lines        8883     8883              
==========================================
- Hits         7482     7480       -2     
- Misses       1401     1403       +2     
Impacted Files Coverage Δ
src/OpenTelemetry/Internal/WildcardHelper.cs 88.88% <88.88%> (ø)
src/OpenTelemetry/Metrics/MeterProviderSdk.cs 87.02% <100.00%> (-0.11%) ⬇️
src/OpenTelemetry/Trace/TracerProviderSdk.cs 96.40% <100.00%> (-0.10%) ⬇️
...ter.ZPages/Implementation/ZPagesActivityTracker.cs 97.14% <0.00%> (-2.86%) ⬇️
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 71.29% <0.00%> (-0.93%) ⬇️
...Telemetry/Internal/SelfDiagnosticsEventListener.cs 97.65% <0.00%> (+0.78%) ⬆️

@reyang
Copy link
Member Author

reyang commented Feb 8, 2022

  1. Need changelog entry
  2. I suppose we didn't have unit test for tracing's AddSource with wildcard?

Changelog is already included in the PR.
I'm working on the unit test for tracing part, got interrupted by other things, will update the PR later today.

Comment on lines 84 to 88
if (meterSources.Any(s => s.Contains('*')))
{
var regex = GetWildcardRegex(meterSources);
var regex = this.GetWildcardRegex(meterSources);
shouldListenTo = instrument => regex.IsMatch(instrument.Meter.Name);
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a to a contains check for * and ? now?

Copy link
Member Author

Choose a reason for hiding this comment

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

YES 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

I've fixed this and added test cases.
Not sure if it'll be better to extract the s.Contains('*') || s.Contains('?') logic into a common helper, looks like it is currently used in 3 places.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if it'll be better to extract the s.Contains('*') || s.Contains('?') logic into a common helper, looks like it is currently used in 3 places.

I think it'd be a decent minor improvement, so something like:

internal static bool ContainsWildcard(string s)
{
    return s.Contains('*') || s.Contains('?');
}

...

if (meterSources.Any(ContainsWildcard))

but, I'm ok 👍 without if you think it reads better without the helper

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe an extension method on String class? 😆

Copy link
Member

Choose a reason for hiding this comment

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

That'd work too!

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the PR by extracting the wildcard logics to WildcardHelper.

I didn't use String extension method because it could be too noisy (e.g. if someone is using Intellisense).

Copy link
Member

Choose a reason for hiding this comment

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

I didn't use String extension method because it could be too noisy (e.g. if someone is using Intellisense).

Yea I think that's a good call. I was thinking that too, but thought maybe since it'd be internal it'd just affect us and not the whole 🌏

Copy link
Member

@alanwest alanwest left a comment

Choose a reason for hiding this comment

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

LWTM (Looks wild to me)

@cijothomas
Copy link
Member

Considering we are close to 1.2 stable release, i'll leave it open for a day to give more reviewers an opportunity to spot anything risky in this PR.

@cijothomas cijothomas merged commit 1b5765b into open-telemetry:main Feb 10, 2022
@reyang reyang deleted the reyang/wildcard branch February 15, 2022 05:04
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.

4 participants