From 1ee3ab3330468a61e60a2fe2789f666abefd4d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Mon, 15 May 2023 11:58:42 +0200 Subject: [PATCH] Fix the factory name for the limit function --- .chloggen/fix_ottl_limit.yaml | 16 ++++++++++++++++ pkg/ottl/ottlfuncs/func_limit.go | 2 +- .../internal/logs/processor_test.go | 6 ++++++ .../internal/metrics/processor_test.go | 7 +++++++ .../internal/traces/processor_test.go | 6 ++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 .chloggen/fix_ottl_limit.yaml diff --git a/.chloggen/fix_ottl_limit.yaml b/.chloggen/fix_ottl_limit.yaml new file mode 100755 index 000000000000..9690d02c72fb --- /dev/null +++ b/.chloggen/fix_ottl_limit.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/ottl + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix the factory name for the limit function + +# One or more tracking issues related to the change +issues: [21920] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/pkg/ottl/ottlfuncs/func_limit.go b/pkg/ottl/ottlfuncs/func_limit.go index 541ffce9c4e3..978a45341b9c 100644 --- a/pkg/ottl/ottlfuncs/func_limit.go +++ b/pkg/ottl/ottlfuncs/func_limit.go @@ -30,7 +30,7 @@ type LimitArguments[K any] struct { } func NewLimitFactory[K any]() ottl.Factory[K] { - return ottl.NewFactory("Limit", &LimitArguments[K]{}, createLimitFunction[K]) + return ottl.NewFactory("limit", &LimitArguments[K]{}, createLimitFunction[K]) } func createLimitFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) (ottl.ExprFunc[K], error) { diff --git a/processor/transformprocessor/internal/logs/processor_test.go b/processor/transformprocessor/internal/logs/processor_test.go index bc618ece008e..653a14df9b44 100644 --- a/processor/transformprocessor/internal/logs/processor_test.go +++ b/processor/transformprocessor/internal/logs/processor_test.go @@ -328,6 +328,12 @@ func Test_ProcessLogs_LogContext(t *testing.T) { td.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Attributes().PutStr("json_test", "pass") }, }, + { + statement: `limit(attributes, 0, []) where body == "operationA"`, + want: func(td plog.Logs) { + td.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Attributes().RemoveIf(func(s string, v pcommon.Value) bool { return true }) + }, + }, } for _, tt := range tests { diff --git a/processor/transformprocessor/internal/metrics/processor_test.go b/processor/transformprocessor/internal/metrics/processor_test.go index 3c04ff616719..48875c4f2770 100644 --- a/processor/transformprocessor/internal/metrics/processor_test.go +++ b/processor/transformprocessor/internal/metrics/processor_test.go @@ -505,6 +505,13 @@ func Test_ProcessMetrics_DataPointContext(t *testing.T) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().PutStr("json_test", "pass") }, }, + { + statements: []string{`limit(attributes, 0, []) where metric.name == "operationA"`}, + want: func(td pmetric.Metrics) { + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().RemoveIf(func(s string, v pcommon.Value) bool { return true }) + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().RemoveIf(func(s string, v pcommon.Value) bool { return true }) + }, + }, } for _, tt := range tests { diff --git a/processor/transformprocessor/internal/traces/processor_test.go b/processor/transformprocessor/internal/traces/processor_test.go index 370aba41b05c..aaa8b2105733 100644 --- a/processor/transformprocessor/internal/traces/processor_test.go +++ b/processor/transformprocessor/internal/traces/processor_test.go @@ -373,6 +373,12 @@ func Test_ProcessTraces_TraceContext(t *testing.T) { td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().PutStr("json_test", "pass") }, }, + { + statement: `limit(attributes, 0, []) where name == "operationA"`, + want: func(td ptrace.Traces) { + td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Attributes().RemoveIf(func(s string, v pcommon.Value) bool { return true }) + }, + }, } for _, tt := range tests {