From 172a11f9ccec76b0b7e23dd3b4b00dd33d755c43 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Tue, 27 Feb 2024 20:01:05 +0530 Subject: [PATCH 01/30] [feat]: added breaking changes to newTransformContext func of log.go, for making schemaURL accessible --- connector/countconnector/connector.go | 2 +- pkg/ottl/contexts/ottllog/log.go | 32 ++++++++++++++++++- .../attributesprocessor/attributes_log.go | 2 +- processor/filterprocessor/logs.go | 2 +- processor/routingprocessor/logs.go | 2 ++ .../internal/common/logs.go | 2 +- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/connector/countconnector/connector.go b/connector/countconnector/connector.go index 2cf5280fececc..b20fba679aea9 100644 --- a/connector/countconnector/connector.go +++ b/connector/countconnector/connector.go @@ -176,7 +176,7 @@ func (c *count) ConsumeLogs(ctx context.Context, ld plog.Logs) error { for k := 0; k < scopeLogs.LogRecords().Len(); k++ { logRecord := scopeLogs.LogRecords().At(k) - lCtx := ottllog.NewTransformContext(logRecord, scopeLogs.Scope(), resourceLog.Resource()) + lCtx := ottllog.NewTransformContext(logRecord, scopeLogs.Scope(), resourceLog.Resource(), scopeLogs, resourceLog) multiError = errors.Join(multiError, counter.update(ctx, logRecord.Attributes(), lCtx)) } } diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go index 30a7fab352bc4..2ba2ea583bd6b 100644 --- a/pkg/ottl/contexts/ottllog/log.go +++ b/pkg/ottl/contexts/ottllog/log.go @@ -26,16 +26,20 @@ type TransformContext struct { instrumentationScope pcommon.InstrumentationScope resource pcommon.Resource cache pcommon.Map + scopeLogs plog.ScopeLogs + resourceLogs plog.ResourceLogs } type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(logRecord plog.LogRecord, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource) TransformContext { +func NewTransformContext(logRecord plog.LogRecord, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeLogs plog.ScopeLogs, resourceLogs plog.ResourceLogs) TransformContext { return TransformContext{ logRecord: logRecord, instrumentationScope: instrumentationScope, resource: resource, cache: pcommon.NewMap(), + scopeLogs: scopeLogs, + resourceLogs: resourceLogs, } } @@ -55,6 +59,14 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } +func (tCtx TransformContext) getScopeLogs() plog.ScopeLogs { + return tCtx.scopeLogs +} + +func (tCtx TransformContext) getResourceLogs() plog.ResourceLogs { + return tCtx.resourceLogs +} + func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( @@ -208,7 +220,10 @@ func (pep *pathExpressionParser) parsePath(path ottl.Path[TransformContext]) (ot } else { return accessSpanID(), nil } + case "schemaURL": + return accessSchemaURL(), nil } + return nil, fmt.Errorf("invalid path expression %v", path) } @@ -491,3 +506,18 @@ func accessStringSpanID() ottl.StandardGetSetter[TransformContext] { }, } } + +func accessSchemaURL() ottl.StandardGetSetter[TransformContext] { + return ottl.StandardGetSetter[TransformContext]{ + Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { + return tCtx.getScopeLogs().SchemaUrl(), nil + }, + Setter: func(ctx context.Context, tCtx TransformContext, val any) error { + if schemaURL, ok := val.(string); ok { + tCtx.getScopeLogs().SetSchemaUrl(schemaURL) + tCtx.getResourceLogs().SetSchemaUrl(schemaURL) + } + return nil + }, + } +} diff --git a/processor/attributesprocessor/attributes_log.go b/processor/attributesprocessor/attributes_log.go index 7b7e9659d93c4..310f64f7e1963 100644 --- a/processor/attributesprocessor/attributes_log.go +++ b/processor/attributesprocessor/attributes_log.go @@ -44,7 +44,7 @@ func (a *logAttributesProcessor) processLogs(ctx context.Context, ld plog.Logs) for k := 0; k < logs.Len(); k++ { lr := logs.At(k) if a.skipExpr != nil { - skip, err := a.skipExpr.Eval(ctx, ottllog.NewTransformContext(lr, library, resource)) + skip, err := a.skipExpr.Eval(ctx, ottllog.NewTransformContext(lr, library, resource, ils, rs)) if err != nil { return ld, err } diff --git a/processor/filterprocessor/logs.go b/processor/filterprocessor/logs.go index 421eea9c8b6e6..15d498ef763e8 100644 --- a/processor/filterprocessor/logs.go +++ b/processor/filterprocessor/logs.go @@ -78,7 +78,7 @@ func (flp *filterLogProcessor) processLogs(ctx context.Context, ld plog.Logs) (p scope := sl.Scope() lrs := sl.LogRecords() lrs.RemoveIf(func(lr plog.LogRecord) bool { - skip, err := flp.skipExpr.Eval(ctx, ottllog.NewTransformContext(lr, scope, resource)) + skip, err := flp.skipExpr.Eval(ctx, ottllog.NewTransformContext(lr, scope, resource, sl, rl)) if err != nil { errors = multierr.Append(errors, err) return false diff --git a/processor/routingprocessor/logs.go b/processor/routingprocessor/logs.go index d300f0e2b82ec..d6f0a0b260920 100644 --- a/processor/routingprocessor/logs.go +++ b/processor/routingprocessor/logs.go @@ -108,6 +108,8 @@ func (p *logProcessor) route(ctx context.Context, l plog.Logs) error { plog.NewLogRecord(), pcommon.NewInstrumentationScope(), rlogs.Resource(), + plog.NewScopeLogs(), + rlogs, ) matchCount := len(p.router.routes) diff --git a/processor/transformprocessor/internal/common/logs.go b/processor/transformprocessor/internal/common/logs.go index 83f2e81e9bce1..b8e2577926f53 100644 --- a/processor/transformprocessor/internal/common/logs.go +++ b/processor/transformprocessor/internal/common/logs.go @@ -35,7 +35,7 @@ func (l logStatements) ConsumeLogs(ctx context.Context, ld plog.Logs) error { slogs := rlogs.ScopeLogs().At(j) logs := slogs.LogRecords() for k := 0; k < logs.Len(); k++ { - tCtx := ottllog.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource()) + tCtx := ottllog.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource(), slogs, rlogs) err := l.Execute(ctx, tCtx) if err != nil { return err From 8b70eeffa33c77215c38647a7e09e8b04831c4b6 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Thu, 29 Feb 2024 18:33:59 +0530 Subject: [PATCH 02/30] [fix]: Added separate functions to access schema_url using Scope/ResourceLog --- pkg/ottl/contexts/ottllog/log.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go index 2ba2ea583bd6b..df490215e8413 100644 --- a/pkg/ottl/contexts/ottllog/log.go +++ b/pkg/ottl/contexts/ottllog/log.go @@ -220,8 +220,16 @@ func (pep *pathExpressionParser) parsePath(path ottl.Path[TransformContext]) (ot } else { return accessSpanID(), nil } - case "schemaURL": - return accessSchemaURL(), nil + case "schema_url": + if path.Name() == "resource" && path.Next() != nil { + if path.Next().Name() == "schema_url" { + return accessResourceSchemaURL(), nil + } + } else if path.Name() == "scope" && path.Next() != nil { + if path.Next().Name() == "schema_url" { + return accessScopeSchemaURL(), nil + } + } } return nil, fmt.Errorf("invalid path expression %v", path) @@ -507,7 +515,21 @@ func accessStringSpanID() ottl.StandardGetSetter[TransformContext] { } } -func accessSchemaURL() ottl.StandardGetSetter[TransformContext] { +func accessResourceSchemaURL() ottl.StandardGetSetter[TransformContext] { + return ottl.StandardGetSetter[TransformContext]{ + Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { + return tCtx.getResourceLogs().SchemaUrl(), nil + }, + Setter: func(ctx context.Context, tCtx TransformContext, val any) error { + if schemaURL, ok := val.(string); ok { + tCtx.getResourceLogs().SetSchemaUrl(schemaURL) + } + return nil + }, + } +} + +func accessScopeSchemaURL() ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { return tCtx.getScopeLogs().SchemaUrl(), nil @@ -515,7 +537,6 @@ func accessSchemaURL() ottl.StandardGetSetter[TransformContext] { Setter: func(ctx context.Context, tCtx TransformContext, val any) error { if schemaURL, ok := val.(string); ok { tCtx.getScopeLogs().SetSchemaUrl(schemaURL) - tCtx.getResourceLogs().SetSchemaUrl(schemaURL) } return nil }, From ff353a78a067d6e47a5243cf4da6a0aabf3d74d3 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Thu, 7 Mar 2024 16:31:38 +0530 Subject: [PATCH 03/30] [feat]: Updated Implementation using SchemaURLItem Interface for ottllog package in contexts --- pkg/ottl/contexts/internal/schema.go | 6 ++++++ pkg/ottl/contexts/internal/scope.go | 16 ++++++++++++++++ pkg/ottl/contexts/internal/scope_test.go | 11 ++++++++++- pkg/ottl/contexts/ottllog/log.go | 22 ++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 pkg/ottl/contexts/internal/schema.go diff --git a/pkg/ottl/contexts/internal/schema.go b/pkg/ottl/contexts/internal/schema.go new file mode 100644 index 0000000000000..056ab042c04de --- /dev/null +++ b/pkg/ottl/contexts/internal/schema.go @@ -0,0 +1,6 @@ +package internal + +type SchemaURLItem interface { + SchemaURL() string + SetSchemaURL(v string) +} diff --git a/pkg/ottl/contexts/internal/scope.go b/pkg/ottl/contexts/internal/scope.go index d7e462cd1aa52..be167d547a47a 100644 --- a/pkg/ottl/contexts/internal/scope.go +++ b/pkg/ottl/contexts/internal/scope.go @@ -14,6 +14,8 @@ import ( type InstrumentationScopeContext interface { GetInstrumentationScope() pcommon.InstrumentationScope + GetScopeSchemaURLItem() SchemaURLItem + SetScopeSchemaURLItem(s SchemaURLItem) } func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { @@ -118,3 +120,17 @@ func accessInstrumentationScopeDroppedAttributesCount[K InstrumentationScopeCont }, } } + +func accessInstrumentationScopeSchemaURLItem[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] { + return ottl.StandardGetSetter[K]{ + Getter: func(ctx context.Context, tCtx K) (any, error) { + return tCtx.GetScopeSchemaURLItem(), nil + }, + Setter: func(ctx context.Context, tCtx K, val any) error { + if schemaURLItem, ok := val.(SchemaURLItem); ok { + tCtx.SetScopeSchemaURLItem(schemaURLItem) + } + return nil + }, + } +} diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index 997ac6096048e..600a072adbbde 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -395,13 +395,22 @@ func createInstrumentationScope() pcommon.InstrumentationScope { } type instrumentationScopeContext struct { - is pcommon.InstrumentationScope + is pcommon.InstrumentationScope + schemaURLItem SchemaURLItem } func (r *instrumentationScopeContext) GetInstrumentationScope() pcommon.InstrumentationScope { return r.is } +func (r *instrumentationScopeContext) GetScopeSchemaURLItem() SchemaURLItem { + return r.schemaURLItem +} + +func (r *instrumentationScopeContext) SetScopeSchemaURLItem(schema SchemaURLItem) { + r.schemaURLItem = schema +} + func newInstrumentationScopeContext(is pcommon.InstrumentationScope) *instrumentationScopeContext { return &instrumentationScopeContext{is: is} } diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go index df490215e8413..db9f9868b43f4 100644 --- a/pkg/ottl/contexts/ottllog/log.go +++ b/pkg/ottl/contexts/ottllog/log.go @@ -21,6 +21,18 @@ import ( var _ internal.ResourceContext = TransformContext{} var _ internal.InstrumentationScopeContext = TransformContext{} +type LogScopeSchemaURLItem struct { + scopeLogs plog.ScopeLogs +} + +func (schema LogScopeSchemaURLItem) SchemaURL() string { + return schema.SchemaURL() +} + +func (schema LogScopeSchemaURLItem) SetSchemaURL(v string) { + schema.SetSchemaURL(v) +} + type TransformContext struct { logRecord plog.LogRecord instrumentationScope pcommon.InstrumentationScope @@ -28,6 +40,7 @@ type TransformContext struct { cache pcommon.Map scopeLogs plog.ScopeLogs resourceLogs plog.ResourceLogs + logSchemaURLItem internal.SchemaURLItem } type Option func(*ottl.Parser[TransformContext]) @@ -40,6 +53,7 @@ func NewTransformContext(logRecord plog.LogRecord, instrumentationScope pcommon. cache: pcommon.NewMap(), scopeLogs: scopeLogs, resourceLogs: resourceLogs, + logSchemaURLItem: LogScopeSchemaURLItem{scopeLogs: scopeLogs}, } } @@ -67,6 +81,14 @@ func (tCtx TransformContext) getResourceLogs() plog.ResourceLogs { return tCtx.resourceLogs } +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { + return tCtx.logSchemaURLItem +} + +func (tCtx TransformContext) SetScopeSchemaURLItem(schema internal.SchemaURLItem) { + tCtx.logSchemaURLItem = schema +} + func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( From 02457c7d7109932c166000c5e73bd21252445181 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Tue, 19 Mar 2024 23:13:10 +0530 Subject: [PATCH 04/30] [FIX]: Fixed SchemaURLItem interface to match the function call in ScopeLogs and ResourceLogs --- internal/filter/filterlog/filterlog_test.go | 12 ++-- pkg/ottl/contexts/internal/resource.go | 15 +++++ pkg/ottl/contexts/internal/schema.go | 4 +- pkg/ottl/contexts/internal/scope.go | 9 +-- pkg/ottl/contexts/ottllog/log.go | 65 +-------------------- pkg/ottl/contexts/ottllog/log_test.go | 8 +-- 6 files changed, 34 insertions(+), 79 deletions(-) diff --git a/internal/filter/filterlog/filterlog_test.go b/internal/filter/filterlog/filterlog_test.go index 7e315e49450af..b0a07f16fab14 100644 --- a/internal/filter/filterlog/filterlog_test.go +++ b/internal/filter/filterlog/filterlog_test.go @@ -151,11 +151,11 @@ func TestLogRecord_Matching_False(t *testing.T) { assert.NoError(t, err) require.NotNil(t, expr) - val, err := expr.Eval(context.Background(), ottllog.NewTransformContext(lr, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + val, err := expr.Eval(context.Background(), ottllog.NewTransformContext(lr, pcommon.NewInstrumentationScope(), pcommon.NewResource(), plog.NewScopeLogs(), plog.NewResourceLogs())) require.NoError(t, err) assert.False(t, val) - val, err = expr.Eval(context.Background(), ottllog.NewTransformContext(lrm, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + val, err = expr.Eval(context.Background(), ottllog.NewTransformContext(lrm, pcommon.NewInstrumentationScope(), pcommon.NewResource(), plog.NewScopeLogs(), plog.NewResourceLogs())) require.NoError(t, err) assert.False(t, val) }) @@ -228,12 +228,12 @@ func TestLogRecord_Matching_True(t *testing.T) { require.NotNil(t, expr) assert.NotNil(t, lr) - val, err := expr.Eval(context.Background(), ottllog.NewTransformContext(lr, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + val, err := expr.Eval(context.Background(), ottllog.NewTransformContext(lr, pcommon.NewInstrumentationScope(), pcommon.NewResource(), plog.NewScopeLogs(), plog.NewResourceLogs())) require.NoError(t, err) assert.True(t, val) assert.NotNil(t, lrm) - val, err = expr.Eval(context.Background(), ottllog.NewTransformContext(lrm, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + val, err = expr.Eval(context.Background(), ottllog.NewTransformContext(lrm, pcommon.NewInstrumentationScope(), pcommon.NewResource(), plog.NewScopeLogs(), plog.NewResourceLogs())) require.NoError(t, err) assert.True(t, val) }) @@ -1304,7 +1304,7 @@ func Test_NewSkipExpr_With_Bridge(t *testing.T) { scope := pcommon.NewInstrumentationScope() - tCtx := ottllog.NewTransformContext(log, scope, resource) + tCtx := ottllog.NewTransformContext(log, scope, resource, plog.NewScopeLogs(), plog.NewResourceLogs()) boolExpr, err := NewSkipExpr(tt.condition) require.NoError(t, err) @@ -1378,7 +1378,7 @@ func BenchmarkFilterlog_NewSkipExpr(b *testing.B) { scope := pcommon.NewInstrumentationScope() - tCtx := ottllog.NewTransformContext(log, scope, resource) + tCtx := ottllog.NewTransformContext(log, scope, resource, plog.NewScopeLogs(), plog.NewResourceLogs()) b.Run(tt.name, func(b *testing.B) { for i := 0; i < b.N; i++ { diff --git a/pkg/ottl/contexts/internal/resource.go b/pkg/ottl/contexts/internal/resource.go index f7d5a3135ed62..e9adda3b66144 100644 --- a/pkg/ottl/contexts/internal/resource.go +++ b/pkg/ottl/contexts/internal/resource.go @@ -14,6 +14,7 @@ import ( type ResourceContext interface { GetResource() pcommon.Resource + GetResourceSchemaURLItem() SchemaURLItem } func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { @@ -85,3 +86,17 @@ func accessResourceDroppedAttributesCount[K ResourceContext]() ottl.StandardGetS }, } } + +func accessResourceSchemaURLItem[K ResourceContext]() ottl.StandardGetSetter[K] { + return ottl.StandardGetSetter[K]{ + Getter: func(ctx context.Context, tCtx K) (any, error) { + return tCtx.GetResourceSchemaURLItem().SchemaUrl(), nil + }, + Setter: func(ctx context.Context, tCtx K, val any) error { + if schemaURL, ok := val.(string); ok { + tCtx.GetResourceSchemaURLItem().SetSchemaUrl(schemaURL) + } + return nil + }, + } +} diff --git a/pkg/ottl/contexts/internal/schema.go b/pkg/ottl/contexts/internal/schema.go index 056ab042c04de..d505cd6ab3925 100644 --- a/pkg/ottl/contexts/internal/schema.go +++ b/pkg/ottl/contexts/internal/schema.go @@ -1,6 +1,6 @@ package internal type SchemaURLItem interface { - SchemaURL() string - SetSchemaURL(v string) + SchemaUrl() string + SetSchemaUrl(v string) } diff --git a/pkg/ottl/contexts/internal/scope.go b/pkg/ottl/contexts/internal/scope.go index be167d547a47a..7114f437ab5b2 100644 --- a/pkg/ottl/contexts/internal/scope.go +++ b/pkg/ottl/contexts/internal/scope.go @@ -15,7 +15,6 @@ import ( type InstrumentationScopeContext interface { GetInstrumentationScope() pcommon.InstrumentationScope GetScopeSchemaURLItem() SchemaURLItem - SetScopeSchemaURLItem(s SchemaURLItem) } func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { @@ -35,6 +34,8 @@ func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl. return accessInstrumentationScopeAttributesKey[K](mapKeys), nil case "dropped_attributes_count": return accessInstrumentationScopeDroppedAttributesCount[K](), nil + case "schema_url": + return accessInstrumentationScopeSchemaURLItem[K](), nil default: return nil, fmt.Errorf("invalid scope path expression %v", path) } @@ -124,11 +125,11 @@ func accessInstrumentationScopeDroppedAttributesCount[K InstrumentationScopeCont func accessInstrumentationScopeSchemaURLItem[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ Getter: func(ctx context.Context, tCtx K) (any, error) { - return tCtx.GetScopeSchemaURLItem(), nil + return tCtx.GetScopeSchemaURLItem().SchemaUrl(), nil }, Setter: func(ctx context.Context, tCtx K, val any) error { - if schemaURLItem, ok := val.(SchemaURLItem); ok { - tCtx.SetScopeSchemaURLItem(schemaURLItem) + if schemaURL, ok := val.(string); ok { + tCtx.GetScopeSchemaURLItem().SetSchemaUrl(schemaURL) } return nil }, diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go index db9f9868b43f4..830ac05ea595e 100644 --- a/pkg/ottl/contexts/ottllog/log.go +++ b/pkg/ottl/contexts/ottllog/log.go @@ -21,18 +21,6 @@ import ( var _ internal.ResourceContext = TransformContext{} var _ internal.InstrumentationScopeContext = TransformContext{} -type LogScopeSchemaURLItem struct { - scopeLogs plog.ScopeLogs -} - -func (schema LogScopeSchemaURLItem) SchemaURL() string { - return schema.SchemaURL() -} - -func (schema LogScopeSchemaURLItem) SetSchemaURL(v string) { - schema.SetSchemaURL(v) -} - type TransformContext struct { logRecord plog.LogRecord instrumentationScope pcommon.InstrumentationScope @@ -40,7 +28,6 @@ type TransformContext struct { cache pcommon.Map scopeLogs plog.ScopeLogs resourceLogs plog.ResourceLogs - logSchemaURLItem internal.SchemaURLItem } type Option func(*ottl.Parser[TransformContext]) @@ -53,7 +40,6 @@ func NewTransformContext(logRecord plog.LogRecord, instrumentationScope pcommon. cache: pcommon.NewMap(), scopeLogs: scopeLogs, resourceLogs: resourceLogs, - logSchemaURLItem: LogScopeSchemaURLItem{scopeLogs: scopeLogs}, } } @@ -73,22 +59,14 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) getScopeLogs() plog.ScopeLogs { +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { return tCtx.scopeLogs } -func (tCtx TransformContext) getResourceLogs() plog.ResourceLogs { +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { return tCtx.resourceLogs } -func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { - return tCtx.logSchemaURLItem -} - -func (tCtx TransformContext) SetScopeSchemaURLItem(schema internal.SchemaURLItem) { - tCtx.logSchemaURLItem = schema -} - func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( @@ -242,18 +220,7 @@ func (pep *pathExpressionParser) parsePath(path ottl.Path[TransformContext]) (ot } else { return accessSpanID(), nil } - case "schema_url": - if path.Name() == "resource" && path.Next() != nil { - if path.Next().Name() == "schema_url" { - return accessResourceSchemaURL(), nil - } - } else if path.Name() == "scope" && path.Next() != nil { - if path.Next().Name() == "schema_url" { - return accessScopeSchemaURL(), nil - } - } } - return nil, fmt.Errorf("invalid path expression %v", path) } @@ -536,31 +503,3 @@ func accessStringSpanID() ottl.StandardGetSetter[TransformContext] { }, } } - -func accessResourceSchemaURL() ottl.StandardGetSetter[TransformContext] { - return ottl.StandardGetSetter[TransformContext]{ - Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return tCtx.getResourceLogs().SchemaUrl(), nil - }, - Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - if schemaURL, ok := val.(string); ok { - tCtx.getResourceLogs().SetSchemaUrl(schemaURL) - } - return nil - }, - } -} - -func accessScopeSchemaURL() ottl.StandardGetSetter[TransformContext] { - return ottl.StandardGetSetter[TransformContext]{ - Getter: func(ctx context.Context, tCtx TransformContext) (any, error) { - return tCtx.getScopeLogs().SchemaUrl(), nil - }, - Setter: func(ctx context.Context, tCtx TransformContext, val any) error { - if schemaURL, ok := val.(string); ok { - tCtx.getScopeLogs().SetSchemaUrl(schemaURL) - } - return nil - }, - } -} diff --git a/pkg/ottl/contexts/ottllog/log_test.go b/pkg/ottl/contexts/ottllog/log_test.go index 2ae9d5dba6747..b8be9e050dcbd 100644 --- a/pkg/ottl/contexts/ottllog/log_test.go +++ b/pkg/ottl/contexts/ottllog/log_test.go @@ -628,12 +628,12 @@ func Test_newPathGetSetter(t *testing.T) { log, il, resource := createTelemetry(tt.bodyType) - tCtx := NewTransformContext(log, il, resource) + tCtx := NewTransformContext(log, il, resource, plog.NewScopeLogs(), plog.NewResourceLogs()) got, err := accessor.Get(context.Background(), tCtx) assert.NoError(t, err) assert.Equal(t, tt.orig, got) - tCtx = NewTransformContext(log, il, resource) + tCtx = NewTransformContext(log, il, resource, plog.NewScopeLogs(), plog.NewResourceLogs()) err = accessor.Set(context.Background(), tCtx, tt.newVal) assert.NoError(t, err) @@ -736,11 +736,11 @@ func Test_InvalidBodyIndexing(t *testing.T) { log, il, resource := createTelemetry("string") - tCtx := NewTransformContext(log, il, resource) + tCtx := NewTransformContext(log, il, resource, plog.NewScopeLogs(), plog.NewResourceLogs()) _, err = accessor.Get(context.Background(), tCtx) assert.Error(t, err) - tCtx = NewTransformContext(log, il, resource) + tCtx = NewTransformContext(log, il, resource, plog.NewScopeLogs(), plog.NewResourceLogs()) err = accessor.Set(context.Background(), tCtx, nil) assert.Error(t, err) } From 615c0cc975f6935a24139f40522c31f2fb543d21 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Tue, 19 Mar 2024 23:16:18 +0530 Subject: [PATCH 05/30] [FIX]: Fixed resource_test.go to match the ResourceContext interface --- pkg/ottl/contexts/internal/resource_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/ottl/contexts/internal/resource_test.go b/pkg/ottl/contexts/internal/resource_test.go index 12ad179044561..0a66649505aee 100644 --- a/pkg/ottl/contexts/internal/resource_test.go +++ b/pkg/ottl/contexts/internal/resource_test.go @@ -371,13 +371,18 @@ func createResource() pcommon.Resource { } type resourceContext struct { - resource pcommon.Resource + resource pcommon.Resource + schemaURLItem SchemaURLItem } func (r *resourceContext) GetResource() pcommon.Resource { return r.resource } +func (r *resourceContext) GetResourceSchemaURLItem() SchemaURLItem { + return r.schemaURLItem +} + func newResourceContext(resource pcommon.Resource) *resourceContext { return &resourceContext{resource: resource} } From af6427e582d49de74396c67ccd01c433295bb155 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Sun, 14 Apr 2024 01:26:11 +0530 Subject: [PATCH 06/30] [feat]: completed implementation for spans and traces --- .chloggen/schemaurl-ottl-context.yaml | 27 +++++++++++++++++++ connector/countconnector/connector.go | 16 +++++------ .../honeycombmarkerexporter/logs_exporter.go | 2 +- .../filter/filtermetric/filtermetric_test.go | 4 +-- internal/filter/filterottl/functions_test.go | 4 +-- internal/filter/filterspan/filterspan_test.go | 10 +++---- pkg/ottl/contexts/internal/resource.go | 2 ++ pkg/ottl/contexts/internal/scope_test.go | 25 ++++++++++++----- pkg/ottl/contexts/ottldatapoint/datapoint.go | 14 +++++++++- .../contexts/ottldatapoint/datapoint_test.go | 12 ++++----- pkg/ottl/contexts/ottlmetric/metrics.go | 14 +++++++++- pkg/ottl/contexts/ottlmetric/metrics_test.go | 2 +- pkg/ottl/contexts/ottlresource/resource.go | 5 ++++ pkg/ottl/contexts/ottlscope/scope.go | 10 +++++++ pkg/ottl/contexts/ottlspan/span.go | 14 +++++++++- pkg/ottl/contexts/ottlspan/span_test.go | 2 +- .../contexts/ottlspanevent/span_events.go | 14 +++++++++- .../ottlspanevent/span_events_test.go | 2 +- .../attributesprocessor/attributes_metric.go | 2 +- .../attributesprocessor/attributes_trace.go | 2 +- processor/filterprocessor/metrics.go | 10 +++---- processor/filterprocessor/traces.go | 4 +-- processor/routingprocessor/metrics.go | 2 ++ processor/routingprocessor/traces.go | 2 ++ processor/spanprocessor/span.go | 2 +- .../internal/sampling/ottl.go | 4 +-- .../internal/common/metrics.go | 10 +++---- .../internal/common/traces.go | 4 +-- ...unc_convert_gauge_to_sum_datapoint_test.go | 2 +- .../metrics/func_convert_gauge_to_sum_test.go | 2 +- ...unc_convert_sum_to_gauge_datapoint_test.go | 2 +- .../metrics/func_convert_sum_to_gauge_test.go | 2 +- ...c_convert_summary_count_val_to_sum_test.go | 2 +- ...unc_convert_summary_sum_val_to_sum_test.go | 2 +- .../internal/metrics/func_copy_metric_test.go | 2 +- .../metrics/func_extract_count_metric_test.go | 2 +- .../metrics/func_extract_sum_metric_test.go | 2 +- 37 files changed, 174 insertions(+), 65 deletions(-) create mode 100644 .chloggen/schemaurl-ottl-context.yaml diff --git a/.chloggen/schemaurl-ottl-context.yaml b/.chloggen/schemaurl-ottl-context.yaml new file mode 100644 index 0000000000000..0b2707a944f2e --- /dev/null +++ b/.chloggen/schemaurl-ottl-context.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/connector/countconnector/connector.go b/connector/countconnector/connector.go index b20fba679aea9..700002ba9e279 100644 --- a/connector/countconnector/connector.go +++ b/connector/countconnector/connector.go @@ -56,12 +56,12 @@ func (c *count) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { for k := 0; k < scopeSpan.Spans().Len(); k++ { span := scopeSpan.Spans().At(k) - sCtx := ottlspan.NewTransformContext(span, scopeSpan.Scope(), resourceSpan.Resource()) + sCtx := ottlspan.NewTransformContext(span, scopeSpan.Scope(), resourceSpan.Resource(), scopeSpan, resourceSpan) multiError = errors.Join(multiError, spansCounter.update(ctx, span.Attributes(), sCtx)) for l := 0; l < span.Events().Len(); l++ { event := span.Events().At(l) - eCtx := ottlspanevent.NewTransformContext(event, span, scopeSpan.Scope(), resourceSpan.Resource()) + eCtx := ottlspanevent.NewTransformContext(event, span, scopeSpan.Scope(), resourceSpan.Resource(), scopeSpan, resourceSpan) multiError = errors.Join(multiError, spanEventsCounter.update(ctx, event.Attributes(), eCtx)) } } @@ -101,7 +101,7 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { for k := 0; k < scopeMetrics.Metrics().Len(); k++ { metric := scopeMetrics.Metrics().At(k) - mCtx := ottlmetric.NewTransformContext(metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) + mCtx := ottlmetric.NewTransformContext(metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric) multiError = errors.Join(multiError, metricsCounter.update(ctx, pcommon.NewMap(), mCtx)) //exhaustive:enforce @@ -109,31 +109,31 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { case pmetric.MetricTypeGauge: dps := metric.Gauge().DataPoints() for i := 0; i < dps.Len(); i++ { - dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) + dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric) multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeSum: dps := metric.Sum().DataPoints() for i := 0; i < dps.Len(); i++ { - dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) + dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric) multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeSummary: dps := metric.Summary().DataPoints() for i := 0; i < dps.Len(); i++ { - dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) + dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric) multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeHistogram: dps := metric.Histogram().DataPoints() for i := 0; i < dps.Len(); i++ { - dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) + dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric) multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeExponentialHistogram: dps := metric.ExponentialHistogram().DataPoints() for i := 0; i < dps.Len(); i++ { - dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) + dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource(), scopeMetrics, resourceMetric) multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeEmpty: diff --git a/exporter/honeycombmarkerexporter/logs_exporter.go b/exporter/honeycombmarkerexporter/logs_exporter.go index 297eddbec852f..93b6d826dc0e6 100644 --- a/exporter/honeycombmarkerexporter/logs_exporter.go +++ b/exporter/honeycombmarkerexporter/logs_exporter.go @@ -83,7 +83,7 @@ func (e *honeycombLogsExporter) exportMarkers(ctx context.Context, ld plog.Logs) logs := slogs.LogRecords() for k := 0; k < logs.Len(); k++ { logRecord := logs.At(k) - tCtx := ottllog.NewTransformContext(logRecord, slogs.Scope(), rlogs.Resource()) + tCtx := ottllog.NewTransformContext(logRecord, slogs.Scope(), rlogs.Resource(), slogs, rlogs) for _, m := range e.markers { match, err := m.logBoolExpr.Eval(ctx, tCtx) if err != nil { diff --git a/internal/filter/filtermetric/filtermetric_test.go b/internal/filter/filtermetric/filtermetric_test.go index ea63fa7eb7f7b..c5935b97d6510 100644 --- a/internal/filter/filtermetric/filtermetric_test.go +++ b/internal/filter/filtermetric/filtermetric_test.go @@ -83,7 +83,7 @@ func TestMatcherMatches(t *testing.T) { assert.NotNil(t, matcher) assert.NoError(t, err) - matches, err := matcher.Eval(context.Background(), ottlmetric.NewTransformContext(test.metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource())) + matches, err := matcher.Eval(context.Background(), ottlmetric.NewTransformContext(test.metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) assert.NoError(t, err) assert.Equal(t, test.shouldMatch, matches) }) @@ -188,7 +188,7 @@ func Test_NewSkipExpr_With_Bridge(t *testing.T) { scope := pcommon.NewInstrumentationScope() - tCtx := ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), scope, resource) + tCtx := ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), scope, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) boolExpr, err := NewSkipExpr(tt.include, tt.exclude) require.NoError(t, err) diff --git a/internal/filter/filterottl/functions_test.go b/internal/filter/filterottl/functions_test.go index 2e1755361d27f..abb327073cea0 100644 --- a/internal/filter/filterottl/functions_test.go +++ b/internal/filter/filterottl/functions_test.go @@ -126,7 +126,7 @@ func Test_HasAttrKeyOnDatapoint(t *testing.T) { t.Run(tt.name, func(t *testing.T) { exprFunc, err := hasAttributeKeyOnDatapoint(tt.key) assert.NoError(t, err) - result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource())) + result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) assert.NoError(t, err) assert.Equal(t, tt.expected, result) }) @@ -351,7 +351,7 @@ func Test_HasAttrOnDatapoint(t *testing.T) { t.Run(tt.name, func(t *testing.T) { exprFunc, err := hasAttributeOnDatapoint(tt.key, tt.expectedVal) assert.NoError(t, err) - result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource())) + result, err := exprFunc(context.Background(), ottlmetric.NewTransformContext(tt.input(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) assert.NoError(t, err) assert.Equal(t, tt.expected, result) }) diff --git a/internal/filter/filterspan/filterspan_test.go b/internal/filter/filterspan/filterspan_test.go index ff04a1d997c37..5a71facf3a17d 100644 --- a/internal/filter/filterspan/filterspan_test.go +++ b/internal/filter/filterspan/filterspan_test.go @@ -179,7 +179,7 @@ func TestSpan_Matching_False(t *testing.T) { require.NoError(t, err) assert.NotNil(t, expr) - val, err := expr.Eval(context.Background(), ottlspan.NewTransformContext(span, library, resource)) + val, err := expr.Eval(context.Background(), ottlspan.NewTransformContext(span, library, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans())) require.NoError(t, err) assert.False(t, val) }) @@ -197,7 +197,7 @@ func TestSpan_MissingServiceName(t *testing.T) { assert.NotNil(t, mp) emptySpan := ptrace.NewSpan() - val, err := mp.Eval(context.Background(), ottlspan.NewTransformContext(emptySpan, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + val, err := mp.Eval(context.Background(), ottlspan.NewTransformContext(emptySpan, pcommon.NewInstrumentationScope(), pcommon.NewResource(), ptrace.NewScopeSpans(), ptrace.NewResourceSpans())) require.NoError(t, err) assert.False(t, val) } @@ -288,7 +288,7 @@ func TestSpan_Matching_True(t *testing.T) { require.NoError(t, err) assert.NotNil(t, mp) - val, err := mp.Eval(context.Background(), ottlspan.NewTransformContext(span, library, resource)) + val, err := mp.Eval(context.Background(), ottlspan.NewTransformContext(span, library, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans())) require.NoError(t, err) assert.True(t, val) }) @@ -1211,7 +1211,7 @@ func Test_NewSkipExpr_With_Bridge(t *testing.T) { scope.SetName("scope") scope.SetVersion("0.1.0") - tCtx := ottlspan.NewTransformContext(span, scope, resource) + tCtx := ottlspan.NewTransformContext(span, scope, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans()) boolExpr, err := NewSkipExpr(tt.condition) require.NoError(t, err) @@ -1279,7 +1279,7 @@ func BenchmarkFilterspan_NewSkipExpr(b *testing.B) { scope := pcommon.NewInstrumentationScope() - tCtx := ottlspan.NewTransformContext(span, scope, resource) + tCtx := ottlspan.NewTransformContext(span, scope, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans()) b.Run(tt.name, func(b *testing.B) { for i := 0; i < b.N; i++ { diff --git a/pkg/ottl/contexts/internal/resource.go b/pkg/ottl/contexts/internal/resource.go index d1f9e3616fa87..53870a7841dd8 100644 --- a/pkg/ottl/contexts/internal/resource.go +++ b/pkg/ottl/contexts/internal/resource.go @@ -28,6 +28,8 @@ func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter return accessResourceAttributesKey[K](path.Keys()), nil case "dropped_attributes_count": return accessResourceDroppedAttributesCount[K](), nil + case "schema_url": + return accessResourceSchemaURLItem[K](), nil default: return nil, FormatDefaultErrorMessage(path.Name(), path.String(), "Resource", ResourceContextRef) } diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index 5ed5567dbe306..880ef1452450a 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/plog" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" @@ -17,6 +18,7 @@ import ( func TestScopePathGetSetter(t *testing.T) { refIS := createInstrumentationScope() + refISC := newInstrumentationScopeContext(refIS, s) newAttrs := pcommon.NewMap() newAttrs.PutStr("hello", "world") tests := []struct { @@ -57,6 +59,17 @@ func TestScopePathGetSetter(t *testing.T) { is.SetVersion("next") }, }, + { + name: "instrumentation_scope schema_url", + path: &TestPath[*instrumentationScopeContext]{ + N: "schema_url", + }, + orig: refISC.GetScopeSchemaURLItem(), + newVal: "new_schema_url", + modified: func(is pcommon.InstrumentationScope) { + refISC.GetScopeSchemaURLItem().SetSchemaUrl() + }, + }, { name: "attributes", path: &TestPath[*instrumentationScopeContext]{ @@ -394,6 +407,10 @@ func createInstrumentationScope() pcommon.InstrumentationScope { return is } +func createSchemaURLItem() SchemaURLItem { + return plog.NewScopeLogs() +} + type instrumentationScopeContext struct { is pcommon.InstrumentationScope schemaURLItem SchemaURLItem @@ -407,10 +424,6 @@ func (r *instrumentationScopeContext) GetScopeSchemaURLItem() SchemaURLItem { return r.schemaURLItem } -func (r *instrumentationScopeContext) SetScopeSchemaURLItem(schema SchemaURLItem) { - r.schemaURLItem = schema -} - -func newInstrumentationScopeContext(is pcommon.InstrumentationScope) *instrumentationScopeContext { - return &instrumentationScopeContext{is: is} +func newInstrumentationScopeContext(is pcommon.InstrumentationScope, schemaURLItem SchemaURLItem) *instrumentationScopeContext { + return &instrumentationScopeContext{is: is, schemaURLItem: schemaURLItem} } diff --git a/pkg/ottl/contexts/ottldatapoint/datapoint.go b/pkg/ottl/contexts/ottldatapoint/datapoint.go index 6d55fa91ad65c..9ca9216247e31 100644 --- a/pkg/ottl/contexts/ottldatapoint/datapoint.go +++ b/pkg/ottl/contexts/ottldatapoint/datapoint.go @@ -30,11 +30,13 @@ type TransformContext struct { instrumentationScope pcommon.InstrumentationScope resource pcommon.Resource cache pcommon.Map + scopeMetrics pmetric.ScopeMetrics + resourceMetrics pmetric.ResourceMetrics } type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(dataPoint any, metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource) TransformContext { +func NewTransformContext(dataPoint any, metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) TransformContext { return TransformContext{ dataPoint: dataPoint, metric: metric, @@ -42,6 +44,8 @@ func NewTransformContext(dataPoint any, metric pmetric.Metric, metrics pmetric.M instrumentationScope: instrumentationScope, resource: resource, cache: pcommon.NewMap(), + scopeMetrics: scopeMetrics, + resourceMetrics: resourceMetrics, } } @@ -69,6 +73,14 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { + return tCtx.scopeMetrics +} + +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { + return tCtx.resourceMetrics +} + func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( diff --git a/pkg/ottl/contexts/ottldatapoint/datapoint_test.go b/pkg/ottl/contexts/ottldatapoint/datapoint_test.go index d25d7746098d2..e8d837fddaa52 100644 --- a/pkg/ottl/contexts/ottldatapoint/datapoint_test.go +++ b/pkg/ottl/contexts/ottldatapoint/datapoint_test.go @@ -65,7 +65,7 @@ func Test_newPathGetSetter_Cache(t *testing.T) { numberDataPoint := createNumberDataPointTelemetry(tt.valueType) - ctx := NewTransformContext(numberDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := NewTransformContext(numberDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) got, err := accessor.Get(context.Background(), ctx) assert.NoError(t, err) @@ -483,7 +483,7 @@ func Test_newPathGetSetter_NumberDataPoint(t *testing.T) { numberDataPoint := createNumberDataPointTelemetry(tt.valueType) - ctx := NewTransformContext(numberDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := NewTransformContext(numberDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) got, err := accessor.Get(context.Background(), ctx) assert.NoError(t, err) @@ -918,7 +918,7 @@ func Test_newPathGetSetter_HistogramDataPoint(t *testing.T) { histogramDataPoint := createHistogramDataPointTelemetry() - ctx := NewTransformContext(histogramDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := NewTransformContext(histogramDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) got, err := accessor.Get(context.Background(), ctx) assert.NoError(t, err) @@ -1436,7 +1436,7 @@ func Test_newPathGetSetter_ExpoHistogramDataPoint(t *testing.T) { expoHistogramDataPoint := createExpoHistogramDataPointTelemetry() - ctx := NewTransformContext(expoHistogramDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := NewTransformContext(expoHistogramDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) got, err := accessor.Get(context.Background(), ctx) assert.NoError(t, err) @@ -1855,7 +1855,7 @@ func Test_newPathGetSetter_SummaryDataPoint(t *testing.T) { summaryDataPoint := createSummaryDataPointTelemetry() - ctx := NewTransformContext(summaryDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := NewTransformContext(summaryDataPoint, pmetric.NewMetric(), pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) got, err := accessor.Get(context.Background(), ctx) assert.NoError(t, err) @@ -2039,7 +2039,7 @@ func Test_newPathGetSetter_Metric(t *testing.T) { metric := createMetricTelemetry() - ctx := NewTransformContext(pmetric.NewNumberDataPoint(), metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := NewTransformContext(pmetric.NewNumberDataPoint(), metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) got, err := accessor.Get(context.Background(), ctx) assert.NoError(t, err) diff --git a/pkg/ottl/contexts/ottlmetric/metrics.go b/pkg/ottl/contexts/ottlmetric/metrics.go index 964210d46564b..ce5ff174ee69e 100644 --- a/pkg/ottl/contexts/ottlmetric/metrics.go +++ b/pkg/ottl/contexts/ottlmetric/metrics.go @@ -25,17 +25,21 @@ type TransformContext struct { instrumentationScope pcommon.InstrumentationScope resource pcommon.Resource cache pcommon.Map + scopeMetrics pmetric.ScopeMetrics + resourceMetrics pmetric.ResourceMetrics } type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource) TransformContext { +func NewTransformContext(metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) TransformContext { return TransformContext{ metric: metric, metrics: metrics, instrumentationScope: instrumentationScope, resource: resource, cache: pcommon.NewMap(), + scopeMetrics: scopeMetrics, + resourceMetrics: resourceMetrics, } } @@ -59,6 +63,14 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { + return tCtx.scopeMetrics +} + +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { + return tCtx.resourceMetrics +} + func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( diff --git a/pkg/ottl/contexts/ottlmetric/metrics_test.go b/pkg/ottl/contexts/ottlmetric/metrics_test.go index fb2bfb4b670ad..3ab79f61e2950 100644 --- a/pkg/ottl/contexts/ottlmetric/metrics_test.go +++ b/pkg/ottl/contexts/ottlmetric/metrics_test.go @@ -149,7 +149,7 @@ func Test_newPathGetSetter(t *testing.T) { metric := createMetricTelemetry() - ctx := NewTransformContext(metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := NewTransformContext(metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) got, err := accessor.Get(context.Background(), ctx) assert.NoError(t, err) diff --git a/pkg/ottl/contexts/ottlresource/resource.go b/pkg/ottl/contexts/ottlresource/resource.go index e37440d9dbc2b..fc1ad950a5f69 100644 --- a/pkg/ottl/contexts/ottlresource/resource.go +++ b/pkg/ottl/contexts/ottlresource/resource.go @@ -38,6 +38,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } +// [TODO]: Find appropriate way to access schemaURLItem using resource +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { + return nil +} + func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( diff --git a/pkg/ottl/contexts/ottlscope/scope.go b/pkg/ottl/contexts/ottlscope/scope.go index f7a9d92ee8d4a..2e13da5233036 100644 --- a/pkg/ottl/contexts/ottlscope/scope.go +++ b/pkg/ottl/contexts/ottlscope/scope.go @@ -45,6 +45,16 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } +// [TODO]: +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { + return nil +} + +// [TODO]: Methods needs to be implemented for resource +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { + return nil +} + func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( diff --git a/pkg/ottl/contexts/ottlspan/span.go b/pkg/ottl/contexts/ottlspan/span.go index a680fd68a96a1..a2e5685783518 100644 --- a/pkg/ottl/contexts/ottlspan/span.go +++ b/pkg/ottl/contexts/ottlspan/span.go @@ -23,16 +23,20 @@ type TransformContext struct { instrumentationScope pcommon.InstrumentationScope resource pcommon.Resource cache pcommon.Map + scopeSpans ptrace.ScopeSpans + resourceSpans ptrace.ResourceSpans } type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(span ptrace.Span, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource) TransformContext { +func NewTransformContext(span ptrace.Span, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeSpans ptrace.ScopeSpans, resourceSpans ptrace.ResourceSpans) TransformContext { return TransformContext{ span: span, instrumentationScope: instrumentationScope, resource: resource, cache: pcommon.NewMap(), + scopeSpans: scopeSpans, + resourceSpans: resourceSpans, } } @@ -52,6 +56,14 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { + return tCtx.resourceSpans +} + +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { + return tCtx.scopeSpans +} + func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( diff --git a/pkg/ottl/contexts/ottlspan/span_test.go b/pkg/ottl/contexts/ottlspan/span_test.go index c02ae40ae6139..041d64f80a360 100644 --- a/pkg/ottl/contexts/ottlspan/span_test.go +++ b/pkg/ottl/contexts/ottlspan/span_test.go @@ -699,7 +699,7 @@ func Test_newPathGetSetter(t *testing.T) { span, il, resource := createTelemetry() - tCtx := NewTransformContext(span, il, resource) + tCtx := NewTransformContext(span, il, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans()) got, err := accessor.Get(context.Background(), tCtx) assert.NoError(t, err) diff --git a/pkg/ottl/contexts/ottlspanevent/span_events.go b/pkg/ottl/contexts/ottlspanevent/span_events.go index baf2aadcb4754..1b7045d2c2dce 100644 --- a/pkg/ottl/contexts/ottlspanevent/span_events.go +++ b/pkg/ottl/contexts/ottlspanevent/span_events.go @@ -26,17 +26,21 @@ type TransformContext struct { instrumentationScope pcommon.InstrumentationScope resource pcommon.Resource cache pcommon.Map + scopeSpans ptrace.ScopeSpans + resouceSpans ptrace.ResourceSpans } type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(spanEvent ptrace.SpanEvent, span ptrace.Span, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource) TransformContext { +func NewTransformContext(spanEvent ptrace.SpanEvent, span ptrace.Span, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeSpans ptrace.ScopeSpans, resourceSpans ptrace.ResourceSpans) TransformContext { return TransformContext{ spanEvent: spanEvent, span: span, instrumentationScope: instrumentationScope, resource: resource, cache: pcommon.NewMap(), + scopeSpans: scopeSpans, + resouceSpans: resourceSpans, } } @@ -60,6 +64,14 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { + return tCtx.scopeSpans +} + +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { + return tCtx.resouceSpans +} + func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { pep := pathExpressionParser{telemetrySettings} p, err := ottl.NewParser[TransformContext]( diff --git a/pkg/ottl/contexts/ottlspanevent/span_events_test.go b/pkg/ottl/contexts/ottlspanevent/span_events_test.go index 0464b36e9aeee..57e87ced66361 100644 --- a/pkg/ottl/contexts/ottlspanevent/span_events_test.go +++ b/pkg/ottl/contexts/ottlspanevent/span_events_test.go @@ -449,7 +449,7 @@ func Test_newPathGetSetter(t *testing.T) { spanEvent, span, il, resource := createTelemetry() - tCtx := NewTransformContext(spanEvent, span, il, resource) + tCtx := NewTransformContext(spanEvent, span, il, resource, ptrace.NewScopeSpans(), ptrace.NewResourceSpans()) got, err := accessor.Get(context.Background(), tCtx) assert.NoError(t, err) diff --git a/processor/attributesprocessor/attributes_metric.go b/processor/attributesprocessor/attributes_metric.go index 72a4d9d03fcfa..b09de40d43407 100644 --- a/processor/attributesprocessor/attributes_metric.go +++ b/processor/attributesprocessor/attributes_metric.go @@ -44,7 +44,7 @@ func (a *metricAttributesProcessor) processMetrics(ctx context.Context, md pmetr for k := 0; k < metrics.Len(); k++ { m := metrics.At(k) if a.skipExpr != nil { - skip, err := a.skipExpr.Eval(ctx, ottlmetric.NewTransformContext(m, metrics, scope, resource)) + skip, err := a.skipExpr.Eval(ctx, ottlmetric.NewTransformContext(m, metrics, scope, resource, ils, rs)) if err != nil { return md, err } diff --git a/processor/attributesprocessor/attributes_trace.go b/processor/attributesprocessor/attributes_trace.go index 64aa73e524ba9..c3d1b6fd4fc17 100644 --- a/processor/attributesprocessor/attributes_trace.go +++ b/processor/attributesprocessor/attributes_trace.go @@ -44,7 +44,7 @@ func (a *spanAttributesProcessor) processTraces(ctx context.Context, td ptrace.T for k := 0; k < spans.Len(); k++ { span := spans.At(k) if a.skipExpr != nil { - skip, err := a.skipExpr.Eval(ctx, ottlspan.NewTransformContext(span, scope, resource)) + skip, err := a.skipExpr.Eval(ctx, ottlspan.NewTransformContext(span, scope, resource, ils, rs)) if err != nil { return td, err } diff --git a/processor/filterprocessor/metrics.go b/processor/filterprocessor/metrics.go index 10551d3dd117a..a1730447c23be 100644 --- a/processor/filterprocessor/metrics.go +++ b/processor/filterprocessor/metrics.go @@ -135,7 +135,7 @@ func (fmp *filterMetricProcessor) processMetrics(ctx context.Context, md pmetric scope := smetrics.Scope() smetrics.Metrics().RemoveIf(func(metric pmetric.Metric) bool { if fmp.skipMetricExpr != nil { - skip, err := fmp.skipMetricExpr.Eval(ctx, ottlmetric.NewTransformContext(metric, smetrics.Metrics(), scope, resource)) + skip, err := fmp.skipMetricExpr.Eval(ctx, ottlmetric.NewTransformContext(metric, smetrics.Metrics(), scope, resource, smetrics, rmetrics)) if err != nil { errors = multierr.Append(errors, err) } @@ -259,7 +259,7 @@ func newResExpr(mp *filterconfig.MetricMatchProperties) (expr.BoolExpr[ottlresou func (fmp *filterMetricProcessor) handleNumberDataPoints(ctx context.Context, dps pmetric.NumberDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { var errors error dps.RemoveIf(func(datapoint pmetric.NumberDataPoint) bool { - skip, err := fmp.skipDataPointExpr.Eval(ctx, ottldatapoint.NewTransformContext(datapoint, metric, metrics, is, resource)) + skip, err := fmp.skipDataPointExpr.Eval(ctx, ottldatapoint.NewTransformContext(datapoint, metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) if err != nil { errors = multierr.Append(errors, err) return false @@ -272,7 +272,7 @@ func (fmp *filterMetricProcessor) handleNumberDataPoints(ctx context.Context, dp func (fmp *filterMetricProcessor) handleHistogramDataPoints(ctx context.Context, dps pmetric.HistogramDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { var errors error dps.RemoveIf(func(datapoint pmetric.HistogramDataPoint) bool { - skip, err := fmp.skipDataPointExpr.Eval(ctx, ottldatapoint.NewTransformContext(datapoint, metric, metrics, is, resource)) + skip, err := fmp.skipDataPointExpr.Eval(ctx, ottldatapoint.NewTransformContext(datapoint, metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) if err != nil { errors = multierr.Append(errors, err) return false @@ -285,7 +285,7 @@ func (fmp *filterMetricProcessor) handleHistogramDataPoints(ctx context.Context, func (fmp *filterMetricProcessor) handleExponetialHistogramDataPoints(ctx context.Context, dps pmetric.ExponentialHistogramDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { var errors error dps.RemoveIf(func(datapoint pmetric.ExponentialHistogramDataPoint) bool { - skip, err := fmp.skipDataPointExpr.Eval(ctx, ottldatapoint.NewTransformContext(datapoint, metric, metrics, is, resource)) + skip, err := fmp.skipDataPointExpr.Eval(ctx, ottldatapoint.NewTransformContext(datapoint, metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) if err != nil { errors = multierr.Append(errors, err) return false @@ -298,7 +298,7 @@ func (fmp *filterMetricProcessor) handleExponetialHistogramDataPoints(ctx contex func (fmp *filterMetricProcessor) handleSummaryDataPoints(ctx context.Context, dps pmetric.SummaryDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { var errors error dps.RemoveIf(func(datapoint pmetric.SummaryDataPoint) bool { - skip, err := fmp.skipDataPointExpr.Eval(ctx, ottldatapoint.NewTransformContext(datapoint, metric, metrics, is, resource)) + skip, err := fmp.skipDataPointExpr.Eval(ctx, ottldatapoint.NewTransformContext(datapoint, metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) if err != nil { errors = multierr.Append(errors, err) return false diff --git a/processor/filterprocessor/traces.go b/processor/filterprocessor/traces.go index ff64e85470d11..230b432c01be6 100644 --- a/processor/filterprocessor/traces.go +++ b/processor/filterprocessor/traces.go @@ -93,7 +93,7 @@ func (fsp *filterSpanProcessor) processTraces(ctx context.Context, td ptrace.Tra scope := ss.Scope() ss.Spans().RemoveIf(func(span ptrace.Span) bool { if fsp.skipSpanExpr != nil { - skip, err := fsp.skipSpanExpr.Eval(ctx, ottlspan.NewTransformContext(span, scope, resource)) + skip, err := fsp.skipSpanExpr.Eval(ctx, ottlspan.NewTransformContext(span, scope, resource, ss, rs)) if err != nil { errors = multierr.Append(errors, err) return false @@ -104,7 +104,7 @@ func (fsp *filterSpanProcessor) processTraces(ctx context.Context, td ptrace.Tra } if fsp.skipSpanEventExpr != nil { span.Events().RemoveIf(func(spanEvent ptrace.SpanEvent) bool { - skip, err := fsp.skipSpanEventExpr.Eval(ctx, ottlspanevent.NewTransformContext(spanEvent, span, scope, resource)) + skip, err := fsp.skipSpanEventExpr.Eval(ctx, ottlspanevent.NewTransformContext(spanEvent, span, scope, resource, ss, rs)) if err != nil { errors = multierr.Append(errors, err) return false diff --git a/processor/routingprocessor/metrics.go b/processor/routingprocessor/metrics.go index ea8f4b5ecbe2b..f1df833e00bde 100644 --- a/processor/routingprocessor/metrics.go +++ b/processor/routingprocessor/metrics.go @@ -110,6 +110,8 @@ func (p *metricsProcessor) route(ctx context.Context, tm pmetric.Metrics) error pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), rmetrics.Resource(), + rmetrics.ScopeMetrics().At(i), + rmetrics, ) matchCount := len(p.router.routes) diff --git a/processor/routingprocessor/traces.go b/processor/routingprocessor/traces.go index 779ca4f4fe5ca..c8ec0aaf2bb87 100644 --- a/processor/routingprocessor/traces.go +++ b/processor/routingprocessor/traces.go @@ -109,6 +109,8 @@ func (p *tracesProcessor) route(ctx context.Context, t ptrace.Traces) error { ptrace.NewSpan(), pcommon.NewInstrumentationScope(), rspans.Resource(), + rspans.ScopeSpans().At(i), + rspans, ) matchCount := len(p.router.routes) diff --git a/processor/spanprocessor/span.go b/processor/spanprocessor/span.go index 20f8f2a043fac..32ac59bdbe0bd 100644 --- a/processor/spanprocessor/span.go +++ b/processor/spanprocessor/span.go @@ -79,7 +79,7 @@ func (sp *spanProcessor) processTraces(ctx context.Context, td ptrace.Traces) (p for k := 0; k < spans.Len(); k++ { span := spans.At(k) if sp.skipExpr != nil { - skip, err := sp.skipExpr.Eval(ctx, ottlspan.NewTransformContext(span, scope, resource)) + skip, err := sp.skipExpr.Eval(ctx, ottlspan.NewTransformContext(span, scope, resource, ils, rs)) if err != nil { return td, err } diff --git a/processor/tailsamplingprocessor/internal/sampling/ottl.go b/processor/tailsamplingprocessor/internal/sampling/ottl.go index cccf3e1ad590e..4e50358b002e3 100644 --- a/processor/tailsamplingprocessor/internal/sampling/ottl.go +++ b/processor/tailsamplingprocessor/internal/sampling/ottl.go @@ -88,7 +88,7 @@ func (ocf *ottlConditionFilter) Evaluate(ctx context.Context, traceID pcommon.Tr // Span evaluation if ocf.sampleSpanExpr != nil { - ok, err = ocf.sampleSpanExpr.Eval(ctx, ottlspan.NewTransformContext(span, scope, resource)) + ok, err = ocf.sampleSpanExpr.Eval(ctx, ottlspan.NewTransformContext(span, scope, resource, ss, rs)) if err != nil { return Error, err } @@ -101,7 +101,7 @@ func (ocf *ottlConditionFilter) Evaluate(ctx context.Context, traceID pcommon.Tr if ocf.sampleSpanEventExpr != nil { spanEvents := span.Events() for l := 0; l < spanEvents.Len(); l++ { - ok, err = ocf.sampleSpanEventExpr.Eval(ctx, ottlspanevent.NewTransformContext(spanEvents.At(l), span, scope, resource)) + ok, err = ocf.sampleSpanEventExpr.Eval(ctx, ottlspanevent.NewTransformContext(spanEvents.At(l), span, scope, resource, ss, rs)) if err != nil { return Error, err } diff --git a/processor/transformprocessor/internal/common/metrics.go b/processor/transformprocessor/internal/common/metrics.go index 602245ac00153..64158eef2a12d 100644 --- a/processor/transformprocessor/internal/common/metrics.go +++ b/processor/transformprocessor/internal/common/metrics.go @@ -37,7 +37,7 @@ func (m metricStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metrics smetrics := rmetrics.ScopeMetrics().At(j) metrics := smetrics.Metrics() for k := 0; k < metrics.Len(); k++ { - tCtx := ottlmetric.NewTransformContext(metrics.At(k), smetrics.Metrics(), smetrics.Scope(), rmetrics.Resource()) + tCtx := ottlmetric.NewTransformContext(metrics.At(k), smetrics.Metrics(), smetrics.Scope(), rmetrics.Resource(), smetrics, rmetrics) err := m.Execute(ctx, tCtx) if err != nil { return err @@ -93,7 +93,7 @@ func (d dataPointStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metr func (d dataPointStatements) handleNumberDataPoints(ctx context.Context, dps pmetric.NumberDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { for i := 0; i < dps.Len(); i++ { - tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource) + tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) err := d.Execute(ctx, tCtx) if err != nil { return err @@ -104,7 +104,7 @@ func (d dataPointStatements) handleNumberDataPoints(ctx context.Context, dps pme func (d dataPointStatements) handleHistogramDataPoints(ctx context.Context, dps pmetric.HistogramDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { for i := 0; i < dps.Len(); i++ { - tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource) + tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) err := d.Execute(ctx, tCtx) if err != nil { return err @@ -115,7 +115,7 @@ func (d dataPointStatements) handleHistogramDataPoints(ctx context.Context, dps func (d dataPointStatements) handleExponetialHistogramDataPoints(ctx context.Context, dps pmetric.ExponentialHistogramDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { for i := 0; i < dps.Len(); i++ { - tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource) + tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) err := d.Execute(ctx, tCtx) if err != nil { return err @@ -126,7 +126,7 @@ func (d dataPointStatements) handleExponetialHistogramDataPoints(ctx context.Con func (d dataPointStatements) handleSummaryDataPoints(ctx context.Context, dps pmetric.SummaryDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { for i := 0; i < dps.Len(); i++ { - tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource) + tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) err := d.Execute(ctx, tCtx) if err != nil { return err diff --git a/processor/transformprocessor/internal/common/traces.go b/processor/transformprocessor/internal/common/traces.go index fe4c597097702..a961faff3bb09 100644 --- a/processor/transformprocessor/internal/common/traces.go +++ b/processor/transformprocessor/internal/common/traces.go @@ -36,7 +36,7 @@ func (t traceStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces) er sspans := rspans.ScopeSpans().At(j) spans := sspans.Spans() for k := 0; k < spans.Len(); k++ { - tCtx := ottlspan.NewTransformContext(spans.At(k), sspans.Scope(), rspans.Resource()) + tCtx := ottlspan.NewTransformContext(spans.At(k), sspans.Scope(), rspans.Resource(), sspans, rspans) err := t.Execute(ctx, tCtx) if err != nil { return err @@ -69,7 +69,7 @@ func (s spanEventStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces span := spans.At(k) spanEvents := span.Events() for n := 0; n < spanEvents.Len(); n++ { - tCtx := ottlspanevent.NewTransformContext(spanEvents.At(n), span, sspans.Scope(), rspans.Resource()) + tCtx := ottlspanevent.NewTransformContext(spanEvents.At(n), span, sspans.Scope(), rspans.Resource(), sspans, rspans) err := s.Execute(ctx, tCtx) if err != nil { return err diff --git a/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint_test.go b/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint_test.go index 981030c5ad907..926f3021a8e9b 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_datapoint_test.go @@ -115,7 +115,7 @@ func Test_convertDatapointGaugeToSum(t *testing.T) { metric := pmetric.NewMetric() tt.input.CopyTo(metric) - ctx := ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) exprFunc, _ := convertDatapointGaugeToSum(tt.stringAggTemp, tt.monotonic) diff --git a/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_test.go b/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_test.go index 005767c03d265..ebd71c9790a17 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_gauge_to_sum_test.go @@ -115,7 +115,7 @@ func Test_convertGaugeToSum(t *testing.T) { metric := pmetric.NewMetric() tt.input.CopyTo(metric) - ctx := ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) exprFunc, _ := convertGaugeToSum(tt.stringAggTemp, tt.monotonic) diff --git a/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint_test.go b/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint_test.go index 1ba4f0c88d7d2..206f899c6e287 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_datapoint_test.go @@ -83,7 +83,7 @@ func Test_convertDatapointSumToGauge(t *testing.T) { metric := pmetric.NewMetric() tt.input.CopyTo(metric) - ctx := ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) exprFunc, _ := convertDatapointSumToGauge() diff --git a/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_test.go b/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_test.go index 53cf37989ac44..c8227fc4668d4 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_sum_to_gauge_test.go @@ -83,7 +83,7 @@ func Test_convertSumToGauge(t *testing.T) { metric := pmetric.NewMetric() tt.input.CopyTo(metric) - ctx := ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource()) + ctx := ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) exprFunc, _ := convertSumToGauge() diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go index d25d7ef7cb702..0f680987177e1 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_count_val_to_sum_test.go @@ -97,7 +97,7 @@ func Test_ConvertSummaryCountValToSum(t *testing.T) { evaluate, err := convertSummaryCountValToSum(tt.temporality, tt.monotonicity) assert.NoError(t, err) - _, err = evaluate(nil, ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + _, err = evaluate(nil, ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) assert.NoError(t, err) expected := pmetric.NewMetricSlice() diff --git a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go index 552f6ee905b19..540d8ee928b9d 100644 --- a/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go +++ b/processor/transformprocessor/internal/metrics/func_convert_summary_sum_val_to_sum_test.go @@ -105,7 +105,7 @@ func Test_ConvertSummarySumValToSum(t *testing.T) { evaluate, err := convertSummarySumValToSum(tt.temporality, tt.monotonicity) assert.NoError(t, err) - _, err = evaluate(nil, ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + _, err = evaluate(nil, ottldatapoint.NewTransformContext(pmetric.NewNumberDataPoint(), tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) assert.NoError(t, err) expected := pmetric.NewMetricSlice() diff --git a/processor/transformprocessor/internal/metrics/func_copy_metric_test.go b/processor/transformprocessor/internal/metrics/func_copy_metric_test.go index 32c6dd381745f..16d4b320962f2 100644 --- a/processor/transformprocessor/internal/metrics/func_copy_metric_test.go +++ b/processor/transformprocessor/internal/metrics/func_copy_metric_test.go @@ -127,7 +127,7 @@ func Test_copyMetric(t *testing.T) { exprFunc, err := copyMetric(tt.name, tt.desc, tt.unit) assert.NoError(t, err) - _, err = exprFunc(nil, ottlmetric.NewTransformContext(input, ms, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + _, err = exprFunc(nil, ottlmetric.NewTransformContext(input, ms, pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) assert.NoError(t, err) x := pmetric.NewScopeMetrics() diff --git a/processor/transformprocessor/internal/metrics/func_extract_count_metric_test.go b/processor/transformprocessor/internal/metrics/func_extract_count_metric_test.go index cf3c22d121f44..8f6209426046a 100644 --- a/processor/transformprocessor/internal/metrics/func_extract_count_metric_test.go +++ b/processor/transformprocessor/internal/metrics/func_extract_count_metric_test.go @@ -157,7 +157,7 @@ func Test_extractCountMetric(t *testing.T) { evaluate, err := extractCountMetric(tt.monotonicity) assert.NoError(t, err) - _, err = evaluate(nil, ottlmetric.NewTransformContext(tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + _, err = evaluate(nil, ottlmetric.NewTransformContext(tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) assert.Equal(t, tt.wantErr, err) if tt.want != nil { diff --git a/processor/transformprocessor/internal/metrics/func_extract_sum_metric_test.go b/processor/transformprocessor/internal/metrics/func_extract_sum_metric_test.go index a2601675b67e8..a8ba26231743b 100644 --- a/processor/transformprocessor/internal/metrics/func_extract_sum_metric_test.go +++ b/processor/transformprocessor/internal/metrics/func_extract_sum_metric_test.go @@ -284,7 +284,7 @@ func Test_extractSumMetric(t *testing.T) { evaluate, err := extractSumMetric(tt.monotonicity) assert.NoError(t, err) - _, err = evaluate(nil, ottlmetric.NewTransformContext(tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource())) + _, err = evaluate(nil, ottlmetric.NewTransformContext(tt.input, actualMetrics, pcommon.NewInstrumentationScope(), pcommon.NewResource(), pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics())) assert.Equal(t, tt.wantErr, err) if tt.want != nil { From 8898a507eacfd40b3a54bf940fed8f8c3196bdc5 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 17 Apr 2024 14:43:34 +0530 Subject: [PATCH 07/30] Update schemaurl-ottl-context.yaml Update changelog for final merge to include schema_url field in pkg/ottlcontext --- .chloggen/schemaurl-ottl-context.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.chloggen/schemaurl-ottl-context.yaml b/.chloggen/schemaurl-ottl-context.yaml index 0b2707a944f2e..d9ed45aff862f 100644 --- a/.chloggen/schemaurl-ottl-context.yaml +++ b/.chloggen/schemaurl-ottl-context.yaml @@ -1,21 +1,21 @@ # Use this changelog template to create an entry for release notes. # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' -change_type: +change_type: 'enhancement' # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) -component: +component: 'pkg/ottl/ottlcontext' # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: +note: "The following change allows access to schema_urls fields from ottlcontexts, this enhancing flexibility and functionality of ottlcontexts" # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. -issues: [] +issues: [30229] # (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: +subtext: # If your change doesn't affect end users or the exported elements of any package, # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. @@ -24,4 +24,4 @@ subtext: # Include 'user' if the change is relevant to end users. # Include 'api' if there is a change to a library API. # Default: '[user]' -change_logs: [] +change_logs: [user, api] From f6a3b4994cf4795c445a5d66799ac8e8bf7b1a10 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Mon, 22 Apr 2024 22:59:27 +0530 Subject: [PATCH 08/30] [fix]: separated changelogs for api breaking changes and user enhancement changes --- .chloggen/schemaurl-ottl-context-api.yaml | 27 +++++++++++++++ ....yaml => schemaurl-ottl-context-user.yaml} | 6 ++-- pkg/ottl/contexts/internal/scope_test.go | 34 +++++++++++++------ 3 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 .chloggen/schemaurl-ottl-context-api.yaml rename .chloggen/{schemaurl-ottl-context.yaml => schemaurl-ottl-context-user.yaml} (85%) diff --git a/.chloggen/schemaurl-ottl-context-api.yaml b/.chloggen/schemaurl-ottl-context-api.yaml new file mode 100644 index 0000000000000..b3b0a8c233384 --- /dev/null +++ b/.chloggen/schemaurl-ottl-context-api.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'breaking' + +# 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: "Changed ScopeContext, InstrumentationResourceContext, TransformContext interfaces to make SchemaURL accessible in resources and scopes on all signals" + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [30229] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/.chloggen/schemaurl-ottl-context.yaml b/.chloggen/schemaurl-ottl-context-user.yaml similarity index 85% rename from .chloggen/schemaurl-ottl-context.yaml rename to .chloggen/schemaurl-ottl-context-user.yaml index d9ed45aff862f..ed138bfb35c2b 100644 --- a/.chloggen/schemaurl-ottl-context.yaml +++ b/.chloggen/schemaurl-ottl-context-user.yaml @@ -4,10 +4,10 @@ change_type: 'enhancement' # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) -component: 'pkg/ottl/ottlcontext' +component: 'pkg/ottl' # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: "The following change allows access to schema_urls fields from ottlcontexts, this enhancing flexibility and functionality of ottlcontexts" +note: "Add a `schema_url` field to access the SchemaURL in resources and scopes on all signals" # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [30229] @@ -24,4 +24,4 @@ subtext: # Include 'user' if the change is relevant to end users. # Include 'api' if there is a change to a library API. # Default: '[user]' -change_logs: [user, api] +change_logs: [user] diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index 880ef1452450a..67b5900737211 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/pcommon" - "go.opentelemetry.io/collector/pdata/plog" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" @@ -18,7 +17,8 @@ import ( func TestScopePathGetSetter(t *testing.T) { refIS := createInstrumentationScope() - refISC := newInstrumentationScopeContext(refIS, s) + refISC := newInstrumentationScopeContext(refIS, "schema_url") + newSchemaURLItem := createSchemaURLItem("new_schema_url") newAttrs := pcommon.NewMap() newAttrs.PutStr("hello", "world") tests := []struct { @@ -65,9 +65,9 @@ func TestScopePathGetSetter(t *testing.T) { N: "schema_url", }, orig: refISC.GetScopeSchemaURLItem(), - newVal: "new_schema_url", - modified: func(is pcommon.InstrumentationScope) { - refISC.GetScopeSchemaURLItem().SetSchemaUrl() + newVal: newSchemaURLItem, + modified: func(isc pcommon.InstrumentationScope) { + isc := newInstrumentationScopeContext(is, "new_schema_url") }, }, { @@ -352,11 +352,11 @@ func TestScopePathGetSetter(t *testing.T) { is := createInstrumentationScope() - got, err := accessor.Get(context.Background(), newInstrumentationScopeContext(is)) + got, err := accessor.Get(context.Background(), newInstrumentationScopeContext(is, "schema_url")) assert.NoError(t, err) assert.Equal(t, tt.orig, got) - err = accessor.Set(context.Background(), newInstrumentationScopeContext(is), tt.newVal) + err = accessor.Set(context.Background(), newInstrumentationScopeContext(is, "schema_url"), tt.newVal) assert.NoError(t, err) expectedIS := createInstrumentationScope() @@ -407,8 +407,20 @@ func createInstrumentationScope() pcommon.InstrumentationScope { return is } -func createSchemaURLItem() SchemaURLItem { - return plog.NewScopeLogs() +type TestSchemaURLItem struct { + schema_url string +} + +func (t *TestSchemaURLItem) SchemaUrl() string { + return t.schema_url +} + +func (t *TestSchemaURLItem) SetSchemaUrl(v string) { + t.schema_url = v +} + +func createSchemaURLItem(v string) SchemaURLItem { + return &TestSchemaURLItem{schema_url: v} } type instrumentationScopeContext struct { @@ -424,6 +436,6 @@ func (r *instrumentationScopeContext) GetScopeSchemaURLItem() SchemaURLItem { return r.schemaURLItem } -func newInstrumentationScopeContext(is pcommon.InstrumentationScope, schemaURLItem SchemaURLItem) *instrumentationScopeContext { - return &instrumentationScopeContext{is: is, schemaURLItem: schemaURLItem} +func newInstrumentationScopeContext(is pcommon.InstrumentationScope, schema_url string) *instrumentationScopeContext { + return &instrumentationScopeContext{is: is, schemaURLItem: createSchemaURLItem(schema_url)} } From b41f52f00bad4da078e6ba34b1e9efdc7bbad6e4 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Tue, 7 May 2024 15:11:06 +0530 Subject: [PATCH 09/30] [feat]: add small changes to verify requirements for test_suite for scopes --- pkg/ottl/contexts/internal/scope_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index 67b5900737211..837953932df46 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -17,8 +17,7 @@ import ( func TestScopePathGetSetter(t *testing.T) { refIS := createInstrumentationScope() - refISC := newInstrumentationScopeContext(refIS, "schema_url") - newSchemaURLItem := createSchemaURLItem("new_schema_url") + refISC := newInstrumentationScopeContext(refIS) newAttrs := pcommon.NewMap() newAttrs.PutStr("hello", "world") tests := []struct { @@ -65,9 +64,9 @@ func TestScopePathGetSetter(t *testing.T) { N: "schema_url", }, orig: refISC.GetScopeSchemaURLItem(), - newVal: newSchemaURLItem, - modified: func(isc pcommon.InstrumentationScope) { - isc := newInstrumentationScopeContext(is, "new_schema_url") + newVal: "new_schema_url", + modified: func(is pcommon.InstrumentationScope) { + refISC.GetScopeSchemaURLItem().SetSchemaUrl("new_schema_url") }, }, { @@ -419,8 +418,10 @@ func (t *TestSchemaURLItem) SetSchemaUrl(v string) { t.schema_url = v } -func createSchemaURLItem(v string) SchemaURLItem { - return &TestSchemaURLItem{schema_url: v} +func createSchemaURLItem() SchemaURLItem { + return &TestSchemaURLItem{ + schema_url: "schema_url", + } } type instrumentationScopeContext struct { @@ -436,6 +437,6 @@ func (r *instrumentationScopeContext) GetScopeSchemaURLItem() SchemaURLItem { return r.schemaURLItem } -func newInstrumentationScopeContext(is pcommon.InstrumentationScope, schema_url string) *instrumentationScopeContext { - return &instrumentationScopeContext{is: is, schemaURLItem: createSchemaURLItem(schema_url)} +func newInstrumentationScopeContext(is pcommon.InstrumentationScope) *instrumentationScopeContext { + return &instrumentationScopeContext{is: is, schemaURLItem: createSchemaURLItem()} } From 76ab8251e0fa90104116fd98278206c34ef6b3bd Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 15 May 2024 12:14:39 +0530 Subject: [PATCH 10/30] [feat]: added breaking change to NewTransformContext function for ottlresource --- connector/routingconnector/logs.go | 2 +- connector/routingconnector/metrics.go | 2 +- connector/routingconnector/traces.go | 2 +- pkg/ottl/contexts/ottlresource/resource.go | 2 +- pkg/ottl/contexts/ottlresource/resource_test.go | 3 ++- pkg/ottl/e2e/e2e_test.go | 2 +- processor/filterprocessor/metrics.go | 2 +- processor/filterprocessor/metrics_test.go | 2 +- processor/transformprocessor/internal/common/processor.go | 6 +++--- 9 files changed, 12 insertions(+), 11 deletions(-) diff --git a/connector/routingconnector/logs.go b/connector/routingconnector/logs.go index b5a38fcc05e38..2471e5a148f20 100644 --- a/connector/routingconnector/logs.go +++ b/connector/routingconnector/logs.go @@ -69,7 +69,7 @@ func (c *logsConnector) ConsumeLogs(ctx context.Context, ld plog.Logs) error { for i := 0; i < ld.ResourceLogs().Len(); i++ { rlogs := ld.ResourceLogs().At(i) - rtx := ottlresource.NewTransformContext(rlogs.Resource()) + rtx := ottlresource.NewTransformContext(rlogs.Resource(), rlogs) noRoutesMatch := true for _, route := range c.router.routeSlice { diff --git a/connector/routingconnector/metrics.go b/connector/routingconnector/metrics.go index 853d88a343614..a6aad516ee123 100644 --- a/connector/routingconnector/metrics.go +++ b/connector/routingconnector/metrics.go @@ -69,7 +69,7 @@ func (c *metricsConnector) ConsumeMetrics(ctx context.Context, md pmetric.Metric for i := 0; i < md.ResourceMetrics().Len(); i++ { rmetrics := md.ResourceMetrics().At(i) - rtx := ottlresource.NewTransformContext(rmetrics.Resource()) + rtx := ottlresource.NewTransformContext(rmetrics.Resource(), rmetrics) noRoutesMatch := true for _, route := range c.router.routeSlice { diff --git a/connector/routingconnector/traces.go b/connector/routingconnector/traces.go index 1d1b4f2083b01..97a86356e4a6f 100644 --- a/connector/routingconnector/traces.go +++ b/connector/routingconnector/traces.go @@ -68,7 +68,7 @@ func (c *tracesConnector) ConsumeTraces(ctx context.Context, t ptrace.Traces) er var errs error for i := 0; i < t.ResourceSpans().Len(); i++ { rspans := t.ResourceSpans().At(i) - rtx := ottlresource.NewTransformContext(rspans.Resource()) + rtx := ottlresource.NewTransformContext(rspans.Resource(), rspans) noRoutesMatch := true for _, route := range c.router.routeSlice { diff --git a/pkg/ottl/contexts/ottlresource/resource.go b/pkg/ottl/contexts/ottlresource/resource.go index fc1ad950a5f69..146c39a94f4fa 100644 --- a/pkg/ottl/contexts/ottlresource/resource.go +++ b/pkg/ottl/contexts/ottlresource/resource.go @@ -23,7 +23,7 @@ type TransformContext struct { type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(resource pcommon.Resource) TransformContext { +func NewTransformContext(resource pcommon.Resource, schemaURLItem internal.SchemaURLItem) TransformContext { return TransformContext{ resource: resource, cache: pcommon.NewMap(), diff --git a/pkg/ottl/contexts/ottlresource/resource_test.go b/pkg/ottl/contexts/ottlresource/resource_test.go index 77dde557eaa13..9d490a362c3d5 100644 --- a/pkg/ottl/contexts/ottlresource/resource_test.go +++ b/pkg/ottl/contexts/ottlresource/resource_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/pmetric" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" @@ -368,7 +369,7 @@ func Test_newPathGetSetter(t *testing.T) { resource := createTelemetry() - tCtx := NewTransformContext(resource) + tCtx := NewTransformContext(resource, pmetric.NewResourceMetrics()) got, err := accessor.Get(context.Background(), tCtx) assert.NoError(t, err) assert.Equal(t, tt.orig, got) diff --git a/pkg/ottl/e2e/e2e_test.go b/pkg/ottl/e2e/e2e_test.go index 47995bb265e85..7589b1c37bfaa 100644 --- a/pkg/ottl/e2e/e2e_test.go +++ b/pkg/ottl/e2e/e2e_test.go @@ -793,7 +793,7 @@ func constructLogTransformContext() ottllog.TransformContext { m2 := m.PutEmptyMap("nested") m2.PutStr("test", "pass") - return ottllog.NewTransformContext(logRecord, scope, resource) + return ottllog.NewTransformContext(logRecord, scope, resource, plog.NewScopeLogs(), plog.NewResourceLogs()) } func newResourceLogs(tCtx ottllog.TransformContext) plog.ResourceLogs { diff --git a/processor/filterprocessor/metrics.go b/processor/filterprocessor/metrics.go index a1730447c23be..308059bd58c11 100644 --- a/processor/filterprocessor/metrics.go +++ b/processor/filterprocessor/metrics.go @@ -122,7 +122,7 @@ func (fmp *filterMetricProcessor) processMetrics(ctx context.Context, md pmetric md.ResourceMetrics().RemoveIf(func(rmetrics pmetric.ResourceMetrics) bool { resource := rmetrics.Resource() if fmp.skipResourceExpr != nil { - skip, err := fmp.skipResourceExpr.Eval(ctx, ottlresource.NewTransformContext(resource)) + skip, err := fmp.skipResourceExpr.Eval(ctx, ottlresource.NewTransformContext(resource, rmetrics)) if err != nil { errors = multierr.Append(errors, err) return false diff --git a/processor/filterprocessor/metrics_test.go b/processor/filterprocessor/metrics_test.go index 554484293537d..33971cc12eea8 100644 --- a/processor/filterprocessor/metrics_test.go +++ b/processor/filterprocessor/metrics_test.go @@ -1100,7 +1100,7 @@ func Test_ResourceSkipExpr_With_Bridge(t *testing.T) { resource := pcommon.NewResource() resource.Attributes().PutStr("test", "test") - tCtx := ottlresource.NewTransformContext(resource) + tCtx := ottlresource.NewTransformContext(resource, pmetric.NewResourceMetrics()) boolExpr, err := newSkipResExpr(filterconfig.CreateMetricMatchPropertiesFromDefault(tt.condition.Include), filterconfig.CreateMetricMatchPropertiesFromDefault(tt.condition.Exclude)) require.NoError(t, err) diff --git a/processor/transformprocessor/internal/common/processor.go b/processor/transformprocessor/internal/common/processor.go index e3f291c4242f9..e706cd377d13a 100644 --- a/processor/transformprocessor/internal/common/processor.go +++ b/processor/transformprocessor/internal/common/processor.go @@ -36,7 +36,7 @@ func (r resourceStatements) Capabilities() consumer.Capabilities { func (r resourceStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { for i := 0; i < td.ResourceSpans().Len(); i++ { rspans := td.ResourceSpans().At(i) - tCtx := ottlresource.NewTransformContext(rspans.Resource()) + tCtx := ottlresource.NewTransformContext(rspans.Resource(), rspans) err := r.Execute(ctx, tCtx) if err != nil { return err @@ -48,7 +48,7 @@ func (r resourceStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces) func (r resourceStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { for i := 0; i < md.ResourceMetrics().Len(); i++ { rmetrics := md.ResourceMetrics().At(i) - tCtx := ottlresource.NewTransformContext(rmetrics.Resource()) + tCtx := ottlresource.NewTransformContext(rmetrics.Resource(), rmetrics) err := r.Execute(ctx, tCtx) if err != nil { return err @@ -60,7 +60,7 @@ func (r resourceStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metri func (r resourceStatements) ConsumeLogs(ctx context.Context, ld plog.Logs) error { for i := 0; i < ld.ResourceLogs().Len(); i++ { rlogs := ld.ResourceLogs().At(i) - tCtx := ottlresource.NewTransformContext(rlogs.Resource()) + tCtx := ottlresource.NewTransformContext(rlogs.Resource(), rlogs) err := r.Execute(ctx, tCtx) if err != nil { return err From 61844911317ea86bf03524ca5d38e2fc8221beb9 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 15 May 2024 12:15:33 +0530 Subject: [PATCH 11/30] [fix]: Completed Implementation TransformContext interface --- pkg/ottl/contexts/ottlresource/resource.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/ottl/contexts/ottlresource/resource.go b/pkg/ottl/contexts/ottlresource/resource.go index 146c39a94f4fa..24ef18fe823ab 100644 --- a/pkg/ottl/contexts/ottlresource/resource.go +++ b/pkg/ottl/contexts/ottlresource/resource.go @@ -17,16 +17,18 @@ import ( var _ internal.ResourceContext = TransformContext{} type TransformContext struct { - resource pcommon.Resource - cache pcommon.Map + resource pcommon.Resource + cache pcommon.Map + schemaURLItem internal.SchemaURLItem } type Option func(*ottl.Parser[TransformContext]) func NewTransformContext(resource pcommon.Resource, schemaURLItem internal.SchemaURLItem) TransformContext { return TransformContext{ - resource: resource, - cache: pcommon.NewMap(), + resource: resource, + cache: pcommon.NewMap(), + schemaURLItem: schemaURLItem, } } @@ -38,9 +40,8 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -// [TODO]: Find appropriate way to access schemaURLItem using resource func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { - return nil + return tCtx.schemaURLItem } func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { From a7567819912f73fe055517317ba8297f45a30b40 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 15 May 2024 12:33:32 +0530 Subject: [PATCH 12/30] [feat]: Completed the resource_test pkg.contexts.internal --- pkg/ottl/contexts/internal/resource_test.go | 32 ++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/pkg/ottl/contexts/internal/resource_test.go b/pkg/ottl/contexts/internal/resource_test.go index dce78018a2f8b..60fe48aa823c3 100644 --- a/pkg/ottl/contexts/internal/resource_test.go +++ b/pkg/ottl/contexts/internal/resource_test.go @@ -17,6 +17,7 @@ import ( func TestResourcePathGetSetter(t *testing.T) { refResource := createResource() + refResourceContext := newResourceContext(refResource) newAttrs := pcommon.NewMap() newAttrs.PutStr("hello", "world") @@ -36,6 +37,17 @@ func TestResourcePathGetSetter(t *testing.T) { pcommon.NewResource().CopyTo(resource) }, }, + { + name: "resource schema_url", + path: &TestPath[*resourceContext]{ + N: "schema_url", + }, + orig: refResourceContext.GetResourceSchemaURLItem(), + newVal: "new_schema_url", + modified: func(resource pcommon.Resource) { + refResourceContext.GetResourceSchemaURLItem().SetSchemaUrl("new_schema_url") + }, + }, { name: "attributes", path: &TestPath[*resourceContext]{ @@ -370,6 +382,24 @@ func createResource() pcommon.Resource { return resource } +type TestResourceSchemaURLItem struct { + schema_url string +} + +func (t *TestResourceSchemaURLItem) SchemaUrl() string { + return t.schema_url +} + +func (t *TestResourceSchemaURLItem) SetSchemaUrl(v string) { + t.schema_url = v +} + +func createResourceSchemaURLItem() SchemaURLItem { + return &TestResourceSchemaURLItem{ + schema_url: "schema_url", + } +} + type resourceContext struct { resource pcommon.Resource schemaURLItem SchemaURLItem @@ -384,5 +414,5 @@ func (r *resourceContext) GetResourceSchemaURLItem() SchemaURLItem { } func newResourceContext(resource pcommon.Resource) *resourceContext { - return &resourceContext{resource: resource} + return &resourceContext{resource: resource, schemaURLItem: createResourceSchemaURLItem()} } From 5644f907538daedf38404a811f72692569f21499 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Thu, 16 May 2024 16:29:54 +0530 Subject: [PATCH 13/30] [fix]: added license to the schema.go for ottl.contexts.internal --- pkg/ottl/contexts/internal/scope_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index 837953932df46..bd344302b7e4d 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -351,11 +351,11 @@ func TestScopePathGetSetter(t *testing.T) { is := createInstrumentationScope() - got, err := accessor.Get(context.Background(), newInstrumentationScopeContext(is, "schema_url")) + got, err := accessor.Get(context.Background(), newInstrumentationScopeContext(is)) assert.NoError(t, err) assert.Equal(t, tt.orig, got) - err = accessor.Set(context.Background(), newInstrumentationScopeContext(is, "schema_url"), tt.newVal) + err = accessor.Set(context.Background(), newInstrumentationScopeContext(is), tt.newVal) assert.NoError(t, err) expectedIS := createInstrumentationScope() From 2bb11bd388ac749cbf8f64bd031ce389a705de34 Mon Sep 17 00:00:00 2001 From: OOR BOT Date: Thu, 16 May 2024 16:32:13 +0530 Subject: [PATCH 14/30] [feat]: Completed all required changes for PR --- pkg/ottl/contexts/internal/schema.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/ottl/contexts/internal/schema.go b/pkg/ottl/contexts/internal/schema.go index d505cd6ab3925..2f3053138cc58 100644 --- a/pkg/ottl/contexts/internal/schema.go +++ b/pkg/ottl/contexts/internal/schema.go @@ -1,4 +1,6 @@ -package internal +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 +package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal type SchemaURLItem interface { SchemaUrl() string From f778e6cb04ad8826945ef8de4109c101c42130d9 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Fri, 17 May 2024 14:32:56 +0530 Subject: [PATCH 15/30] [feat]: Completed implementation for ottlscope --- pkg/ottl/contexts/ottlscope/scope.go | 10 +++++----- pkg/ottl/contexts/ottlscope/scope_test.go | 3 ++- .../transformprocessor/internal/common/processor.go | 12 ++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/ottl/contexts/ottlscope/scope.go b/pkg/ottl/contexts/ottlscope/scope.go index 2e13da5233036..c22ddea97832a 100644 --- a/pkg/ottl/contexts/ottlscope/scope.go +++ b/pkg/ottl/contexts/ottlscope/scope.go @@ -21,15 +21,17 @@ type TransformContext struct { instrumentationScope pcommon.InstrumentationScope resource pcommon.Resource cache pcommon.Map + schemaURLItem internal.SchemaURLItem } type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource) TransformContext { +func NewTransformContext(instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, schemaURLItem internal.SchemaURLItem) TransformContext { return TransformContext{ instrumentationScope: instrumentationScope, resource: resource, cache: pcommon.NewMap(), + schemaURLItem: schemaURLItem, } } @@ -45,14 +47,12 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -// [TODO]: func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { - return nil + return tCtx.schemaURLItem } -// [TODO]: Methods needs to be implemented for resource func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { - return nil + return tCtx.schemaURLItem } func NewParser(functions map[string]ottl.Factory[TransformContext], telemetrySettings component.TelemetrySettings, options ...Option) (ottl.Parser[TransformContext], error) { diff --git a/pkg/ottl/contexts/ottlscope/scope_test.go b/pkg/ottl/contexts/ottlscope/scope_test.go index 0e417e8c5787a..bd2e899f96fb5 100644 --- a/pkg/ottl/contexts/ottlscope/scope_test.go +++ b/pkg/ottl/contexts/ottlscope/scope_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/plog" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" @@ -401,7 +402,7 @@ func Test_newPathGetSetter(t *testing.T) { il, resource := createTelemetry() - tCtx := NewTransformContext(il, resource) + tCtx := NewTransformContext(il, resource, plog.NewScopeLogs()) got, err := accessor.Get(context.Background(), tCtx) assert.NoError(t, err) assert.Equal(t, tt.orig, got) diff --git a/processor/transformprocessor/internal/common/processor.go b/processor/transformprocessor/internal/common/processor.go index 4c316da4c2194..137cac8ffeac0 100644 --- a/processor/transformprocessor/internal/common/processor.go +++ b/processor/transformprocessor/internal/common/processor.go @@ -39,7 +39,7 @@ func (r resourceStatements) Capabilities() consumer.Capabilities { func (r resourceStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { for i := 0; i < td.ResourceSpans().Len(); i++ { rspans := td.ResourceSpans().At(i) - tCtx := ottlresource.NewTransformContext(rspans.Resource(), rspans) + tCtx := ottlresource.NewTransformContext(rspans.Resource(), rspans) condition, err := r.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -57,7 +57,7 @@ func (r resourceStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces) func (r resourceStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { for i := 0; i < md.ResourceMetrics().Len(); i++ { rmetrics := md.ResourceMetrics().At(i) - tCtx := ottlresource.NewTransformContext(rmetrics.Resource(), rmetrics) + tCtx := ottlresource.NewTransformContext(rmetrics.Resource(), rmetrics) condition, err := r.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -75,7 +75,7 @@ func (r resourceStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metri func (r resourceStatements) ConsumeLogs(ctx context.Context, ld plog.Logs) error { for i := 0; i < ld.ResourceLogs().Len(); i++ { rlogs := ld.ResourceLogs().At(i) - tCtx := ottlresource.NewTransformContext(rlogs.Resource(), rlogs) + tCtx := ottlresource.NewTransformContext(rlogs.Resource(), rlogs) condition, err := r.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -111,7 +111,7 @@ func (s scopeStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces) er rspans := td.ResourceSpans().At(i) for j := 0; j < rspans.ScopeSpans().Len(); j++ { sspans := rspans.ScopeSpans().At(j) - tCtx := ottlscope.NewTransformContext(sspans.Scope(), rspans.Resource()) + tCtx := ottlscope.NewTransformContext(sspans.Scope(), rspans.Resource(), sspans) condition, err := s.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -132,7 +132,7 @@ func (s scopeStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) rmetrics := md.ResourceMetrics().At(i) for j := 0; j < rmetrics.ScopeMetrics().Len(); j++ { smetrics := rmetrics.ScopeMetrics().At(j) - tCtx := ottlscope.NewTransformContext(smetrics.Scope(), rmetrics.Resource()) + tCtx := ottlscope.NewTransformContext(smetrics.Scope(), rmetrics.Resource(), smetrics) condition, err := s.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -153,7 +153,7 @@ func (s scopeStatements) ConsumeLogs(ctx context.Context, ld plog.Logs) error { rlogs := ld.ResourceLogs().At(i) for j := 0; j < rlogs.ScopeLogs().Len(); j++ { slogs := rlogs.ScopeLogs().At(j) - tCtx := ottlscope.NewTransformContext(slogs.Scope(), rlogs.Resource()) + tCtx := ottlscope.NewTransformContext(slogs.Scope(), rlogs.Resource(), slogs) condition, err := s.BoolExpr.Eval(ctx, tCtx) if err != nil { return err From 23851b8ce8f27bad4d4716ca4b3dba0986e0a52d Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Fri, 17 May 2024 08:43:12 -0400 Subject: [PATCH 16/30] Update pkg/ottl/contexts/internal/schema.go --- pkg/ottl/contexts/internal/schema.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ottl/contexts/internal/schema.go b/pkg/ottl/contexts/internal/schema.go index 2f3053138cc58..1f03b6cbce6e4 100644 --- a/pkg/ottl/contexts/internal/schema.go +++ b/pkg/ottl/contexts/internal/schema.go @@ -1,6 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal +package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" type SchemaURLItem interface { SchemaUrl() string From ae7d24f2115876f623b57beec980549d56b7065d Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 22 May 2024 12:09:48 +0530 Subject: [PATCH 17/30] [fix]: Moved SchemaURL to ottlcommon package to expose the struct to users --- pkg/ottl/contexts/internal/resource.go | 4 +++- pkg/ottl/contexts/internal/resource_test.go | 7 ++++--- pkg/ottl/contexts/internal/scope.go | 4 +++- pkg/ottl/contexts/internal/scope_test.go | 7 ++++--- pkg/ottl/contexts/ottlcommon/README.md | 0 pkg/ottl/contexts/ottlcommon/package_test.go | 14 ++++++++++++++ .../contexts/{internal => ottlcommon}/schema.go | 2 +- pkg/ottl/contexts/ottldatapoint/datapoint.go | 5 +++-- pkg/ottl/contexts/ottllog/log.go | 9 +++++---- pkg/ottl/contexts/ottlmetric/metrics.go | 5 +++-- pkg/ottl/contexts/ottlresource/resource.go | 7 ++++--- pkg/ottl/contexts/ottlscope/scope.go | 9 +++++---- pkg/ottl/contexts/ottlspan/span.go | 5 +++-- pkg/ottl/contexts/ottlspanevent/span_events.go | 5 +++-- 14 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 pkg/ottl/contexts/ottlcommon/README.md create mode 100644 pkg/ottl/contexts/ottlcommon/package_test.go rename pkg/ottl/contexts/{internal => ottlcommon}/schema.go (57%) diff --git a/pkg/ottl/contexts/internal/resource.go b/pkg/ottl/contexts/internal/resource.go index 53870a7841dd8..ed9cae1d2834b 100644 --- a/pkg/ottl/contexts/internal/resource.go +++ b/pkg/ottl/contexts/internal/resource.go @@ -9,11 +9,13 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) type ResourceContext interface { GetResource() pcommon.Resource - GetResourceSchemaURLItem() SchemaURLItem + GetResourceSchemaURLItem() ottlcommon.SchemaURLItem } func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { diff --git a/pkg/ottl/contexts/internal/resource_test.go b/pkg/ottl/contexts/internal/resource_test.go index 60fe48aa823c3..cda12613440b4 100644 --- a/pkg/ottl/contexts/internal/resource_test.go +++ b/pkg/ottl/contexts/internal/resource_test.go @@ -11,6 +11,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" ) @@ -394,7 +395,7 @@ func (t *TestResourceSchemaURLItem) SetSchemaUrl(v string) { t.schema_url = v } -func createResourceSchemaURLItem() SchemaURLItem { +func createResourceSchemaURLItem() ottlcommon.SchemaURLItem { return &TestResourceSchemaURLItem{ schema_url: "schema_url", } @@ -402,14 +403,14 @@ func createResourceSchemaURLItem() SchemaURLItem { type resourceContext struct { resource pcommon.Resource - schemaURLItem SchemaURLItem + schemaURLItem ottlcommon.SchemaURLItem } func (r *resourceContext) GetResource() pcommon.Resource { return r.resource } -func (r *resourceContext) GetResourceSchemaURLItem() SchemaURLItem { +func (r *resourceContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { return r.schemaURLItem } diff --git a/pkg/ottl/contexts/internal/scope.go b/pkg/ottl/contexts/internal/scope.go index 8e9139fc1e717..013fa470f0645 100644 --- a/pkg/ottl/contexts/internal/scope.go +++ b/pkg/ottl/contexts/internal/scope.go @@ -9,11 +9,13 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) type InstrumentationScopeContext interface { GetInstrumentationScope() pcommon.InstrumentationScope - GetScopeSchemaURLItem() SchemaURLItem + GetScopeSchemaURLItem() ottlcommon.SchemaURLItem } func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index bd344302b7e4d..d01ed1dda52f6 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -11,6 +11,7 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" ) @@ -418,7 +419,7 @@ func (t *TestSchemaURLItem) SetSchemaUrl(v string) { t.schema_url = v } -func createSchemaURLItem() SchemaURLItem { +func createSchemaURLItem() ottlcommon.SchemaURLItem { return &TestSchemaURLItem{ schema_url: "schema_url", } @@ -426,14 +427,14 @@ func createSchemaURLItem() SchemaURLItem { type instrumentationScopeContext struct { is pcommon.InstrumentationScope - schemaURLItem SchemaURLItem + schemaURLItem ottlcommon.SchemaURLItem } func (r *instrumentationScopeContext) GetInstrumentationScope() pcommon.InstrumentationScope { return r.is } -func (r *instrumentationScopeContext) GetScopeSchemaURLItem() SchemaURLItem { +func (r *instrumentationScopeContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { return r.schemaURLItem } diff --git a/pkg/ottl/contexts/ottlcommon/README.md b/pkg/ottl/contexts/ottlcommon/README.md new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/pkg/ottl/contexts/ottlcommon/package_test.go b/pkg/ottl/contexts/ottlcommon/package_test.go new file mode 100644 index 0000000000000..c37c5b487a12e --- /dev/null +++ b/pkg/ottl/contexts/ottlcommon/package_test.go @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package ottlcommon + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/pkg/ottl/contexts/internal/schema.go b/pkg/ottl/contexts/ottlcommon/schema.go similarity index 57% rename from pkg/ottl/contexts/internal/schema.go rename to pkg/ottl/contexts/ottlcommon/schema.go index 1f03b6cbce6e4..0b09cac09df18 100644 --- a/pkg/ottl/contexts/internal/schema.go +++ b/pkg/ottl/contexts/ottlcommon/schema.go @@ -1,6 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" +package ottlcommon // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon type SchemaURLItem interface { SchemaUrl() string diff --git a/pkg/ottl/contexts/ottldatapoint/datapoint.go b/pkg/ottl/contexts/ottldatapoint/datapoint.go index 9ca9216247e31..b60494721582b 100644 --- a/pkg/ottl/contexts/ottldatapoint/datapoint.go +++ b/pkg/ottl/contexts/ottldatapoint/datapoint.go @@ -14,6 +14,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) const ( @@ -73,11 +74,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.scopeMetrics } -func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.resourceMetrics } diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go index a7ef92f3d02b9..0a5818691e963 100644 --- a/pkg/ottl/contexts/ottllog/log.go +++ b/pkg/ottl/contexts/ottllog/log.go @@ -15,7 +15,8 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/ottlcommon" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" + common "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/ottlcommon" ) const ( @@ -63,11 +64,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.scopeLogs } -func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.resourceLogs } @@ -344,7 +345,7 @@ func accessSeverityText() ottl.StandardGetSetter[TransformContext] { func accessBody() ottl.StandardGetSetter[TransformContext] { return ottl.StandardGetSetter[TransformContext]{ Getter: func(_ context.Context, tCtx TransformContext) (any, error) { - return ottlcommon.GetValue(tCtx.GetLogRecord().Body()), nil + return common.GetValue(tCtx.GetLogRecord().Body()), nil }, Setter: func(_ context.Context, tCtx TransformContext, val any) error { return internal.SetValue(tCtx.GetLogRecord().Body(), val) diff --git a/pkg/ottl/contexts/ottlmetric/metrics.go b/pkg/ottl/contexts/ottlmetric/metrics.go index ce5ff174ee69e..84a7ef82d6227 100644 --- a/pkg/ottl/contexts/ottlmetric/metrics.go +++ b/pkg/ottl/contexts/ottlmetric/metrics.go @@ -13,6 +13,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) var _ internal.ResourceContext = TransformContext{} @@ -63,11 +64,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.scopeMetrics } -func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.resourceMetrics } diff --git a/pkg/ottl/contexts/ottlresource/resource.go b/pkg/ottl/contexts/ottlresource/resource.go index 24ef18fe823ab..b9cbdbc74ab27 100644 --- a/pkg/ottl/contexts/ottlresource/resource.go +++ b/pkg/ottl/contexts/ottlresource/resource.go @@ -12,6 +12,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) var _ internal.ResourceContext = TransformContext{} @@ -19,12 +20,12 @@ var _ internal.ResourceContext = TransformContext{} type TransformContext struct { resource pcommon.Resource cache pcommon.Map - schemaURLItem internal.SchemaURLItem + schemaURLItem ottlcommon.SchemaURLItem } type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(resource pcommon.Resource, schemaURLItem internal.SchemaURLItem) TransformContext { +func NewTransformContext(resource pcommon.Resource, schemaURLItem ottlcommon.SchemaURLItem) TransformContext { return TransformContext{ resource: resource, cache: pcommon.NewMap(), @@ -40,7 +41,7 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.schemaURLItem } diff --git a/pkg/ottl/contexts/ottlscope/scope.go b/pkg/ottl/contexts/ottlscope/scope.go index c22ddea97832a..a2841f650e925 100644 --- a/pkg/ottl/contexts/ottlscope/scope.go +++ b/pkg/ottl/contexts/ottlscope/scope.go @@ -12,6 +12,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) var _ internal.ResourceContext = TransformContext{} @@ -21,12 +22,12 @@ type TransformContext struct { instrumentationScope pcommon.InstrumentationScope resource pcommon.Resource cache pcommon.Map - schemaURLItem internal.SchemaURLItem + schemaURLItem ottlcommon.SchemaURLItem } type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, schemaURLItem internal.SchemaURLItem) TransformContext { +func NewTransformContext(instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, schemaURLItem ottlcommon.SchemaURLItem) TransformContext { return TransformContext{ instrumentationScope: instrumentationScope, resource: resource, @@ -47,11 +48,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.schemaURLItem } -func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.schemaURLItem } diff --git a/pkg/ottl/contexts/ottlspan/span.go b/pkg/ottl/contexts/ottlspan/span.go index a2e5685783518..0cebbbd6a14b4 100644 --- a/pkg/ottl/contexts/ottlspan/span.go +++ b/pkg/ottl/contexts/ottlspan/span.go @@ -13,6 +13,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) var _ internal.ResourceContext = TransformContext{} @@ -56,11 +57,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.resourceSpans } -func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.scopeSpans } diff --git a/pkg/ottl/contexts/ottlspanevent/span_events.go b/pkg/ottl/contexts/ottlspanevent/span_events.go index 1b7045d2c2dce..404eb6bf15130 100644 --- a/pkg/ottl/contexts/ottlspanevent/span_events.go +++ b/pkg/ottl/contexts/ottlspanevent/span_events.go @@ -14,6 +14,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) var _ internal.ResourceContext = TransformContext{} @@ -64,11 +65,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.scopeSpans } -func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { return tCtx.resouceSpans } From a934a2b1db180cdea891e0437a8cf0ac84cddf72 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Fri, 31 May 2024 15:32:33 +0530 Subject: [PATCH 18/30] [fix]: passed correct smetrics, rmetrics for ottldatapoint functions, this would allow access to correct schemaURL --- .../internal/common/metrics.go | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/processor/transformprocessor/internal/common/metrics.go b/processor/transformprocessor/internal/common/metrics.go index 884d2f6d6c6b2..3ae07920ca2cf 100644 --- a/processor/transformprocessor/internal/common/metrics.go +++ b/processor/transformprocessor/internal/common/metrics.go @@ -40,7 +40,7 @@ func (m metricStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metrics smetrics := rmetrics.ScopeMetrics().At(j) metrics := smetrics.Metrics() for k := 0; k < metrics.Len(); k++ { - tCtx := ottlmetric.NewTransformContext(metrics.At(k), smetrics.Metrics(), smetrics.Scope(), rmetrics.Resource(), smetrics, rmetrics) + tCtx := ottlmetric.NewTransformContext(metrics.At(k), smetrics.Metrics(), smetrics.Scope(), rmetrics.Resource(), smetrics, rmetrics) condition, err := m.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -82,15 +82,15 @@ func (d dataPointStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metr //exhaustive:enforce switch metric.Type() { case pmetric.MetricTypeSum: - err = d.handleNumberDataPoints(ctx, metric.Sum().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource()) + err = d.handleNumberDataPoints(ctx, metric.Sum().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource(), smetrics, rmetrics) case pmetric.MetricTypeGauge: - err = d.handleNumberDataPoints(ctx, metric.Gauge().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource()) + err = d.handleNumberDataPoints(ctx, metric.Gauge().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource(), smetrics, rmetrics) case pmetric.MetricTypeHistogram: - err = d.handleHistogramDataPoints(ctx, metric.Histogram().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource()) + err = d.handleHistogramDataPoints(ctx, metric.Histogram().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource(), smetrics, rmetrics) case pmetric.MetricTypeExponentialHistogram: - err = d.handleExponetialHistogramDataPoints(ctx, metric.ExponentialHistogram().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource()) + err = d.handleExponetialHistogramDataPoints(ctx, metric.ExponentialHistogram().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource(), smetrics, rmetrics) case pmetric.MetricTypeSummary: - err = d.handleSummaryDataPoints(ctx, metric.Summary().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource()) + err = d.handleSummaryDataPoints(ctx, metric.Summary().DataPoints(), metrics.At(k), metrics, smetrics.Scope(), rmetrics.Resource(), smetrics, rmetrics) } if err != nil { return err @@ -101,9 +101,9 @@ func (d dataPointStatements) ConsumeMetrics(ctx context.Context, md pmetric.Metr return nil } -func (d dataPointStatements) handleNumberDataPoints(ctx context.Context, dps pmetric.NumberDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { +func (d dataPointStatements) handleNumberDataPoints(ctx context.Context, dps pmetric.NumberDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) error { for i := 0; i < dps.Len(); i++ { - tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) + tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, scopeMetrics, resourceMetrics) condition, err := d.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -118,9 +118,9 @@ func (d dataPointStatements) handleNumberDataPoints(ctx context.Context, dps pme return nil } -func (d dataPointStatements) handleHistogramDataPoints(ctx context.Context, dps pmetric.HistogramDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { +func (d dataPointStatements) handleHistogramDataPoints(ctx context.Context, dps pmetric.HistogramDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) error { for i := 0; i < dps.Len(); i++ { - tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) + tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, scopeMetrics, resourceMetrics) condition, err := d.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -135,9 +135,9 @@ func (d dataPointStatements) handleHistogramDataPoints(ctx context.Context, dps return nil } -func (d dataPointStatements) handleExponetialHistogramDataPoints(ctx context.Context, dps pmetric.ExponentialHistogramDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { +func (d dataPointStatements) handleExponetialHistogramDataPoints(ctx context.Context, dps pmetric.ExponentialHistogramDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) error { for i := 0; i < dps.Len(); i++ { - tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) + tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, scopeMetrics, resourceMetrics) condition, err := d.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -152,9 +152,9 @@ func (d dataPointStatements) handleExponetialHistogramDataPoints(ctx context.Con return nil } -func (d dataPointStatements) handleSummaryDataPoints(ctx context.Context, dps pmetric.SummaryDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource) error { +func (d dataPointStatements) handleSummaryDataPoints(ctx context.Context, dps pmetric.SummaryDataPointSlice, metric pmetric.Metric, metrics pmetric.MetricSlice, is pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) error { for i := 0; i < dps.Len(); i++ { - tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, pmetric.NewScopeMetrics(), pmetric.NewResourceMetrics()) + tCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, metrics, is, resource, scopeMetrics, resourceMetrics) condition, err := d.BoolExpr.Eval(ctx, tCtx) if err != nil { return err From 647bd6854d9a884a6464ab2cc2e583e5d8b62467 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Sun, 2 Jun 2024 16:28:03 +0530 Subject: [PATCH 19/30] [feat]: added tests to transformprocessor package to set schema_url --- .../transformprocessor/internal/common/logs.go | 2 +- .../internal/logs/processor_test.go | 14 ++++++++++++++ .../internal/metrics/processor_test.go | 14 ++++++++++++++ .../internal/traces/processor_test.go | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/processor/transformprocessor/internal/common/logs.go b/processor/transformprocessor/internal/common/logs.go index 50195e57f4e7c..4d9726c38260b 100644 --- a/processor/transformprocessor/internal/common/logs.go +++ b/processor/transformprocessor/internal/common/logs.go @@ -38,7 +38,7 @@ func (l logStatements) ConsumeLogs(ctx context.Context, ld plog.Logs) error { slogs := rlogs.ScopeLogs().At(j) logs := slogs.LogRecords() for k := 0; k < logs.Len(); k++ { - tCtx := ottllog.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource(), slogs, rlogs) + tCtx := ottllog.NewTransformContext(logs.At(k), slogs.Scope(), rlogs.Resource(), slogs, rlogs) condition, err := l.BoolExpr.Eval(ctx, tCtx) if err != nil { return err diff --git a/processor/transformprocessor/internal/logs/processor_test.go b/processor/transformprocessor/internal/logs/processor_test.go index f401093b7d300..caf2fe4c4cd48 100644 --- a/processor/transformprocessor/internal/logs/processor_test.go +++ b/processor/transformprocessor/internal/logs/processor_test.go @@ -44,6 +44,12 @@ func Test_ProcessLogs_ResourceContext(t *testing.T) { want: func(_ plog.Logs) { }, }, + { + statement: `set(schema_url, "test_schema_url")`, + want: func(td plog.Logs) { + td.ResourceLogs().At(0).SetSchemaUrl("test_schema_url") + }, + }, } for _, tt := range tests { @@ -79,6 +85,12 @@ func Test_ProcessLogs_ScopeContext(t *testing.T) { want: func(_ plog.Logs) { }, }, + { + statement: `set(schema_url, "test_schema_url")`, + want: func(td plog.Logs) { + td.ResourceLogs().At(0).ScopeLogs().At(0).SetSchemaUrl("test_schema_url") + }, + }, } for _, tt := range tests { @@ -500,8 +512,10 @@ func Test_ProcessTraces_Error(t *testing.T) { func constructLogs() plog.Logs { td := plog.NewLogs() rs0 := td.ResourceLogs().AppendEmpty() + rs0.SetSchemaUrl("test_schema_url") rs0.Resource().Attributes().PutStr("host.name", "localhost") rs0ils0 := rs0.ScopeLogs().AppendEmpty() + rs0ils0.SetSchemaUrl("test_schema_url") rs0ils0.Scope().SetName("scope") fillLogOne(rs0ils0.LogRecords().AppendEmpty()) fillLogTwo(rs0ils0.LogRecords().AppendEmpty()) diff --git a/processor/transformprocessor/internal/metrics/processor_test.go b/processor/transformprocessor/internal/metrics/processor_test.go index 8b71ab0f62686..03f0b31de2a5f 100644 --- a/processor/transformprocessor/internal/metrics/processor_test.go +++ b/processor/transformprocessor/internal/metrics/processor_test.go @@ -40,6 +40,12 @@ func Test_ProcessMetrics_ResourceContext(t *testing.T) { want: func(_ pmetric.Metrics) { }, }, + { + statement: `set(schema_url, "test_schema_url")`, + want: func(td pmetric.Metrics) { + td.ResourceMetrics().At(0).SetSchemaUrl("test_schema_url") + }, + }, } for _, tt := range tests { @@ -75,6 +81,12 @@ func Test_ProcessMetrics_ScopeContext(t *testing.T) { want: func(_ pmetric.Metrics) { }, }, + { + statement: `set(schema_url, "test_schema_url")`, + want: func(td pmetric.Metrics) { + td.ResourceMetrics().At(0).ScopeMetrics().At(0).SetSchemaUrl("test_schema_url") + }, + }, } for _, tt := range tests { @@ -810,8 +822,10 @@ func Test_ProcessMetrics_Error(t *testing.T) { func constructMetrics() pmetric.Metrics { td := pmetric.NewMetrics() rm0 := td.ResourceMetrics().AppendEmpty() + rm0.SetSchemaUrl("test_schema_url") rm0.Resource().Attributes().PutStr("host.name", "myhost") rm0ils0 := rm0.ScopeMetrics().AppendEmpty() + rm0ils0.SetSchemaUrl("test_schema_url") rm0ils0.Scope().SetName("scope") fillMetricOne(rm0ils0.Metrics().AppendEmpty()) fillMetricTwo(rm0ils0.Metrics().AppendEmpty()) diff --git a/processor/transformprocessor/internal/traces/processor_test.go b/processor/transformprocessor/internal/traces/processor_test.go index e0217942d3b80..134182716c813 100644 --- a/processor/transformprocessor/internal/traces/processor_test.go +++ b/processor/transformprocessor/internal/traces/processor_test.go @@ -45,6 +45,12 @@ func Test_ProcessTraces_ResourceContext(t *testing.T) { want: func(_ ptrace.Traces) { }, }, + { + statement: `set(schema_url, "test_schema_url")`, + want: func(td ptrace.Traces) { + td.ResourceSpans().At(0).SetSchemaUrl("test_schema_url") + }, + }, } for _, tt := range tests { @@ -80,6 +86,12 @@ func Test_ProcessTraces_ScopeContext(t *testing.T) { want: func(_ ptrace.Traces) { }, }, + { + statement: `set(schema_url, "test_schema_url")`, + want: func(td ptrace.Traces) { + td.ResourceSpans().At(0).ScopeSpans().At(0).SetSchemaUrl("test_schema_url") + }, + }, } for _, tt := range tests { @@ -664,8 +676,10 @@ func BenchmarkHundredSpans(b *testing.B) { func constructTraces() ptrace.Traces { td := ptrace.NewTraces() rs0 := td.ResourceSpans().AppendEmpty() + rs0.SetSchemaUrl("test_schema_url") rs0.Resource().Attributes().PutStr("host.name", "localhost") rs0ils0 := rs0.ScopeSpans().AppendEmpty() + rs0ils0.SetSchemaUrl("test_schema_url") rs0ils0.Scope().SetName("scope") fillSpanOne(rs0ils0.Spans().AppendEmpty()) fillSpanTwo(rs0ils0.Spans().AppendEmpty()) From e0192b8ed8a0155f0d623a631493c6e753611f3a Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:10:25 -0400 Subject: [PATCH 20/30] Update pkg/ottl/contexts/ottlcommon/schema.go --- pkg/ottl/contexts/ottlcommon/schema.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ottl/contexts/ottlcommon/schema.go b/pkg/ottl/contexts/ottlcommon/schema.go index 0b09cac09df18..4c6488bcaf22a 100644 --- a/pkg/ottl/contexts/ottlcommon/schema.go +++ b/pkg/ottl/contexts/ottlcommon/schema.go @@ -1,6 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package ottlcommon // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon +package ottlcommon // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" type SchemaURLItem interface { SchemaUrl() string From 94939e6bf26daac40915d95b5a2d5eba30bec050 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Tue, 4 Jun 2024 11:35:25 +0530 Subject: [PATCH 21/30] [fix]: Fixed linting issues inside transform processor --- processor/transformprocessor/internal/common/traces.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/transformprocessor/internal/common/traces.go b/processor/transformprocessor/internal/common/traces.go index cd3e5b3409c0f..de03b8afe9172 100644 --- a/processor/transformprocessor/internal/common/traces.go +++ b/processor/transformprocessor/internal/common/traces.go @@ -39,7 +39,7 @@ func (t traceStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces) er sspans := rspans.ScopeSpans().At(j) spans := sspans.Spans() for k := 0; k < spans.Len(); k++ { - tCtx := ottlspan.NewTransformContext(spans.At(k), sspans.Scope(), rspans.Resource(), sspans, rspans) + tCtx := ottlspan.NewTransformContext(spans.At(k), sspans.Scope(), rspans.Resource(), sspans, rspans) condition, err := t.BoolExpr.Eval(ctx, tCtx) if err != nil { return err @@ -79,7 +79,7 @@ func (s spanEventStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces span := spans.At(k) spanEvents := span.Events() for n := 0; n < spanEvents.Len(); n++ { - tCtx := ottlspanevent.NewTransformContext(spanEvents.At(n), span, sspans.Scope(), rspans.Resource(), sspans, rspans) + tCtx := ottlspanevent.NewTransformContext(spanEvents.At(n), span, sspans.Scope(), rspans.Resource(), sspans, rspans) condition, err := s.BoolExpr.Eval(ctx, tCtx) if err != nil { return err From c97ec249fb7864785496451b5c8b00e5b71fe1ec Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 5 Jun 2024 00:07:20 +0530 Subject: [PATCH 22/30] [fix]: linting errors removed from ottl/contexts --- pkg/ottl/contexts/internal/scope.go | 4 ++-- pkg/ottl/contexts/internal/scope_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/ottl/contexts/internal/scope.go b/pkg/ottl/contexts/internal/scope.go index 013fa470f0645..7c5911591a8bc 100644 --- a/pkg/ottl/contexts/internal/scope.go +++ b/pkg/ottl/contexts/internal/scope.go @@ -125,10 +125,10 @@ func accessInstrumentationScopeDroppedAttributesCount[K InstrumentationScopeCont func accessInstrumentationScopeSchemaURLItem[K InstrumentationScopeContext]() ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ - Getter: func(ctx context.Context, tCtx K) (any, error) { + Getter: func(_ context.Context, tCtx K) (any, error) { return tCtx.GetScopeSchemaURLItem().SchemaUrl(), nil }, - Setter: func(ctx context.Context, tCtx K, val any) error { + Setter: func(_ context.Context, tCtx K, val any) error { if schemaURL, ok := val.(string); ok { tCtx.GetScopeSchemaURLItem().SetSchemaUrl(schemaURL) } diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index d01ed1dda52f6..31b3171b90207 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -66,7 +66,7 @@ func TestScopePathGetSetter(t *testing.T) { }, orig: refISC.GetScopeSchemaURLItem(), newVal: "new_schema_url", - modified: func(is pcommon.InstrumentationScope) { + modified: func(_ pcommon.InstrumentationScope) { refISC.GetScopeSchemaURLItem().SetSchemaUrl("new_schema_url") }, }, @@ -408,20 +408,20 @@ func createInstrumentationScope() pcommon.InstrumentationScope { } type TestSchemaURLItem struct { - schema_url string + schemaURL string } func (t *TestSchemaURLItem) SchemaUrl() string { - return t.schema_url + return t.schemaURL } func (t *TestSchemaURLItem) SetSchemaUrl(v string) { - t.schema_url = v + t.schemaURL = v } func createSchemaURLItem() ottlcommon.SchemaURLItem { return &TestSchemaURLItem{ - schema_url: "schema_url", + schemaURL: "schema_url", } } From d38168c56093af1ffa0f3e28cae4f71c088f7d39 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Tue, 11 Jun 2024 19:21:01 +0530 Subject: [PATCH 23/30] [fix]: Adding linting rule in golang to prevent lint on interface by gofmt --- pkg/ottl/contexts/ottlcommon/schema.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/ottl/contexts/ottlcommon/schema.go b/pkg/ottl/contexts/ottlcommon/schema.go index 4c6488bcaf22a..0dbffed376506 100644 --- a/pkg/ottl/contexts/ottlcommon/schema.go +++ b/pkg/ottl/contexts/ottlcommon/schema.go @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 package ottlcommon // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" +//nolint:gofmt type SchemaURLItem interface { SchemaUrl() string SetSchemaUrl(v string) From 7dcfa93537970b0706b1486a7f2822b7ca3dbe3c Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 12 Jun 2024 17:07:40 +0530 Subject: [PATCH 24/30] Removed ottlcommon package, did required changes for referencing schemaURLItem correctly --- pkg/ottl/contexts/internal/resource.go | 4 +--- pkg/ottl/contexts/internal/resource_test.go | 7 +++--- .../{ottlcommon => internal}/schema.go | 2 +- pkg/ottl/contexts/internal/scope.go | 4 +--- pkg/ottl/contexts/internal/scope_test.go | 7 +++--- pkg/ottl/contexts/ottlcommon/README.md | 0 pkg/ottl/contexts/ottlcommon/package_test.go | 14 ------------ pkg/ottl/contexts/ottldatapoint/datapoint.go | 5 ++--- pkg/ottl/contexts/ottllog/log.go | 8 +++---- pkg/ottl/contexts/ottlmetric/metrics.go | 22 +++++-------------- pkg/ottl/contexts/ottlresource/resource.go | 7 +++--- pkg/ottl/contexts/ottlscope/scope.go | 9 ++++---- pkg/ottl/contexts/ottlspan/span.go | 5 ++--- .../contexts/ottlspanevent/span_events.go | 5 ++--- pkg/ottl/go.sum | 1 + 15 files changed, 31 insertions(+), 69 deletions(-) rename pkg/ottl/contexts/{ottlcommon => internal}/schema.go (59%) delete mode 100644 pkg/ottl/contexts/ottlcommon/README.md delete mode 100644 pkg/ottl/contexts/ottlcommon/package_test.go diff --git a/pkg/ottl/contexts/internal/resource.go b/pkg/ottl/contexts/internal/resource.go index ed9cae1d2834b..53870a7841dd8 100644 --- a/pkg/ottl/contexts/internal/resource.go +++ b/pkg/ottl/contexts/internal/resource.go @@ -9,13 +9,11 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) type ResourceContext interface { GetResource() pcommon.Resource - GetResourceSchemaURLItem() ottlcommon.SchemaURLItem + GetResourceSchemaURLItem() SchemaURLItem } func ResourcePathGetSetter[K ResourceContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { diff --git a/pkg/ottl/contexts/internal/resource_test.go b/pkg/ottl/contexts/internal/resource_test.go index cda12613440b4..60fe48aa823c3 100644 --- a/pkg/ottl/contexts/internal/resource_test.go +++ b/pkg/ottl/contexts/internal/resource_test.go @@ -11,7 +11,6 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" ) @@ -395,7 +394,7 @@ func (t *TestResourceSchemaURLItem) SetSchemaUrl(v string) { t.schema_url = v } -func createResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func createResourceSchemaURLItem() SchemaURLItem { return &TestResourceSchemaURLItem{ schema_url: "schema_url", } @@ -403,14 +402,14 @@ func createResourceSchemaURLItem() ottlcommon.SchemaURLItem { type resourceContext struct { resource pcommon.Resource - schemaURLItem ottlcommon.SchemaURLItem + schemaURLItem SchemaURLItem } func (r *resourceContext) GetResource() pcommon.Resource { return r.resource } -func (r *resourceContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func (r *resourceContext) GetResourceSchemaURLItem() SchemaURLItem { return r.schemaURLItem } diff --git a/pkg/ottl/contexts/ottlcommon/schema.go b/pkg/ottl/contexts/internal/schema.go similarity index 59% rename from pkg/ottl/contexts/ottlcommon/schema.go rename to pkg/ottl/contexts/internal/schema.go index 0dbffed376506..3763e6a8ee41e 100644 --- a/pkg/ottl/contexts/ottlcommon/schema.go +++ b/pkg/ottl/contexts/internal/schema.go @@ -1,6 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package ottlcommon // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" +package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" //nolint:gofmt type SchemaURLItem interface { diff --git a/pkg/ottl/contexts/internal/scope.go b/pkg/ottl/contexts/internal/scope.go index 7c5911591a8bc..6bc5d7352005c 100644 --- a/pkg/ottl/contexts/internal/scope.go +++ b/pkg/ottl/contexts/internal/scope.go @@ -9,13 +9,11 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" - - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" ) type InstrumentationScopeContext interface { GetInstrumentationScope() pcommon.InstrumentationScope - GetScopeSchemaURLItem() ottlcommon.SchemaURLItem + GetScopeSchemaURLItem() SchemaURLItem } func ScopePathGetSetter[K InstrumentationScopeContext](path ottl.Path[K]) (ottl.GetSetter[K], error) { diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index 31b3171b90207..b7e291c8bf71c 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -11,7 +11,6 @@ import ( "go.opentelemetry.io/collector/pdata/pcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottltest" ) @@ -419,7 +418,7 @@ func (t *TestSchemaURLItem) SetSchemaUrl(v string) { t.schemaURL = v } -func createSchemaURLItem() ottlcommon.SchemaURLItem { +func createSchemaURLItem() SchemaURLItem { return &TestSchemaURLItem{ schemaURL: "schema_url", } @@ -427,14 +426,14 @@ func createSchemaURLItem() ottlcommon.SchemaURLItem { type instrumentationScopeContext struct { is pcommon.InstrumentationScope - schemaURLItem ottlcommon.SchemaURLItem + schemaURLItem SchemaURLItem } func (r *instrumentationScopeContext) GetInstrumentationScope() pcommon.InstrumentationScope { return r.is } -func (r *instrumentationScopeContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { +func (r *instrumentationScopeContext) GetScopeSchemaURLItem() SchemaURLItem { return r.schemaURLItem } diff --git a/pkg/ottl/contexts/ottlcommon/README.md b/pkg/ottl/contexts/ottlcommon/README.md deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/pkg/ottl/contexts/ottlcommon/package_test.go b/pkg/ottl/contexts/ottlcommon/package_test.go deleted file mode 100644 index c37c5b487a12e..0000000000000 --- a/pkg/ottl/contexts/ottlcommon/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package ottlcommon - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/pkg/ottl/contexts/ottldatapoint/datapoint.go b/pkg/ottl/contexts/ottldatapoint/datapoint.go index f00b5b04470ba..a8a6f21580454 100644 --- a/pkg/ottl/contexts/ottldatapoint/datapoint.go +++ b/pkg/ottl/contexts/ottldatapoint/datapoint.go @@ -16,7 +16,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -98,11 +97,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { return tCtx.scopeMetrics } -func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { return tCtx.resourceMetrics } diff --git a/pkg/ottl/contexts/ottllog/log.go b/pkg/ottl/contexts/ottllog/log.go index 20e5183d4fcd9..6ed8e2b9ae893 100644 --- a/pkg/ottl/contexts/ottllog/log.go +++ b/pkg/ottl/contexts/ottllog/log.go @@ -17,10 +17,8 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" - common "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/ottlcommon" + common "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/internal/ottlcommon" ) const ( @@ -94,11 +92,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { return tCtx.scopeLogs } -func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { return tCtx.resourceLogs } diff --git a/pkg/ottl/contexts/ottlmetric/metrics.go b/pkg/ottl/contexts/ottlmetric/metrics.go index 0213237886cee..ce5ff174ee69e 100644 --- a/pkg/ottl/contexts/ottlmetric/metrics.go +++ b/pkg/ottl/contexts/ottlmetric/metrics.go @@ -5,23 +5,19 @@ package ottlmetric // import "github.com/open-telemetry/opentelemetry-collector- import ( "context" - "errors" "fmt" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" - "go.uber.org/zap/zapcore" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) -var _ internal.ResourceContext = (*TransformContext)(nil) -var _ internal.InstrumentationScopeContext = (*TransformContext)(nil) -var _ zapcore.ObjectMarshaler = (*TransformContext)(nil) +var _ internal.ResourceContext = TransformContext{} +var _ internal.InstrumentationScopeContext = TransformContext{} +var _ internal.MetricContext = TransformContext{} type TransformContext struct { metric pmetric.Metric @@ -33,14 +29,6 @@ type TransformContext struct { resourceMetrics pmetric.ResourceMetrics } -func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) error { - err := encoder.AddObject("resource", logging.Resource(tCtx.resource)) - err = errors.Join(err, encoder.AddObject("scope", logging.InstrumentationScope(tCtx.instrumentationScope))) - err = errors.Join(err, encoder.AddObject("metric", logging.Metric(tCtx.metric))) - err = errors.Join(err, encoder.AddObject("cache", logging.Map(tCtx.cache))) - return err -} - type Option func(*ottl.Parser[TransformContext]) func NewTransformContext(metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics) TransformContext { @@ -75,11 +63,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { return tCtx.scopeMetrics } -func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { return tCtx.resourceMetrics } diff --git a/pkg/ottl/contexts/ottlresource/resource.go b/pkg/ottl/contexts/ottlresource/resource.go index 17f3bf5a6c023..f7fddd5b7ac4b 100644 --- a/pkg/ottl/contexts/ottlresource/resource.go +++ b/pkg/ottl/contexts/ottlresource/resource.go @@ -14,7 +14,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -24,7 +23,7 @@ var _ zapcore.ObjectMarshaler = (*TransformContext)(nil) type TransformContext struct { resource pcommon.Resource cache pcommon.Map - schemaURLItem ottlcommon.SchemaURLItem + schemaURLItem internal.SchemaURLItem } func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) error { @@ -35,7 +34,7 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(resource pcommon.Resource, schemaURLItem ottlcommon.SchemaURLItem) TransformContext { +func NewTransformContext(resource pcommon.Resource, schemaURLItem internal.SchemaURLItem) TransformContext { return TransformContext{ resource: resource, cache: pcommon.NewMap(), @@ -51,7 +50,7 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { return tCtx.schemaURLItem } diff --git a/pkg/ottl/contexts/ottlscope/scope.go b/pkg/ottl/contexts/ottlscope/scope.go index f404578650f91..b55635bdcdb38 100644 --- a/pkg/ottl/contexts/ottlscope/scope.go +++ b/pkg/ottl/contexts/ottlscope/scope.go @@ -14,7 +14,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -26,7 +25,7 @@ type TransformContext struct { instrumentationScope pcommon.InstrumentationScope resource pcommon.Resource cache pcommon.Map - schemaURLItem ottlcommon.SchemaURLItem + schemaURLItem internal.SchemaURLItem } func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) error { @@ -38,7 +37,7 @@ func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) err type Option func(*ottl.Parser[TransformContext]) -func NewTransformContext(instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, schemaURLItem ottlcommon.SchemaURLItem) TransformContext { +func NewTransformContext(instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, schemaURLItem internal.SchemaURLItem) TransformContext { return TransformContext{ instrumentationScope: instrumentationScope, resource: resource, @@ -59,11 +58,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { return tCtx.schemaURLItem } -func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { return tCtx.schemaURLItem } diff --git a/pkg/ottl/contexts/ottlspan/span.go b/pkg/ottl/contexts/ottlspan/span.go index 5a88356d789eb..34fc2c944c1e3 100644 --- a/pkg/ottl/contexts/ottlspan/span.go +++ b/pkg/ottl/contexts/ottlspan/span.go @@ -15,7 +15,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -69,11 +68,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { return tCtx.resourceSpans } -func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { return tCtx.scopeSpans } diff --git a/pkg/ottl/contexts/ottlspanevent/span_events.go b/pkg/ottl/contexts/ottlspanevent/span_events.go index 9bece30e0e1ba..8a4de90f15e97 100644 --- a/pkg/ottl/contexts/ottlspanevent/span_events.go +++ b/pkg/ottl/contexts/ottlspanevent/span_events.go @@ -16,7 +16,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlcommon" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging" ) @@ -77,11 +76,11 @@ func (tCtx TransformContext) getCache() pcommon.Map { return tCtx.cache } -func (tCtx TransformContext) GetScopeSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetScopeSchemaURLItem() internal.SchemaURLItem { return tCtx.scopeSpans } -func (tCtx TransformContext) GetResourceSchemaURLItem() ottlcommon.SchemaURLItem { +func (tCtx TransformContext) GetResourceSchemaURLItem() internal.SchemaURLItem { return tCtx.resouceSpans } diff --git a/pkg/ottl/go.sum b/pkg/ottl/go.sum index d54637b29bae1..42a399ece9991 100644 --- a/pkg/ottl/go.sum +++ b/pkg/ottl/go.sum @@ -60,6 +60,7 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/collector v0.102.2-0.20240606174409-6888f8f7a45f h1:l2ZMTF7/+2qhoLy7poXJFCdkQDYN3C8D5Bi/8bEmQWE= go.opentelemetry.io/collector/component v0.102.2-0.20240606174409-6888f8f7a45f h1:OBqdOlHQqgt991UMBC6B04N/fLZNZS/ik/JC+XH41OE= go.opentelemetry.io/collector/component v0.102.2-0.20240606174409-6888f8f7a45f/go.mod h1:hg92ib1gYoAh1TxQj4k0O/V+WH1CGs76LQTHfbJ1cU4= go.opentelemetry.io/collector/config/configtelemetry v0.102.2-0.20240606174409-6888f8f7a45f h1:Wb7t+GbTt2rZ4O3qBwHbW2gq2lecsbQ6R6UQZbi6lKA= From 71eb05ab1752da521f21d30fb53eb11a383674cf Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 12 Jun 2024 17:24:00 +0530 Subject: [PATCH 25/30] Update go.sum --- pkg/ottl/go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/ottl/go.sum b/pkg/ottl/go.sum index 42a399ece9991..d54637b29bae1 100644 --- a/pkg/ottl/go.sum +++ b/pkg/ottl/go.sum @@ -60,7 +60,6 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.opentelemetry.io/collector v0.102.2-0.20240606174409-6888f8f7a45f h1:l2ZMTF7/+2qhoLy7poXJFCdkQDYN3C8D5Bi/8bEmQWE= go.opentelemetry.io/collector/component v0.102.2-0.20240606174409-6888f8f7a45f h1:OBqdOlHQqgt991UMBC6B04N/fLZNZS/ik/JC+XH41OE= go.opentelemetry.io/collector/component v0.102.2-0.20240606174409-6888f8f7a45f/go.mod h1:hg92ib1gYoAh1TxQj4k0O/V+WH1CGs76LQTHfbJ1cU4= go.opentelemetry.io/collector/config/configtelemetry v0.102.2-0.20240606174409-6888f8f7a45f h1:Wb7t+GbTt2rZ4O3qBwHbW2gq2lecsbQ6R6UQZbi6lKA= From d1140fb6313c187ce9c8fe9b651a87c757eaf1cb Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 19 Jun 2024 11:45:32 +0530 Subject: [PATCH 26/30] Updated test files to fix errors in unit tests --- pkg/ottl/contexts/internal/resource.go | 4 ++-- pkg/ottl/contexts/internal/resource_test.go | 12 ++++++------ pkg/ottl/contexts/internal/scope_test.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/ottl/contexts/internal/resource.go b/pkg/ottl/contexts/internal/resource.go index 53870a7841dd8..2dfee7fce9f8c 100644 --- a/pkg/ottl/contexts/internal/resource.go +++ b/pkg/ottl/contexts/internal/resource.go @@ -90,10 +90,10 @@ func accessResourceDroppedAttributesCount[K ResourceContext]() ottl.StandardGetS func accessResourceSchemaURLItem[K ResourceContext]() ottl.StandardGetSetter[K] { return ottl.StandardGetSetter[K]{ - Getter: func(ctx context.Context, tCtx K) (any, error) { + Getter: func(_ context.Context, tCtx K) (any, error) { return tCtx.GetResourceSchemaURLItem().SchemaUrl(), nil }, - Setter: func(ctx context.Context, tCtx K, val any) error { + Setter: func(_ context.Context, tCtx K, val any) error { if schemaURL, ok := val.(string); ok { tCtx.GetResourceSchemaURLItem().SetSchemaUrl(schemaURL) } diff --git a/pkg/ottl/contexts/internal/resource_test.go b/pkg/ottl/contexts/internal/resource_test.go index 60fe48aa823c3..4c06cf0ee34fe 100644 --- a/pkg/ottl/contexts/internal/resource_test.go +++ b/pkg/ottl/contexts/internal/resource_test.go @@ -42,9 +42,9 @@ func TestResourcePathGetSetter(t *testing.T) { path: &TestPath[*resourceContext]{ N: "schema_url", }, - orig: refResourceContext.GetResourceSchemaURLItem(), + orig: refResourceContext.GetResourceSchemaURLItem().SchemaUrl(), newVal: "new_schema_url", - modified: func(resource pcommon.Resource) { + modified: func(_ pcommon.Resource) { refResourceContext.GetResourceSchemaURLItem().SetSchemaUrl("new_schema_url") }, }, @@ -383,20 +383,20 @@ func createResource() pcommon.Resource { } type TestResourceSchemaURLItem struct { - schema_url string + schemaURL string } func (t *TestResourceSchemaURLItem) SchemaUrl() string { - return t.schema_url + return t.schemaURL } func (t *TestResourceSchemaURLItem) SetSchemaUrl(v string) { - t.schema_url = v + t.schemaURL = v } func createResourceSchemaURLItem() SchemaURLItem { return &TestResourceSchemaURLItem{ - schema_url: "schema_url", + schemaURL: "schema_url", } } diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index b7e291c8bf71c..74f171c2dd026 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -63,7 +63,7 @@ func TestScopePathGetSetter(t *testing.T) { path: &TestPath[*instrumentationScopeContext]{ N: "schema_url", }, - orig: refISC.GetScopeSchemaURLItem(), + orig: refISC.GetScopeSchemaURLItem().SchemaUrl(), newVal: "new_schema_url", modified: func(_ pcommon.InstrumentationScope) { refISC.GetScopeSchemaURLItem().SetSchemaUrl("new_schema_url") From ace0b7410f12113065014f4745612d3c885e0158 Mon Sep 17 00:00:00 2001 From: Ishan Shanware Date: Wed, 19 Jun 2024 12:38:27 +0530 Subject: [PATCH 27/30] Updated test files to fix errors in processort/routingprocessor --- processor/routingprocessor/metrics.go | 2 +- processor/routingprocessor/traces.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/routingprocessor/metrics.go b/processor/routingprocessor/metrics.go index a4003bc9c41c1..a7192519cb89b 100644 --- a/processor/routingprocessor/metrics.go +++ b/processor/routingprocessor/metrics.go @@ -115,7 +115,7 @@ func (p *metricsProcessor) route(ctx context.Context, tm pmetric.Metrics) error pmetric.NewMetricSlice(), pcommon.NewInstrumentationScope(), rmetrics.Resource(), - rmetrics.ScopeMetrics().At(i), + pmetric.NewScopeMetrics(), rmetrics, ) diff --git a/processor/routingprocessor/traces.go b/processor/routingprocessor/traces.go index eac88da76d5b2..5b0762ebdc76a 100644 --- a/processor/routingprocessor/traces.go +++ b/processor/routingprocessor/traces.go @@ -114,7 +114,7 @@ func (p *tracesProcessor) route(ctx context.Context, t ptrace.Traces) error { ptrace.NewSpan(), pcommon.NewInstrumentationScope(), rspans.Resource(), - rspans.ScopeSpans().At(i), + ptrace.NewScopeSpans(), rspans, ) From e9f05b9fe63535e6dabcc58423f5923516ae736a Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Fri, 21 Jun 2024 08:50:00 -0400 Subject: [PATCH 28/30] Update pkg/ottl/contexts/internal/schema.go --- pkg/ottl/contexts/internal/schema.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/ottl/contexts/internal/schema.go b/pkg/ottl/contexts/internal/schema.go index 3763e6a8ee41e..225f2fba15e9e 100644 --- a/pkg/ottl/contexts/internal/schema.go +++ b/pkg/ottl/contexts/internal/schema.go @@ -2,8 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal" -//nolint:gofmt +//revive:disable:var-naming The methods in this interface are defined by pdata types. type SchemaURLItem interface { SchemaUrl() string SetSchemaUrl(v string) } +//revive:enable:var-naming From 5f7ea93908c1cf852c7058c1ce30dc95b3a1eb7d Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Fri, 21 Jun 2024 08:56:21 -0400 Subject: [PATCH 29/30] Fix lint --- pkg/ottl/contexts/internal/resource_test.go | 2 ++ pkg/ottl/contexts/internal/scope_test.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pkg/ottl/contexts/internal/resource_test.go b/pkg/ottl/contexts/internal/resource_test.go index 4c06cf0ee34fe..679844ca95b4a 100644 --- a/pkg/ottl/contexts/internal/resource_test.go +++ b/pkg/ottl/contexts/internal/resource_test.go @@ -386,6 +386,7 @@ type TestResourceSchemaURLItem struct { schemaURL string } +//revive:disable:var-naming This must implement the SchemaURL interface. func (t *TestResourceSchemaURLItem) SchemaUrl() string { return t.schemaURL } @@ -393,6 +394,7 @@ func (t *TestResourceSchemaURLItem) SchemaUrl() string { func (t *TestResourceSchemaURLItem) SetSchemaUrl(v string) { t.schemaURL = v } +//revive:enable:var-naming func createResourceSchemaURLItem() SchemaURLItem { return &TestResourceSchemaURLItem{ diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index 74f171c2dd026..f99a1111b8f9d 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -410,6 +410,7 @@ type TestSchemaURLItem struct { schemaURL string } +//revive:disable:var-naming This must implement the SchemaURL interface. func (t *TestSchemaURLItem) SchemaUrl() string { return t.schemaURL } @@ -417,6 +418,7 @@ func (t *TestSchemaURLItem) SchemaUrl() string { func (t *TestSchemaURLItem) SetSchemaUrl(v string) { t.schemaURL = v } +//revive:enable:var-naming func createSchemaURLItem() SchemaURLItem { return &TestSchemaURLItem{ From 638d61f85461010590801e46bfc31a5bb206f693 Mon Sep 17 00:00:00 2001 From: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> Date: Fri, 21 Jun 2024 09:04:53 -0400 Subject: [PATCH 30/30] Run gofmt --- pkg/ottl/contexts/internal/resource_test.go | 1 + pkg/ottl/contexts/internal/schema.go | 1 + pkg/ottl/contexts/internal/scope_test.go | 1 + 3 files changed, 3 insertions(+) diff --git a/pkg/ottl/contexts/internal/resource_test.go b/pkg/ottl/contexts/internal/resource_test.go index 679844ca95b4a..71100ec95122e 100644 --- a/pkg/ottl/contexts/internal/resource_test.go +++ b/pkg/ottl/contexts/internal/resource_test.go @@ -394,6 +394,7 @@ func (t *TestResourceSchemaURLItem) SchemaUrl() string { func (t *TestResourceSchemaURLItem) SetSchemaUrl(v string) { t.schemaURL = v } + //revive:enable:var-naming func createResourceSchemaURLItem() SchemaURLItem { diff --git a/pkg/ottl/contexts/internal/schema.go b/pkg/ottl/contexts/internal/schema.go index 225f2fba15e9e..c5b6702200e5c 100644 --- a/pkg/ottl/contexts/internal/schema.go +++ b/pkg/ottl/contexts/internal/schema.go @@ -7,4 +7,5 @@ type SchemaURLItem interface { SchemaUrl() string SetSchemaUrl(v string) } + //revive:enable:var-naming diff --git a/pkg/ottl/contexts/internal/scope_test.go b/pkg/ottl/contexts/internal/scope_test.go index f99a1111b8f9d..1f9837fc8d2b6 100644 --- a/pkg/ottl/contexts/internal/scope_test.go +++ b/pkg/ottl/contexts/internal/scope_test.go @@ -418,6 +418,7 @@ func (t *TestSchemaURLItem) SchemaUrl() string { func (t *TestSchemaURLItem) SetSchemaUrl(v string) { t.schemaURL = v } + //revive:enable:var-naming func createSchemaURLItem() SchemaURLItem {