From 1e0fa788b42158ba7f7f1cf1d1e49a597c9f68df Mon Sep 17 00:00:00 2001 From: Joseph Sirianni Date: Fri, 4 Feb 2022 10:06:30 -0500 Subject: [PATCH] resolve an issue where cmd/stanza package tests are pointing to an invalid examples directory (#538) --- cmd/stanza/example_test.go | 8 +-- .../testdata/simple_plugins/config.yaml | 13 +++++ .../simple_plugins/plugins/decorator.yaml | 29 ++++++++++ .../simple_plugins/plugins/repeater.yaml | 15 +++++ cmd/stanza/testdata/tomcat/access.log | 7 +++ cmd/stanza/testdata/tomcat/config.yaml | 57 +++++++++++++++++++ 6 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 cmd/stanza/testdata/simple_plugins/config.yaml create mode 100644 cmd/stanza/testdata/simple_plugins/plugins/decorator.yaml create mode 100644 cmd/stanza/testdata/simple_plugins/plugins/repeater.yaml create mode 100644 cmd/stanza/testdata/tomcat/access.log create mode 100644 cmd/stanza/testdata/tomcat/config.yaml diff --git a/cmd/stanza/example_test.go b/cmd/stanza/example_test.go index d7f32a3fa..4297b6097 100644 --- a/cmd/stanza/example_test.go +++ b/cmd/stanza/example_test.go @@ -35,10 +35,10 @@ func TestTomcatExample(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("Skipping on windows because of service failures") } - err := os.Chdir("../../examples/tomcat") + err := os.Chdir("testdata/tomcat") require.NoError(t, err) defer func() { - err := os.Chdir("../../cmd/stanza") + err := os.Chdir("../../../../cmd/stanza") require.NoError(t, err) }() @@ -87,10 +87,10 @@ func TestSimplePluginsExample(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("Skipping on windows because of service failures") } - err := os.Chdir("../../examples/simple_plugins") + err := os.Chdir("testdata/simple_plugins") require.NoError(t, err) defer func() { - err := os.Chdir("../../cmd/stanza") + err := os.Chdir("../../../../cmd/stanza") require.NoError(t, err) }() diff --git a/cmd/stanza/testdata/simple_plugins/config.yaml b/cmd/stanza/testdata/simple_plugins/config.yaml new file mode 100644 index 000000000..f4393d589 --- /dev/null +++ b/cmd/stanza/testdata/simple_plugins/config.yaml @@ -0,0 +1,13 @@ +# This example configuration uses two plugins that are defined +# in the ./plugins directory. See those files for details +pipeline: + # repeater is a plugin defined by ./plugins/repeater.yaml + - type: repeater + + # decorator is a plugin defined by ./plugins/decorator.yaml + # It adds the label "decorated" to each entry that passes through + # it with the value specified here + - type: decorator + value: my_decorated_value + + - type: stdout diff --git a/cmd/stanza/testdata/simple_plugins/plugins/decorator.yaml b/cmd/stanza/testdata/simple_plugins/plugins/decorator.yaml new file mode 100644 index 000000000..a9c82a29d --- /dev/null +++ b/cmd/stanza/testdata/simple_plugins/plugins/decorator.yaml @@ -0,0 +1,29 @@ +version: 0.0.0 +title: Decorator +description: A decorator plugin +parameters: + - name: value + label: Value + description: A value to decorate the entries + type: string + required: true + +# This plugin is registered as the type 'decorator'. +# The type comes from the filename. +# It take any entries sent to it, and add the label +# 'decorated' to those entries with a value specified +# by the argument 'value' in the top-level pipeline +pipeline: + # The input parameter is replaced with the ID of the + # operator in the top-level config so that the plugin + # graph can be connected properly. + - id: {{ .input }} + type: metadata + labels: + # The value parameter comes from the configuration + # of the plugin in the top-level config + decorated: {{ .value }} + # The output is parameterized with go templates + # so that it can use the output that is configured for the + # plugin in the top-level pipeline + output: {{ .output }} diff --git a/cmd/stanza/testdata/simple_plugins/plugins/repeater.yaml b/cmd/stanza/testdata/simple_plugins/plugins/repeater.yaml new file mode 100644 index 000000000..5da733007 --- /dev/null +++ b/cmd/stanza/testdata/simple_plugins/plugins/repeater.yaml @@ -0,0 +1,15 @@ +# This plugin is registered as the type 'repeater'. +# The type comes from the filename. +# It will generate exactly 5 entries with the same +# timestamp and the content "test record" +pipeline: + - type: generate_input + static: true + entry: + timestamp: "2006-01-02T15:04:05Z" + record: "test record" + count: 5 + # The output is parameterized with go templates + # so that it can use the output that is configured for the + # plugin in the top-level pipeline + output: {{ .output }} diff --git a/cmd/stanza/testdata/tomcat/access.log b/cmd/stanza/testdata/tomcat/access.log new file mode 100644 index 000000000..687948c39 --- /dev/null +++ b/cmd/stanza/testdata/tomcat/access.log @@ -0,0 +1,7 @@ +10.66.2.46 - - [13/Mar/2019:10:43:00 -0400] "GET / HTTP/1.1" 404 - +10.66.2.46 - - [13/Mar/2019:10:43:01 -0400] "GET /favicon.ico HTTP/1.1" 404 - +10.66.2.46 - - [13/Mar/2019:10:43:08 -0400] "GET /manager HTTP/1.1" 302 - +10.66.2.46 - - [13/Mar/2019:10:43:08 -0400] "GET /manager/ HTTP/1.1" 403 3420 +10.66.2.46 - - [13/Mar/2019:11:00:26 -0400] "GET /manager/html HTTP/1.1" 401 2473 +10.66.2.46 - tomcat [13/Mar/2019:11:00:53 -0400] "GET /manager/html HTTP/1.1" 200 11936 +10.66.2.46 - - [13/Mar/2019:11:00:53 -0400] "GET /manager/images/asf-logo.svg HTTP/1.1" 200 19698 diff --git a/cmd/stanza/testdata/tomcat/config.yaml b/cmd/stanza/testdata/tomcat/config.yaml new file mode 100644 index 000000000..1ff45dadb --- /dev/null +++ b/cmd/stanza/testdata/tomcat/config.yaml @@ -0,0 +1,57 @@ +--- +pipeline: + + # Read lines from Apache Tomcat access logs + # Example input line: + # 10.66.2.46 - - [13/Mar/2019:10:43:00 -0400] "GET / HTTP/1.1" 404 - + - type: file_input + start_at: beginning + include: + - ./access.log + labels: + log_type: tomcat + + # Parse the logs into labeled fields + # Example input: + # { + # "timestamp": "2020-06-13T11:00:53-04:00", + # "record": "10.66.2.46 - - [13/Mar/2019:10:43:00 -0400] "GET / HTTP/1.1" 404 -" + # } + - type: regex_parser + regex: >- + (?P[^\s]+) + - + (?P[^\s]+) + \[(?P[^\]]+)\] + "(?P[A-Z]+) + (?P[^\s]+)[^"]*" + (?P\d+) + (?P[\d-]+) + timestamp: + parse_from: timestamp + layout: '%d/%b/%Y:%H:%M:%S %z' + severity: + parse_from: http_status + preserve_to: http_status + mapping: + error: "4xx" + info: + - min: 300 + max: 399 + debug: 200 + + # Write the log to stdout + # Example input: + # { + # "timestamp": "2019-03-13T11:00:53-04:00", + # "severity": 60, + # "record": { + # "bytes_sent": "19698", + # "http_method": "GET", + # "http_status": "200", + # "remote_host": "10.66.2.46", + # "remote_user": "-", + # "url_path": "/manager/images/asf-logo.svg" + # } + # } + - type: stdout