-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/datadog]: add ignore_resources configuration option (#3245)
* [exporter/datadog]: wip add blocklist for resources. wip test and documentation * [exporter/datadog]: clean up ignore resources defaults * [exporter/datadog]: remove unused helpers * [exporter/datadog]: add yaml config details * [exporter/datadog]: add links to datadog agent funcs * [exporter/datadog]: seperate blocklist into its own file and tests * [exporter/datadog]: fix copyrights * [exporter/datadog]: pr feedback update code comments and update naming conventions, clean up code comments * [exporter/datadog]: add validatioon block to config * [exporter/datadog]: update config * [exporter/datadog]: linting * [exporter/datadog]: wip add helper tests * [exporter/datadog]: add helper tests * [exporter/datadog]: linting * [exporter/datadog]: use mustcompile for denylist * [exporter/datadog]: fix tests for new config/denylist behavior * [exporter/datadog]: add ignore resources validation test for config
- Loading branch information
1 parent
64a5d55
commit f853a99
Showing
13 changed files
with
363 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package datadogexporter | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/trace/exportable/pb" | ||
) | ||
|
||
// Denylister holds a list of regular expressions which will match resources | ||
// on spans that should be dropped. | ||
// From: https://github.com/DataDog/datadog-agent/blob/a6872e436681ea2136cf8a67465e99fdb4450519/pkg/trace/filters/blacklister.go#L15-L19 | ||
type Denylister struct { | ||
list []*regexp.Regexp | ||
} | ||
|
||
// Allows returns true if the Denylister permits this span. | ||
// From: https://github.com/DataDog/datadog-agent/blob/a6872e436681ea2136cf8a67465e99fdb4450519/pkg/trace/filters/blacklister.go#L21-L29 | ||
func (f *Denylister) Allows(span *pb.Span) bool { | ||
for _, entry := range f.list { | ||
if entry.MatchString(span.Resource) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
// NewDenylister creates a new Denylister based on the given list of | ||
// regular expressions. | ||
// From: https://github.com/DataDog/datadog-agent/blob/a6872e436681ea2136cf8a67465e99fdb4450519/pkg/trace/filters/blacklister.go#L41-L45 | ||
func NewDenylister(exprs []string) *Denylister { | ||
return &Denylister{list: compileRules(exprs)} | ||
} | ||
|
||
// compileRules compiles as many rules as possible from the list of expressions. | ||
// From: https://github.com/DataDog/datadog-agent/blob/a6872e436681ea2136cf8a67465e99fdb4450519/pkg/trace/filters/blacklister.go#L47-L59 | ||
func compileRules(exprs []string) []*regexp.Regexp { | ||
list := make([]*regexp.Regexp, 0, len(exprs)) | ||
for _, entry := range exprs { | ||
rule := regexp.MustCompile(entry) | ||
list = append(list, rule) | ||
} | ||
return list | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package datadogexporter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/trace/exportable/pb" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestSpan returns a fix span with hardcoded info, useful for reproducible tests | ||
// https://github.com/DataDog/datadog-agent/blob/d3a4cd66314d70162e2c76d2481f4b93455cf717/pkg/trace/test/testutil/span.go#L372 | ||
func testSpan() *pb.Span { | ||
return &pb.Span{ | ||
Duration: 10000000, | ||
Error: 0, | ||
Resource: "GET /some/raclette", | ||
Service: "django", | ||
Name: "django.controller", | ||
SpanID: 42, | ||
Start: 1472732573337575936, | ||
TraceID: 424242, | ||
Meta: map[string]string{ | ||
"user": "eric", | ||
"pool": "fondue", | ||
}, | ||
Metrics: map[string]float64{ | ||
"cheese_weight": 100000.0, | ||
}, | ||
ParentID: 1111, | ||
Type: "http", | ||
} | ||
} | ||
|
||
func TestDenylister(t *testing.T) { | ||
tests := []struct { | ||
filter []string | ||
resource string | ||
expectation bool | ||
}{ | ||
{[]string{"/foo/bar"}, "/foo/bar", false}, | ||
{[]string{"/foo/b.r"}, "/foo/bar", false}, | ||
{[]string{"[0-9]+"}, "/abcde", true}, | ||
{[]string{"[0-9]+"}, "/abcde123", false}, | ||
{[]string{"\\(foobar\\)"}, "(foobar)", false}, | ||
{[]string{"\\(foobar\\)"}, "(bar)", true}, | ||
{[]string{"(GET|POST) /healthcheck"}, "GET /foobar", true}, | ||
{[]string{"(GET|POST) /healthcheck"}, "GET /healthcheck", false}, | ||
{[]string{"(GET|POST) /healthcheck"}, "POST /healthcheck", false}, | ||
{[]string{"SELECT COUNT\\(\\*\\) FROM BAR"}, "SELECT COUNT(*) FROM BAR", false}, | ||
{[]string{"ABC+", "W+"}, "ABCCCC", false}, | ||
{[]string{"ABC+", "W+"}, "WWW", false}, | ||
} | ||
|
||
for _, test := range tests { | ||
span := testSpan() | ||
span.Resource = test.resource | ||
filter := NewDenylister(test.filter) | ||
|
||
assert.Equal(t, test.expectation, filter.Allows(span)) | ||
} | ||
} | ||
|
||
func TestCompileRules(t *testing.T) { | ||
filter := NewDenylister([]string{"\n{6}"}) | ||
for i := 0; i < 100; i++ { | ||
span := testSpan() | ||
assert.True(t, filter.Allows(span)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.