Skip to content

Commit

Permalink
Update names
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerHelmuth committed Feb 6, 2023
1 parent 5403d72 commit 3e8fe08
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
18 changes: 10 additions & 8 deletions processor/filterprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,28 +324,30 @@ The filter processor has access to all the [factory functions of the OTTL](https
In addition, the processor defines a few of its own functions:

**Metrics only functions**
- [HasAttrKeyOnDatapoint](#HasAttrKeyOnDatapoint)
- [HasAttrOnDatapoint](#HasAttrOnDatapoint)
- [HasAttributeOnDatapointWithValue](#HasAttributeOnDatapointWithValue)

#### HasAttrOnDatapoint
#### HasAttrKeyOnDatapoint

`HasAttrOnDatapoint(key)`
`HasAttrKeyOnDatapoint(key)`

Returns `true` if the given key appears in the attribute map of any datapoint on a metric.
`key` must be a string.

Examples:

- `HasAttrOnDatapoint("http.target")`
- `HasAttrKeyOnDatapoint("http.method")`

#### HasAttributeOnDatapointWithValue
#### HasAttrOnDatapoint

`HasAttributeOnDatapointWithValue(key, value)`
`HasAttrOnDatapoint(key, value)`

Returns `true` if the given key and corresponding value appears in the attribute map of any datapoint on a metric.
Returns `true` if the given key and value appears in the attribute map of any datapoint on a metric.
`key` and `value` must both be strings.

Examples:

- `HasAttrOnDatapoint("http.target")`
- `HasAttrOnDatapoint("http.method", "GET")`

### OTTL Examples

Expand Down
6 changes: 3 additions & 3 deletions processor/filterprocessor/internal/common/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ func functions[K any]() map[string]interface{} {

func metricFunctions() map[string]interface{} {
funcs := functions[ottlmetric.TransformContext]()
funcs["HasAttrKeyOnDatapoint"] = hasAttributeKeyOnDatapoint
funcs["HasAttrOnDatapoint"] = hasAttributeOnDatapoint
funcs["HasAttrOnDatapointWithValue"] = hasAttributeOnDatapointWithValue

return funcs
}

func hasAttributeOnDatapointWithValue(key string, expectedVal string) (ottl.ExprFunc[ottlmetric.TransformContext], error) {
func hasAttributeOnDatapoint(key string, expectedVal string) (ottl.ExprFunc[ottlmetric.TransformContext], error) {
return func(ctx context.Context, tCtx ottlmetric.TransformContext) (interface{}, error) {
return checkDataPoints(tCtx, key, &expectedVal)
}, nil
}

func hasAttributeOnDatapoint(key string) (ottl.ExprFunc[ottlmetric.TransformContext], error) {
func hasAttributeKeyOnDatapoint(key string) (ottl.ExprFunc[ottlmetric.TransformContext], error) {
return func(ctx context.Context, tCtx ottlmetric.TransformContext) (interface{}, error) {
return checkDataPoints(tCtx, key, nil)
}, nil
Expand Down
8 changes: 4 additions & 4 deletions processor/filterprocessor/internal/common/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric"
)

func Test_HasAttrOnDatapoint(t *testing.T) {
func Test_HasAttrKeyOnDatapoint(t *testing.T) {
tests := []struct {
name string
key string
Expand Down Expand Up @@ -135,7 +135,7 @@ func Test_HasAttrOnDatapoint(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
exprFunc, err := hasAttributeOnDatapoint(tt.key)
exprFunc, err := hasAttributeKeyOnDatapoint(tt.key)
assert.NoError(t, err)
result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pcommon.NewInstrumentationScope(), pcommon.NewResource()))
assert.NoError(t, err)
Expand All @@ -144,7 +144,7 @@ func Test_HasAttrOnDatapoint(t *testing.T) {
}
}

func Test_HasAttrOnDatapointWithValue(t *testing.T) {
func Test_HasAttrOnDatapoint(t *testing.T) {
tests := []struct {
name string
key string
Expand Down Expand Up @@ -360,7 +360,7 @@ func Test_HasAttrOnDatapointWithValue(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
exprFunc, err := hasAttributeOnDatapoint(tt.key)
exprFunc, err := hasAttributeOnDatapoint(tt.key, tt.expectedVal)
assert.NoError(t, err)
result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pcommon.NewInstrumentationScope(), pcommon.NewResource()))
assert.NoError(t, err)
Expand Down

0 comments on commit 3e8fe08

Please sign in to comment.