Logstash: access name of current pipeline within cfg?

Is it possible to access the name of the current pipeline within cfg?

For example, my pipelines.yml might contain:

- pipeline.id: pipeline.triage
  path.config: "/etc/logstash/pipelines/pipeline.triage.conf"
- pipeline.id: pipeline.fallback
  path.config: "/etc/logstash/pipelines/pipeline.fallback.conf"

Within pipeline.triage.conf, I want to have something like:

  mutate {
    add_field => { "[pipeline][history]" => "%{[_pipeline]}" ]
  }

Goal: I would like [pipeline][history] to end up with a literal value of pipeline.fallback, but without having to hardcode that value in the config.

I hoped that Accessing Event Data and Fields in the Configuration might contain a hint, but if it's there, I couldn't see it.

Hello,
At the moment it's not possible to have the name of the pipeline from the [@metadata] fields, but you can get them via Ruby using:

ruby { code => "event.set(\"pipeline_id\", execution_context.pipeline.pipeline_id)" }

Please note this will trigger an error if you're not using multiple pipelines.

Hope it helps!

Best regards,
Luca

Very useful. Thank you @Luca_Belluccini.

Is there some documentation which covers execution_context and its attributes? I did have a look, but couldn't find it.

I agree it's missing from the documentation, but probably because this is a non-public attribute which is passed to all plugins (inputs, filters, outputs - see here). It is subject to change without notice.

We could raise an issue to check if this is expected to be public or not in the future.