Skip to content

OTTL doesn't correctly handle unary signs or certain floating point formats #45222

@kentquirk

Description

@kentquirk

Component(s)

pkg/ottl

What happened?

Description

I'm trying to write an OTTL plugin for syntax coloring. I needed to write an OTTL grammar, and while doing so I realized there are bugs in OTTL's handling of numeric expressions.

In particular, the OTTL math expression parser did not correctly handle unary signs for plus
and minus. Expressions like "3-5" would not parse correctly. Additionally,
floating point constants that had a decimal point but no fractional digits
(e.g., "3.") were not handled properly and could crash the parser.

Steps to Reproduce

Add this test to Test_lexer in lexer_test.go and run the test. It will fail because "-5" is parsed as a single integer value, but it should not be in this case -- greedy evaluation is generating two ints with no operator.

		{"Math Equation nospace", `3-5`, false, []result{
			{"Int", "3"},
			{typ: "OpAddSub", val: "-"},
			{"Int", "5"},
		}},

A different test is to attempt to parse the value 3. (without trailing digits). It returns an integer 3 and then errors trying to parse the decimal point.

I'm going to submit a PR to fix these issues.

Collector version

v0.142.0

Environment information

Environment

OS: OSX
Compiler(if manually compiled): go 1.25.3

OpenTelemetry Collector configuration

Log output

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpkg/ottl

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions