Skip to content

Commit

Permalink
[pkg/ottl] Support dynamic indexing
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Dec 11, 2024
1 parent 28ede1d commit 1b1df6e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/ottl/contexts/internal/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func accessResourceAttributesKey[K ResourceContext](keys []ottl.Key[K]) ottl.Sta
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetResource().Attributes(), keys, val)
},
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/internal/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func accessInstrumentationScopeAttributesKey[K InstrumentationScopeContext](keys
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetInstrumentationScope().Attributes(), keys, val)
},
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ func accessAttributesKey[K SpanContext](keys []ottl.Key[K]) ottl.StandardGetSett
Setter: func(ctx context.Context, tCtx K, val any) error {
return SetMapValue[K](ctx, tCtx, tCtx.GetSpan().Attributes(), keys, val)
},
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/ottldatapoint/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func accessAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSette
case pmetric.SummaryDataPoint:
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetDataPoint().(pmetric.SummaryDataPoint).Attributes(), key, val)
}
// TODO
return nil
},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/ottllog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ func accessAttributesKey(key []ottl.Key[TransformContext]) ottl.StandardGetSette
Setter: func(ctx context.Context, tCtx TransformContext, val any) error {
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetLogRecord().Attributes(), key, val)
},
// TODO
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ottl/contexts/ottlspanevent/span_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func accessSpanEventAttributesKey(key []ottl.Key[TransformContext]) ottl.Standar
Setter: func(ctx context.Context, tCtx TransformContext, val any) error {
return internal.SetMapValue[TransformContext](ctx, tCtx, tCtx.GetSpanEvent().Attributes(), key, val)
},
// TODO
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/ottl/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func (a *argument) accept(v grammarVisitor) {
// mathExpression, function call, or literal.
type value struct {
IsNil *isNil `parser:"( @'nil'"`
ExpressionPath *path `parser:"| '$''{' @@ '}'"`
Literal *mathExprLiteral `parser:"| @@ (?! OpAddSub | OpMultDiv)"`
MathExpression *mathExpression `parser:"| @@"`
Bytes *byteSlice `parser:"| @Bytes"`
Expand All @@ -260,6 +261,9 @@ func (v *value) accept(vis grammarVisitor) {
i.accept(vis)
}
}
if v.ExpressionPath != nil {
vis.visitPath(v.ExpressionPath)
}
}

// path represents a telemetry path mathExpression.
Expand Down Expand Up @@ -486,6 +490,7 @@ func buildLexer() *lexer.StatefulDefinition {
{Name: `LBrace`, Pattern: `\{`},
{Name: `RBrace`, Pattern: `\}`},
{Name: `Colon`, Pattern: `\:`},
{Name: `Dollar`, Pattern: `\$`},
{Name: `Punct`, Pattern: `[,.\[\]]`},
{Name: `Uppercase`, Pattern: `[A-Z][A-Z0-9_]*`},
{Name: `Lowercase`, Pattern: `[a-z][a-z0-9_]*`},
Expand Down
9 changes: 9 additions & 0 deletions pkg/ottl/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ func Test_lexer(t *testing.T) {
{"String", `"bar"`},
{"RBrace", "}"},
}},
{"Expression path", `${foo["foo"]}`, false, []result{
{"Dollar", "$"},
{"LBrace", "{"},
{"Lowercase", "foo"},
{"Punct", "["},
{"String", `"foo"`},
{"Punct", "]"},
{"RBrace", "}"},
}},
}

for _, tt := range tests {
Expand Down

0 comments on commit 1b1df6e

Please sign in to comment.