open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
3.08k stars 2.37k forks source link

statement are not executed in order #34860

Open newly12 opened 2 months ago

newly12 commented 2 months ago

Component(s)

processor/routing

Describe the issue you're reporting

Not quite sure if this is by design or a bug, this behavior is not documented and sort of surprise to me.

Here is an issue I encountered, given this routing processor config.

          - statement: route() where resource.attributes["__otel_enabled__"] == nil
            exporters: [otlp]
          - statement: delete_key(resource.attributes, "__otel_enabled__") where resource.attributes["__otel_enabled__"] == true
            exporters: [otlp]
          - statement: delete_key(resource.attributes, "__otel_enabled__") where resource.attributes["__otel_enabled__"] == false
            exporters: [nop]

the flag __otel_enabled__ could have 3 values

  1. not defined
  2. true
  3. false

the goal is that when the flag __otel_enabled__ is explicitly set to false, route it to nop exporter.

However statements are execute in random order(range through map), given data has __otel_enabled__ set to false, when 3rd one is executed before 1st one, both statements match, when 1st one is executed before 3rd one, only first statement matches.

github-actions[bot] commented 2 months ago

Pinging code owners:

jpkrohling commented 2 months ago

@djaglowski, how is this handled in other components?

iblancasa commented 2 months ago

In the case of the route connector it uses a slice so I would say it is more deterministic. Maybe we can port that behavior to the processor.

djaglowski commented 2 months ago

I agree this should be deterministic. Since the configuration starts with a slice, I believe order was always intended. The fact that it's ranging over map should be considered a bug IMO.

Frapschen commented 2 months ago

I will try to fix it

github-actions[bot] commented 1 week ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.