You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Logstash 6.2.2中Ruby过滤器配置初始化常量失败问题

Hey there, let's work through this Logstash Ruby filter issue you're hitting—those cryptic constant errors are always frustrating, especially when you've already stripped down your config!

First, let's start with a rock-solid minimal Ruby filter configuration that should pass logstash.bat -t without issues in 6.2.2. Use this as a baseline to verify your setup:

input {
  stdin {}
}

filter {
  ruby {
    code => "event.set('new_field', 'success from ruby filter')"
  }
}

output {
  stdout { codec => rubydebug }
}

Run logstash.bat -t with this config—if it passes, that means your core Logstash installation is working, and the problem lies in your original Ruby code or config structure.

Now, let's break down the common causes of that uninitialized constant error and how to fix them:

  • Invalid Ruby code referencing non-existent constants: That error message points to a missing ConfigurationError constant in the Logstash Ruby context. If your code tries to use raise ConfigurationError or reference that constant directly, it won't exist here. Instead, use plain string error messages if you need to raise issues:

    # Bad: raises missing constant error
    # raise ConfigurationError, "Invalid data"
    
    # Good: works in Logstash's Ruby environment
    raise "Invalid data detected in event"
    
  • Incorrect quote escaping in the code parameter: If your Ruby code uses double quotes, wrap the entire code value in single quotes (or vice versa) to avoid syntax parsing issues. For example:

    # Correct: outer single quotes, inner double quotes
    ruby {
      code => 'event.set("message", event.get("message").upcase)'
    }
    
    # Also correct: outer double quotes, escaped inner double quotes
    ruby {
      code => "event.set(\"message\", event.get(\"message\").upcase)"
    }
    
  • Missing or malformed config blocks: Logstash requires all configs to have input, filter, and output sections. Even if you're just testing the filter, don't skip the other blocks—partial configs can trigger unexpected parsing errors like the one you're seeing.

  • Using deprecated event manipulation methods: In 6.x versions, the recommended way to interact with events is event.set() and event.get(). Avoid using the older event['field'] syntax, as it can sometimes cause context issues with Logstash's internal compiler.

If the minimal config still fails even on a fresh 6.2.2 install, double-check that you're running the command from the correct directory (the Logstash bin folder) and that there are no stray characters or syntax errors in your config file (like missing curly braces, commas, or mismatched quotes).

Once you get the minimal config working, gradually add back your custom Ruby logic, testing with logstash.bat -t after each change to pinpoint exactly which line is causing the error.

内容的提问来源于stack exchange,提问作者Andrew Wynham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:29:20