logstash-plugins / logstash-output-influxdb

Apache License 2.0
58 stars 79 forks source link

Setting a database name from event fields doesn't work anymore #71

Open reinhard-brandstaedter opened 7 years ago

reinhard-brandstaedter commented 7 years ago

Hi,

I was using a influxdb output configuration before I switched to 5.x where I configured the database name dynamically from a logstash event field:

output {
file {
    path => "/tmp/%{[project]}.logstash.out2"
}

influxdb {
    host => "influxdb"
    # to use a database that uses the project code
    db => "%{[project]}"
    allow_time_override => true
    measurement => "%{[businesstransaction]}"
    exclude_fields => [ "businesstransaction", "@timestamp", "@version", "sequence", "message", "type", "project", "location"]
    use_event_fields_for_data_points => true
}
}

This used to create a output file with the name of the field and also write to the database. Now with 5.5. and the latest output plugin it seems that doesn't work anymore. The event field is present in the event and should be accessible, however it doesn't get resolved for setting the db property. The filename is still correct. I also tried with another filed (one that doesn't get excluded) - same story.

{"businesstransaction":"SOLR Requests","responseTime":"88.31740897893906","systemProfile":"y_Production","y_number_of_search_results":6.0,"serverName":"ip-192-168-111-200","project":"y_dyn","tags":["application","serverName","systemProfile"],"y_solr_query_invocation":2.0,"@timestamp":"2017-09-08T13:57:27.256Z","application":"B2C","y_solr_query_time":1.0,"time":"1504879047256"}

Not sure if that is a problem of logstash itself or of the output plugin. Logstash reports an error:

[WARN ][logstash.outputs.influxdb] Non recoverable exception while writing to InfluxDB {:exception=>#<InfluxDB::Error: {"error":"database not found: \"%{[project]}\""}

Any clue why this could happen?

reinhard-brandstaedter commented 7 years ago

an here is the bug/reason for that: @db needs to be database in the below code (will create a pull request)

def dowrite(events, database)
begin
    @influxdbClient.write_points(events, @time_precision, @retention_policy, **@db**  )
rescue InfluxDB::AuthenticationError => ae
    @logger.warn("Authentication Error while writing to InfluxDB", :exception => ae)
rescue InfluxDB::ConnectionError => ce
    @logger.warn("Connection Error while writing to InfluxDB", :exception => ce)
rescue Exception => e
    @logger.warn("Non recoverable exception while writing to InfluxDB", :exception => e)
end
end
TheVastyDeep commented 2 years ago

See also #79 and #82.