-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[processor/transform] Add business logic for handling traces queries. #7300
Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
33715c7
[processor/transform] Add business logic for handling traces queries.
anuraaga d234f06
Global parser
anuraaga a778335
func aliases
anuraaga e4273ee
Start cleanups
anuraaga cc83968
Cleanups
anuraaga e408791
Extract methods for trace access
anuraaga 18ee45b
Remove register / unregisterFunction
anuraaga 0f3e6f9
statement -> query
anuraaga 98582e2
Split out setter
anuraaga f88a0be
keep -> keep_keys
anuraaga 3673a56
lint
anuraaga c55590a
TODO(reflect on reflect)
anuraaga d870f2a
invalid config test
anuraaga ab6e397
resource.attributes tests
anuraaga 43357f7
factory tests
anuraaga 75ae504
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
anuraaga bc8f619
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
anuraaga 70a87b4
Fix test
anuraaga 5a8b421
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
anuraaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,56 @@ | ||
// 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 traces // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/traces" | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/model/pdata" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" | ||
) | ||
|
||
type condFunc = func(span pdata.Span, il pdata.InstrumentationLibrary, resource pdata.Resource) bool | ||
|
||
func newConditionEvaluator(cond *common.Condition) (condFunc, error) { | ||
if cond == nil { | ||
return func(span pdata.Span, il pdata.InstrumentationLibrary, resource pdata.Resource) bool { | ||
return true | ||
}, nil | ||
anuraaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
left, err := newGetter(cond.Left) | ||
if err != nil { | ||
return nil, err | ||
} | ||
right, err := newGetter(cond.Right) | ||
if err != nil { | ||
return nil, err | ||
} | ||
anuraaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
switch cond.Op { | ||
case "==": | ||
return func(span pdata.Span, il pdata.InstrumentationLibrary, resource pdata.Resource) bool { | ||
a := left.get(span, il, resource) | ||
b := right.get(span, il, resource) | ||
return a == b | ||
}, nil | ||
anuraaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case "!=": | ||
return func(span pdata.Span, il pdata.InstrumentationLibrary, resource pdata.Resource) bool { | ||
return left.get(span, il, resource) != right.get(span, il, resource) | ||
}, nil | ||
} | ||
|
||
return nil, fmt.Errorf("unrecognized boolean operation %v", cond.Op) | ||
} |
136 changes: 136 additions & 0 deletions
136
processor/transformprocessor/internal/traces/condition_test.go
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,136 @@ | ||
// 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 traces | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/model/pdata" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/common" | ||
) | ||
|
||
func Test_newConditionEvaluator(t *testing.T) { | ||
span := pdata.NewSpan() | ||
span.SetName("bear") | ||
tests := []struct { | ||
name string | ||
cond *common.Condition | ||
matching pdata.Span | ||
}{ | ||
{ | ||
name: "literals match", | ||
cond: &common.Condition{ | ||
Left: common.Value{ | ||
String: strp("hello"), | ||
}, | ||
Right: common.Value{ | ||
String: strp("hello"), | ||
}, | ||
Op: "==", | ||
}, | ||
matching: span, | ||
}, | ||
{ | ||
name: "literals don't match", | ||
cond: &common.Condition{ | ||
Left: common.Value{ | ||
String: strp("hello"), | ||
}, | ||
Right: common.Value{ | ||
String: strp("goodbye"), | ||
}, | ||
Op: "!=", | ||
}, | ||
matching: span, | ||
}, | ||
{ | ||
name: "path expression matches", | ||
cond: &common.Condition{ | ||
Left: common.Value{ | ||
Path: &common.Path{ | ||
Fields: []common.Field{ | ||
{ | ||
Name: "name", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Right: common.Value{ | ||
String: strp("bear"), | ||
}, | ||
Op: "==", | ||
}, | ||
matching: span, | ||
}, | ||
{ | ||
name: "path expression not matches", | ||
cond: &common.Condition{ | ||
Left: common.Value{ | ||
Path: &common.Path{ | ||
Fields: []common.Field{ | ||
{ | ||
Name: "name", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Right: common.Value{ | ||
String: strp("bear"), | ||
}, | ||
Op: "==", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doh thanks |
||
}, | ||
matching: span, | ||
}, | ||
{ | ||
name: "no condition", | ||
cond: nil, | ||
matching: span, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
evaluate, err := newConditionEvaluator(tt.cond) | ||
assert.NoError(t, err) | ||
assert.True(t, evaluate(tt.matching, pdata.NewInstrumentationLibrary(), pdata.NewResource())) | ||
}) | ||
} | ||
|
||
t.Run("invalid", func(t *testing.T) { | ||
_, err := newConditionEvaluator(&common.Condition{ | ||
Left: common.Value{ | ||
String: strp("bear"), | ||
}, | ||
Op: "<>", | ||
Right: common.Value{ | ||
String: strp("cat"), | ||
}, | ||
}) | ||
assert.Error(t, err) | ||
}) | ||
} | ||
|
||
func strp(s string) *string { | ||
return &s | ||
} | ||
|
||
func intp(i int64) *int64 { | ||
return &i | ||
} | ||
|
||
func floatp(f float64) *float64 { | ||
return &f | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this a "3" stage check?
I think this way we don't have to repeat the checks on the "resource" for every span. I may have already mentioned this idea, but I think it may be an important optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks generally evaluate in well less than a microsecond right now so was hoping to do this as a future optimization. I don't think this effects the query DSL, just the implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are correct, but may affect the "supported" function signatures, so we better do not open yet the API to allow external funcs until we finalize that.