elastic / elastic/logstash

Conditions in input section are ignored

Open
#6,080 6 comments 1 reaction 0 assignees View on GitHub
discuss enhancement
Dominant language
Java
Stars
14.9k
Forks
3.5k
Avg merge
19h 14m
Merged PRs (30d)
63

Description

I was trying to work with environment variables in my logstash config. Basicly, I would like to place `if`s with environment variables around my redis input. Reading #5115, I understand that it's not possible at the moment.

However, there is a strange behaviour in the `input` section: Conditions seem to be ignored all together.

The following config/command line illustrates the problem:

```
input {
if "a" == "b" {
stdin{}
}
}

output {
stdout{}
}
```

```
$ echo 'foo' | docker run -i --rm logstash:2.4 -e 'input{ if "a" == "b" {stdin{}}} output{stdout{}}'
{:timestamp=>"2016-10-18T09:24:40.559000+0000", :message=>"Pipeline main started"}
2016-10-18T09:24:40.544Z 4bb236b25ce5 foo
{:timestamp=>"2016-10-18T09:24:40.681000+0000", :message=>"Pipeline main has been shutdown"}
```

As the condition `"a" == "b"` around `stdin{}` should always be false, I would expect that no input on `stdin` is expected. However, the event `foo` is accepted and processed.

On the other hand, the same condition works on `output` directives (and filters, too):

```
input {
stdin{}
}

output {
if "a" == "b" {
stdout{}
}
}
```

```
$ echo 'foo' | docker run -i --rm logstash:2.4 -e 'input{stdin{}} output{if "a" == "b"{stdout{}}}'
{:timestamp=>"2016-10-18T09:28:57.491000+0000", :message=>"Pipeline main started"}
{:timestamp=>"2016-10-18T09:28:57.622000+0000", :message=>"Pipeline main has been shutdown"}
```

Here, as expected, no output is made.

In general, I would expect conditions to work the same way throughout the config. If some operands are not supported in the input stage (e.g. because no event-data is present yet), the conditions should either evaluate according to nil comparisons, or a syntax error should be thrown for conditions in the `input` section.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.