在 Logstash HTTP 输入中,如何将错误发送给客户端而不是什么都不发送?

In Logstash HTTP input, how can I send the error to the client instead of nothing?

这些是我的 logstash 设置

input {
    http {
        port => 5000
        codec => "json"
    }
}

output {
    elasticsearch {
        hosts => "elasticsearch:9200"
        user => "elastic"
        password => "changeme"
    }
}

如果我这样做 curl -XPUT 'http://127.0.0.1:5000' -d '{"message": "hello"}' 并收到错误,我不会在 CURL 中收到任何反馈。我可以在我的 logstash / elastic stack 控制台中看到错误,但我也想在 curl 中得到它。

Logstash 中的输入和输出阶段是完全断开的,运行 是异步的。

您的 http 输入将始终响应 200 OK,因为您的消息已被接受进行处理。 elasticsearch 输出无法正确索引您的消息这一事实无法传播回输入,因此无法传播到您的 curl 调用。

顺序是这样的:

  1. 您在端口 5000 上调用 curl
  2. http 输入收到您的消息并响应 200 OK -> 此时,你的curl命令returns
  3. http 输入然后通过过滤器和输出管道发送您的消息
  4. elasticsearch输出接收要处理的消息
  5. elasticsearch 输出将消息发送到 Elasticsearch
  6. Elasticseach 抱怨消息并发送 400 错误
  7. elasticsearch 输出在 Logstash 日志中转储该错误

您可以阅读有关 Logstash execution model 的更多信息。