Skip to content

Commit 8638e7d

Browse files
authored
Remove routes > ignored_patterns configuration option (#33)
* Remove routes > ignored_patterns configuration option * Fix integration test
1 parent 18be1ab commit 8638e7d

File tree

16 files changed

+29
-198
lines changed

16 files changed

+29
-198
lines changed

pkg/export/debug/debug_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ func traceFuncHelper(t *testing.T, tracePrinter TracePrinter) string {
6666
Statement: "statement",
6767
}
6868

69-
fakeSpan.SetIgnoreMetrics()
70-
7169
// redirect the TracePrinter function stdout to a pipe so that we can
7270
// capture and return its output
7371
r, w, err := os.Pipe()
@@ -115,7 +113,7 @@ func TestTracePrinterResolve_PrinterCounter(t *testing.T) {
115113
func TestTracePrinterResolve_PrinterJSON(t *testing.T) {
116114
// test as separate chunks to exclude timestamps (start, handlerStart, end)
117115

118-
prefix := `[{"type":"HTTP","ignoreSpan":"Metrics","peer":"peer","peerPort":"1234",` +
116+
prefix := `[{"type":"HTTP","peer":"peer","peerPort":"1234",` +
119117
`"host":"host","hostPort":"5678","traceID":"01020300000000000000000000000000",` +
120118
`"spanID":"0102030000000000","parentSpanID":"0102040000000000","flags":"1",` +
121119
`"peerName":"peername","hostName":"hostname","kind":"SPAN_KIND_SERVER","`
@@ -136,7 +134,6 @@ func TestTracePrinterResolve_PrinterJSONIndent(t *testing.T) {
136134
prefix := `[
137135
{
138136
"type": "HTTP",
139-
"ignoreSpan": "Metrics",
140137
"peer": "peer",
141138
"peerPort": "1234",
142139
"host": "host",

pkg/export/otel/metrics.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,6 @@ func (mr *MetricsReporter) reportMetrics(_ context.Context) {
10401040
if s.InternalSignal() {
10411041
continue
10421042
}
1043-
// If we are ignoring this span because of route patterns, don't do anything
1044-
if s.IgnoreMetrics() {
1045-
continue
1046-
}
10471043
reporter, err := mr.reporters.For(&s.Service)
10481044
if err != nil {
10491045
mlog().Error("unexpected error creating OTEL resource. Ignoring metric",

pkg/export/otel/traces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (tr *tracesOTELReceiver) getConstantAttributes() (map[attr.Name]struct{}, e
204204
}
205205

206206
func (tr *tracesOTELReceiver) spanDiscarded(span *request.Span) bool {
207-
return span.IgnoreTraces() || span.Service.ExportsOTelTraces() || !tr.acceptSpan(span)
207+
return span.Service.ExportsOTelTraces() || !tr.acceptSpan(span)
208208
}
209209

210210
func (tr *tracesOTELReceiver) processSpans(ctx context.Context, exp exporter.Traces, spans []request.Span, traceAttrs map[attr.Name]struct{}, sampler trace.Sampler) {

pkg/export/prom/prom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ func (r *metricsReporter) otelSpanObserved(span *request.Span) bool {
733733
}
734734

735735
func (r *metricsReporter) otelSpanFiltered(span *request.Span) bool {
736-
return span.InternalSignal() || span.IgnoreMetrics()
736+
return span.InternalSignal()
737737
}
738738

739739
//nolint:cyclop

pkg/export/prom/prom_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,45 +314,32 @@ func TestSpanMetricsDiscarded(t *testing.T) {
314314
svcExportTraces := svc.Attrs{}
315315
svcExportTraces.SetExportsOTelTraces()
316316

317-
ignoredSpan := request.Span{Service: svcExportTraces, Type: request.EventTypeHTTPClient, Method: "GET", Route: "/v1/traces", RequestStart: 100, End: 200}
318-
ignoredSpan.SetIgnoreMetrics()
319-
320317
tests := []struct {
321318
name string
322319
span request.Span
323320
discarded bool
324-
filtered bool
325321
}{
326322
{
327323
name: "Foo span is not filtered",
328324
span: request.Span{Service: svcNoExport, Type: request.EventTypeHTTPClient, Method: "GET", Route: "/foo", RequestStart: 100, End: 200},
329325
discarded: false,
330-
filtered: false,
331326
},
332327
{
333328
name: "/v1/metrics span is filtered",
334329
span: request.Span{Service: svcExportMetrics, Type: request.EventTypeHTTPClient, Method: "GET", Route: "/v1/metrics", RequestStart: 100, End: 200},
335330
discarded: true,
336-
filtered: false,
337-
},
338-
{
339-
name: "/v1/traces span is filtered because we ignore this span",
340-
span: ignoredSpan,
341-
discarded: false,
342-
filtered: true,
343331
},
344332
{
345333
name: "/v1/traces span is not filtered",
346334
span: request.Span{Service: svcExportTraces, Type: request.EventTypeHTTPClient, Method: "GET", Route: "/v1/traces", RequestStart: 100, End: 200},
347335
discarded: false,
348-
filtered: false,
349336
},
350337
}
351338

352339
for _, tt := range tests {
353340
t.Run(tt.name, func(t *testing.T) {
354341
assert.Equal(t, tt.discarded, !(mr.otelSpanObserved(&tt.span)), tt.name)
355-
assert.Equal(t, tt.filtered, mr.otelSpanFiltered(&tt.span), tt.name)
342+
assert.False(t, mr.otelSpanFiltered(&tt.span), tt.name)
356343
})
357344
}
358345
}

pkg/internal/request/span.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,6 @@ func (t EventType) MarshalText() ([]byte, error) {
9292
return []byte(t.String()), nil
9393
}
9494

95-
type ignoreMode uint8
96-
97-
const (
98-
ignoreMetrics ignoreMode = 0x1
99-
ignoreTraces ignoreMode = 0x2
100-
)
101-
102-
func (m ignoreMode) String() string {
103-
result := ""
104-
105-
if (m & ignoreMetrics) == ignoreMetrics {
106-
result += "Metrics"
107-
}
108-
if (m & ignoreTraces) == ignoreTraces {
109-
result += "Traces"
110-
}
111-
112-
return result
113-
}
114-
115-
func (m ignoreMode) MarshalText() ([]byte, error) {
116-
return []byte(m.String()), nil
117-
}
118-
11995
const (
12096
MessagingPublish = "publish"
12197
MessagingProcess = "process"
@@ -145,7 +121,6 @@ type PidInfo struct {
145121
// SpanPromGetters and getDefinitions in pkg/export/attributes/attr_defs.go
146122
type Span struct {
147123
Type EventType `json:"type"`
148-
IgnoreSpan ignoreMode `json:"ignoreSpan"`
149124
Method string `json:"-"`
150125
Path string `json:"-"`
151126
Route string `json:"-"`
@@ -341,30 +316,6 @@ func (s *Span) IsClientSpan() bool {
341316
return false
342317
}
343318

344-
func (s *Span) setIgnoreFlag(flag ignoreMode) {
345-
s.IgnoreSpan |= flag
346-
}
347-
348-
func (s *Span) isIgnored(flag ignoreMode) bool {
349-
return (s.IgnoreSpan & flag) == flag
350-
}
351-
352-
func (s *Span) SetIgnoreMetrics() {
353-
s.setIgnoreFlag(ignoreMetrics)
354-
}
355-
356-
func (s *Span) SetIgnoreTraces() {
357-
s.setIgnoreFlag(ignoreTraces)
358-
}
359-
360-
func (s *Span) IgnoreMetrics() bool {
361-
return s.isIgnored(ignoreMetrics)
362-
}
363-
364-
func (s *Span) IgnoreTraces() bool {
365-
return s.isIgnored(ignoreTraces)
366-
}
367-
368319
const (
369320
StatusCodeUnset = "STATUS_CODE_UNSET"
370321
StatusCodeError = "STATUS_CODE_ERROR"

pkg/internal/request/span_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,6 @@ func TestEventTypeString(t *testing.T) {
4646
}
4747
}
4848

49-
func TestIgnoreModeString(t *testing.T) {
50-
modeStringMap := map[ignoreMode]string{
51-
ignoreMetrics: "Metrics",
52-
ignoreTraces: "Traces",
53-
ignoreMode(0): "",
54-
ignoreTraces | ignoreMetrics: "MetricsTraces",
55-
}
56-
57-
for mode, str := range modeStringMap {
58-
assert.Equal(t, mode.String(), str)
59-
}
60-
}
61-
6249
func TestKindString(t *testing.T) {
6350
m := map[*Span]string{
6451
{Type: EventTypeHTTP}: "SPAN_KIND_SERVER",
@@ -181,7 +168,6 @@ func TestSerializeJSONSpans(t *testing.T) {
181168
test := func(t *testing.T, tData *testData) {
182169
span := Span{
183170
Type: tData.eventType,
184-
IgnoreSpan: ignoreMetrics,
185171
Method: "method",
186172
Path: "path",
187173
Route: "route",
@@ -216,7 +202,6 @@ func TestSerializeJSONSpans(t *testing.T) {
216202
assert.Equal(t, map[string]any{
217203
"type": tData.eventType.String(),
218204
"kind": span.ServiceGraphKind(),
219-
"ignoreSpan": "Metrics",
220205
"peer": "peer",
221206
"peerPort": "1234",
222207
"host": "host",

pkg/transform/routes.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ type RoutesConfig struct {
4747
// Unmatch specifies what to do when a route pattern is not matched
4848
Unmatch UnmatchType `yaml:"unmatched"`
4949
// Patterns of the paths that will match to a route
50-
Patterns []string `yaml:"patterns"`
51-
IgnorePatterns []string `yaml:"ignored_patterns"`
52-
IgnoredEvents IgnoreMode `yaml:"ignore_mode"`
50+
Patterns []string `yaml:"patterns"`
5351
// Character that will be used to replace route segments
5452
WildcardChar string `yaml:"wildcard_char,omitempty"`
5553
}
@@ -80,14 +78,7 @@ func (rn *routerNode) provideRoutes(_ context.Context) (swarm.RunFunc, error) {
8078
return nil, err
8179
}
8280
matcher := route.NewMatcher(rc.Patterns)
83-
discarder := route.NewMatcher(rc.IgnorePatterns)
8481
routesEnabled := len(rc.Patterns) > 0
85-
ignoreEnabled := len(rc.IgnorePatterns) > 0
86-
87-
ignoreMode := rc.IgnoredEvents
88-
if ignoreMode == "" {
89-
ignoreMode = IgnoreDefault
90-
}
9182

9283
in := rn.input.Subscribe()
9384
out := rn.output
@@ -98,16 +89,6 @@ func (rn *routerNode) provideRoutes(_ context.Context) (swarm.RunFunc, error) {
9889
for spans := range in {
9990
for i := range spans {
10091
s := &spans[i]
101-
if ignoreEnabled {
102-
if discarder.Find(s.Path) != "" {
103-
if ignoreMode == IgnoreAll {
104-
s.SetIgnoreMetrics()
105-
s.SetIgnoreTraces()
106-
}
107-
// we can't discard it here, ignoring is selective (metrics | traces)
108-
setSpanIgnoreMode(ignoreMode, s)
109-
}
110-
}
11192
if routesEnabled {
11293
s.Route = matcher.Find(s.Path)
11394
}
@@ -174,12 +155,3 @@ func classifyFromPath(rc *RoutesConfig, s *request.Span) {
174155
s.Route = route.ClusterPath(s.Path, rc.WildcardChar[0])
175156
}
176157
}
177-
178-
func setSpanIgnoreMode(mode IgnoreMode, s *request.Span) {
179-
switch mode {
180-
case IgnoreMetrics:
181-
s.SetIgnoreMetrics()
182-
case IgnoreTraces:
183-
s.SetIgnoreTraces()
184-
}
185-
}

pkg/transform/routes_test.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -118,43 +118,6 @@ func TestUnmatchedAuto(t *testing.T) {
118118
}
119119
}
120120

121-
func TestIgnoreRoutes(t *testing.T) {
122-
input := msg.NewQueue[[]request.Span](msg.ChannelBufferLen(10))
123-
output := msg.NewQueue[[]request.Span](msg.ChannelBufferLen(10))
124-
router, err := RoutesProvider(&RoutesConfig{
125-
Unmatch: UnmatchPath, Patterns: []string{"/user/:id", "/v1/metrics"},
126-
IgnorePatterns: []string{"/v1/metrics/*", "/v1/traces/*", "/exact"},
127-
},
128-
input, output)(t.Context())
129-
require.NoError(t, err)
130-
out := output.Subscribe()
131-
defer input.Close()
132-
go router(t.Context())
133-
input.Send([]request.Span{{Path: "/user/1234"}})
134-
input.Send([]request.Span{{Path: "/v1/metrics"}}) // this is in routes and ignore, ignore takes precedence
135-
input.Send([]request.Span{{Path: "/v1/traces/1234/test"}})
136-
input.Send([]request.Span{{Path: "/v1/metrics/1234/test"}}) // this is in routes and ignore, ignore takes precedence
137-
input.Send([]request.Span{{Path: "/v1/traces"}})
138-
input.Send([]request.Span{{Path: "/exact"}})
139-
input.Send([]request.Span{{Path: "/some/path"}})
140-
assert.Equal(t, []request.Span{{
141-
Path: "/user/1234",
142-
Route: "/user/:id",
143-
}}, filterIgnored(func() []request.Span { return testutil.ReadChannel(t, out, testTimeout) }))
144-
assert.Equal(t, []request.Span{{
145-
Path: "/some/path",
146-
Route: "/some/path",
147-
}}, filterIgnored(func() []request.Span { return testutil.ReadChannel(t, out, testTimeout) }))
148-
}
149-
150-
func TestIgnoreMode(t *testing.T) {
151-
s := request.Span{Path: "/user/1234"}
152-
setSpanIgnoreMode(IgnoreTraces, &s)
153-
assert.True(t, s.IgnoreTraces())
154-
setSpanIgnoreMode(IgnoreMetrics, &s)
155-
assert.True(t, s.IgnoreMetrics())
156-
}
157-
158121
func BenchmarkRoutesProvider_Wildcard(b *testing.B) {
159122
benchProvider(b, UnmatchWildcard)
160123
}
@@ -188,27 +151,3 @@ func benchProvider(b *testing.B, unmatch UnmatchType) {
188151
<-outCh
189152
}
190153
}
191-
192-
func filterIgnored(reader func() []request.Span) []request.Span {
193-
for {
194-
input := reader()
195-
output := make([]request.Span, 0, len(input))
196-
for i := range input {
197-
s := &input[i]
198-
199-
if s.IgnoreMetrics() {
200-
continue
201-
}
202-
203-
if s.IgnoreTraces() {
204-
continue
205-
}
206-
207-
output = append(output, *s)
208-
}
209-
210-
if len(output) > 0 {
211-
return output
212-
}
213-
}
214-
}

test/integration/configs/instrumenter-config-grpc-export.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
routes:
22
patterns:
33
- /basic/:rnd
4-
ignored_patterns:
5-
- /metrics
6-
ignore_mode: traces
74
unmatched: path
5+
filter:
6+
application:
7+
url_path:
8+
not_match: /metrics
89
otel_metrics_export:
910
endpoint: http://otelcol:4317
1011
protocol: grpc

0 commit comments

Comments
 (0)