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

Match spans against the instrumentation library and resource attributes #928

Merged
merged 4 commits into from
Oct 8, 2020

Conversation

zeitlinger
Copy link
Member

@zeitlinger zeitlinger commented May 7, 2020

Add the possibility to match spans against the instrumentation library.

This is how it works:

// version match
//  expected actual  match
//  nil      <blank> yes
//  nil      1       yes
//  <blank>  <blank> yes
//  <blank>  1       no
//  1        <blank> no
//  1        1       yes

You can decide to match against all versions (expected = nil), a specific version (e.g. expected = 1), or against "version not provided" (expected = <blank>).

match spans on resource attributes

Use case: drop attribute values (e.g. a password) for a certain version (host.image.version)

allow regexp when matching attribute value if it is a string

Regular expressions should only be prohibited if the expected value is not a string (because an implicit conversion to string would be unexpected).
If the expected value is a string, then a regular expression should be allowed.

@zeitlinger
Copy link
Member Author

@bogdandrutu this is the prototype that we discussed on gitter.

@codecov-io
Copy link

codecov-io commented May 7, 2020

Codecov Report

Merging #928 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #928      +/-   ##
==========================================
+ Coverage   91.35%   91.38%   +0.03%     
==========================================
  Files         280      281       +1     
  Lines       16661    16673      +12     
==========================================
+ Hits        15220    15236      +16     
+ Misses       1009     1007       -2     
+ Partials      432      430       -2     
Impacted Files Coverage Δ
...rnal/processor/filterset/strict/strictfilterset.go 100.00% <ø> (ø)
processor/metrics.go 69.62% <ø> (-2.15%) ⬇️
internal/processor/filterconfig/config.go 100.00% <100.00%> (ø)
...nternal/processor/filterhelper/attributematcher.go 100.00% <100.00%> (ø)
internal/processor/filterlog/filterlog.go 90.90% <100.00%> (-1.40%) ⬇️
internal/processor/filterspan/filterspan.go 100.00% <100.00%> (+3.33%) ⬆️
processor/attributesprocessor/attributes.go 90.90% <100.00%> (-1.95%) ⬇️
processor/spanprocessor/span.go 87.95% <100.00%> (-0.82%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64ec3f3...b78b488. Read the comment docs.

@@ -108,3 +110,16 @@ type Attribute struct {
// If it is not set, any value will match.
Value interface{} `mapstructure:"value"`
}

// version match
Copy link
Member

Choose a reason for hiding this comment

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

Move this comment to the Version argument?

internal/processor/filterspan/config.go Outdated Show resolved Hide resolved
Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

Unless this is somehow urgent I would like to block this until open-telemetry/opentelemetry-proto#149 is resolved. If proposals in open-telemetry/opentelemetry-proto#149 are accepted we don't need this PR.

@bogdandrutu
Copy link
Member

@tigrannajarayan the link is probably wrong

@tigrannajaryan
Copy link
Member

@bogdandrutu sorry, link updated.

@tigrannajaryan
Copy link
Member

open-telemetry/opentelemetry-proto#149 is closed, the decision is to keep InstrumentationLibrary.

This PR can now move forward, nothing blocks it.

@zeitlinger can you please rebase and fix the conflicts?

@zeitlinger
Copy link
Member Author

@tigrannajaryan @bogdandrutu

I see that the matching logic has changed - and this is an opportunity to revisit the design:

If we combine "library" and "version" into one string (concatenated by : as done e.g. by gradle), then the config would look like this:

    include:
      match_type: regexp
      libraries: ["bar", "foo:.*"]

This would match a library bar without a version or a library foo with any version.

I think it's also easier to understand than the previous version match matrix:

// version match
//  expected actual  match
//  nil      <blank> yes
//  nil      1       yes
//  <blank>  <blank> yes
//  <blank>  1       no
//  1        <blank> no
//  1        1       yes

Last, but not least, this would simplify the implementation, because it would be easy to use filterset.FilterSet

WDYT?

@zeitlinger
Copy link
Member Author

@tigrannajaryan @bogdandrutu

I see that the matching logic has changed - and this is an opportunity to revisit the design:

If we combine "library" and "version" into one string (concatenated by : as done e.g. by gradle), then the config would look like this:

    include:
      match_type: regexp
      libraries: ["bar", "foo:.*"]

This would match a library bar without a version or a library foo with any version.

I think it's also easier to understand than the previous version match matrix:

// version match
//  expected actual  match
//  nil      <blank> yes
//  nil      1       yes
//  <blank>  <blank> yes
//  <blank>  1       no
//  1        <blank> no
//  1        1       yes

Last, but not least, this would simplify the implementation, because it would be easy to use filterset.FilterSet

WDYT?

I found a way to avoid this and have and use the more natural

libraries: 
  - name: n
    version: v

@bogdandrutu
Copy link
Member

@zeitlinger looks like we are ready to merge this, so can you rebase and close all comments :)

@zeitlinger
Copy link
Member Author

@zeitlinger looks like we are ready to merge this, so can you rebase and close all comments :)

@bogdandrutu done - note that this PR is based on #929

@zeitlinger zeitlinger marked this pull request as ready for review September 9, 2020 19:59
internal/processor/filterspan/config.go Outdated Show resolved Hide resolved
@@ -100,3 +104,16 @@ type Attribute struct {
// If it is not set, any value will match.
Value interface{} `mapstructure:"value"`
}

type InstrumentationLibrary struct {
Copy link
Member

Choose a reason for hiding this comment

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

Comment if exported. Does this need to be exported?

Copy link
Member Author

Choose a reason for hiding this comment

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

actually not - neither does Attribute. Why did you export Attribute?
It's kind of a public interface, as it has the json structure.

@zeitlinger
Copy link
Member Author

@bogdandrutu I've tried to restart contrib-test - but it's still failing. Looks like a flaky test, but I wasn't able to figure out what it is.

@tigrannajaryan tigrannajaryan self-assigned this Oct 6, 2020
@zeitlinger zeitlinger changed the title match spans against the instrumentation library match spans against the instrumentation library and resource attributes Oct 6, 2020
@zeitlinger
Copy link
Member Author

Please also make similar changes for Logs.

I extracted the attribute matching logic - anything else?

@tigrannajaryan tigrannajaryan changed the title match spans against the instrumentation library and resource attributes Match spans against the instrumentation library and resource attributes Oct 6, 2020
@@ -71,7 +71,7 @@ type MatchProperties struct {
// Config configures the matching patterns used when matching span properties.
filterset.Config `mapstructure:",squash"`

// Note: For spans, one of Services, SpanNames or Attributes must be specified with a
// Note: For spans, one of Services, SpanNames, Attributes, Resources or Libraries must be specified with a
// non-empty value for a valid configuration.

// For logs, one of LogNames or Attributes must be specified with a
Copy link
Member

Choose a reason for hiding this comment

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

Update comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

what exactly?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// For logs, one of LogNames or Attributes must be specified with a
// For logs, one of LogNames, Attributes, Resources or Libraries must be specified with a

Don't we now support Resource and Libraries for logs too?

@tigrannajaryan
Copy link
Member

Mostly LGTM, just one minor comment left.

Normally we ask one PR to add one distinct piece of functionality. This PR adds filtering by resources and by library. Ideally it would be 2 separate PRs. I'll merge the PR as-is to avoid more work to split the PR. For the future please follow one PR - one feature principle.

@tigrannajaryan
Copy link
Member

The build failed, make sure it passes.

@zeitlinger
Copy link
Member Author

Ideally it would be 2 separate PRs.

it was 2 PRs initially, but it considerable effort to update both PRs with upstream

match spans on instrumentation library
allow regexp on attribute value if it is a string
@zeitlinger
Copy link
Member Author

@tigrannajaryan contrib-test seems to be flaky - other tests are working now

Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

LGTM, except one last comment. Can merge after that.

@@ -71,7 +71,7 @@ type MatchProperties struct {
// Config configures the matching patterns used when matching span properties.
filterset.Config `mapstructure:",squash"`

// Note: For spans, one of Services, SpanNames or Attributes must be specified with a
// Note: For spans, one of Services, SpanNames, Attributes, Resources or Libraries must be specified with a
// non-empty value for a valid configuration.

// For logs, one of LogNames or Attributes must be specified with a
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// For logs, one of LogNames or Attributes must be specified with a
// For logs, one of LogNames, Attributes, Resources or Libraries must be specified with a

Don't we now support Resource and Libraries for logs too?

@zeitlinger
Copy link
Member Author

LGTM, except one last comment. Can merge after that.

I double checked logs and we can and should support resources and libraries as well.

I didn't notice this because log filtering is not fully implemented - but the #1830 seems to do it. Once that is merged, I can also include support for resources and libraries.

match logs on instrumentation library
@zeitlinger
Copy link
Member Author

I didn't notice this because log filtering is not fully implemented - but the #1830 seems to do it. Once that is merged, I can also include support for resources and libraries.

Actually it was no problem to implement support - the only intersection with #1830 is a signature change to pass resource and library (which are also available on ResourceLogs

match logs on instrumentation library
match logs on instrumentation library
@zeitlinger
Copy link
Member Author

@tigrannajaryan please review again

@tigrannajaryan tigrannajaryan merged commit 393e98f into open-telemetry:master Oct 8, 2020
@tigrannajaryan
Copy link
Member

Thank you @zeitlinger

@zeitlinger zeitlinger deleted the extended-matcher branch October 9, 2020 07:36
@zeitlinger
Copy link
Member Author

@tigrannajaryan thanks for helping out!

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