Skip to content

Commit

Permalink
resolve an issue where cmd/stanza package tests are pointing to an in…
Browse files Browse the repository at this point in the history
…valid examples directory (#538)
  • Loading branch information
Joseph Sirianni authored Feb 4, 2022
1 parent 7065476 commit 1e0fa78
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/stanza/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()

Expand Down Expand Up @@ -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)
}()

Expand Down
13 changes: 13 additions & 0 deletions cmd/stanza/testdata/simple_plugins/config.yaml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions cmd/stanza/testdata/simple_plugins/plugins/decorator.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
15 changes: 15 additions & 0 deletions cmd/stanza/testdata/simple_plugins/plugins/repeater.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
7 changes: 7 additions & 0 deletions cmd/stanza/testdata/tomcat/access.log
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions cmd/stanza/testdata/tomcat/config.yaml
Original file line number Diff line number Diff line change
@@ -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<remote_host>[^\s]+)
-
(?P<remote_user>[^\s]+)
\[(?P<timestamp>[^\]]+)\]
"(?P<http_method>[A-Z]+)
(?P<url_path>[^\s]+)[^"]*"
(?P<http_status>\d+)
(?P<bytes_sent>[\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

0 comments on commit 1e0fa78

Please sign in to comment.