magnusbaeck / logstash-filter-verifier

Apache License 2.0
191 stars 27 forks source link

Testing input plugins that output multiple fields #128

Closed jgough closed 2 years ago

jgough commented 2 years ago

In the v2 beta daemon mode, what is the preferred way of testing input plugins that output multiple fields and don't need a codec?

For example, the jdbc input produces fields containing values output from the query statement specified:

    jdbc {
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        jdbc_connection_string => "jdbc:mysql://host1:33060/blah"
        jdbc_user => "username"
        jdbc_password => "password"
        jdbc_driver_library => "/usr/share/java/mysql-connector-java.jar"
        id => "jdbc_input"
        schedule => "*/10 * * * *"
        statement => "SELECT 'foo' AS test1, 'bar' AS test2"
    }

Should output an event with fields

"test1": "foo"
"test2": "bar"

What is the best way of testing this?

Previously in v1 I would have tested this with the following:

codec: "json_lines"
testcases:
  - input:
      - >
        {
          "test1": "foo",
          "test2": "bar"
        }
...

Since codec is not an option in daemon mode then how would you recommend testing this? If I do:

input_plugin: "jdbc_input"
testcases:
  - input:
      - >
        {
          "test1": "foo",
          "test2": "bar"
        }
...

Then the string just comes as a JSON string inside the message field. Any suggestions? I can't think of any tidy way of doing this.

breml commented 2 years ago

@jgough I think what you are looking for is the fields object. For an example have a look at https://github.com/magnusbaeck/logstash-filter-verifier/blob/master/testdata/testcases/testcases_event/testcases.json respectively the new version of this file in my most recent PR https://github.com/magnusbaeck/logstash-filter-verifier/blob/a0b728bf8f8c7ce4407ed0ba2ea40add6463377d/testdata/testcases/testcases_event/testcases.json

Does this solve your problem?

jgough commented 2 years ago

Looks indeed that with https://github.com/magnusbaeck/logstash-filter-verifier/pull/129 that I can probably now use the fields object as several of the plugins I need to use (s3, dead_letter_queue) output data nested under @metadata. Thanks!