From 3e8fe0887cdfeb9e2312cd292e8f1f79153e15fe Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Sun, 5 Feb 2023 20:32:00 -0800 Subject: [PATCH] Update names --- processor/filterprocessor/README.md | 18 ++++++++++-------- .../filterprocessor/internal/common/parser.go | 6 +++--- .../internal/common/parser_test.go | 8 ++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/processor/filterprocessor/README.md b/processor/filterprocessor/README.md index 8d930da202e8..cc1489b871a6 100644 --- a/processor/filterprocessor/README.md +++ b/processor/filterprocessor/README.md @@ -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 diff --git a/processor/filterprocessor/internal/common/parser.go b/processor/filterprocessor/internal/common/parser.go index cf4080d2c3d2..ff378dd2b0b7 100644 --- a/processor/filterprocessor/internal/common/parser.go +++ b/processor/filterprocessor/internal/common/parser.go @@ -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 diff --git a/processor/filterprocessor/internal/common/parser_test.go b/processor/filterprocessor/internal/common/parser_test.go index e971a89725ae..975c40de3a35 100644 --- a/processor/filterprocessor/internal/common/parser_test.go +++ b/processor/filterprocessor/internal/common/parser_test.go @@ -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 @@ -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) @@ -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 @@ -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)