Skip to content

[pkg/ottl] Improve slice and maps dynamic indexing validation #37646

Closed as not planned
@edmocosta

Description

@edmocosta

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

We've recently introduced support for indexing maps and slices with dynamic values (#36644), allowing statements to access elements using Int, String, Converter, and Path, which was a great addition to OTTL.

Given slices and maps are indexed using different data types (slices w/ integers, and maps w/ strings), we should improve the OTTL contexts/parser to validate the path's key's types and avoid raising errors at runtime:

ERROR	failed processing logs	{"error": "failed to execute statement: set(attributes[\"test\"], attributes[cache[\"key\"]]), unable to resolve a string index in map: could not resolve key for map/slice, expecting 'string' but got 'int64'"}

Describe the solution you'd like

When users configure statements using invalid key types, for example, slices with string keys, or maps with integer keys, we should raise an error at the collector startup:

log_statements:
 - context: log
   statements:
    - set(cache["key"], 1)
    - set(attributes["test"], attributes[cache["key"]]) # maps indexes must be a string, not int

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions