Skip to content

Support question mark in wildcard - #2875

Merged
cijothomas merged 10 commits into
open-telemetry:mainfrom
reyang:reyang/wildcard
Feb 10, 2022
Merged

Support question mark in wildcard#2875
cijothomas merged 10 commits into
open-telemetry:mainfrom
reyang:reyang/wildcard

Conversation

@reyang

@reyang reyang commented Feb 8, 2022

Copy link
Copy Markdown
Member

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
Comment thread src/OpenTelemetry/ProviderExtensions.cs Outdated

@cijothomas cijothomas left a comment

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.

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

@codecov

codecov Bot commented Feb 8, 2022

Copy link
Copy Markdown

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

reyang commented Feb 8, 2022

Copy link
Copy Markdown
Member Author
  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 thread test/OpenTelemetry.Tests/Metrics/MetricAPITest.cs
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 🌏

@alanwest alanwest left a comment

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.

LWTM (Looks wild to me)

Comment thread src/OpenTelemetry.Api/CHANGELOG.md Outdated
reyang and others added 2 commits February 8, 2022 17:43
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
@cijothomas

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