Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating package-spec dependency #260

Merged
merged 12 commits into from
Feb 25, 2021
33 changes: 13 additions & 20 deletions docs/howto/pipeline_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,19 @@ The input events contain mocked JSON events that are ready to be passed to the i

#### Test configuration

Before sending log events to the ingest pipeline, a data transformation process is applied. The process can be customized using an optional configuration stored as JSON file with the suffix `-config.json` (e.g. `test-access-sample.log-config.json`):

```json
{
"multiline": {
"first_line_pattern": "^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}"
},
"fields": {
"@timestamp": "2020-04-28T11:07:58.223Z",
"ecs": {
"version": "1.5.0"
},
"event.category": [
"web"
]
},
"dynamic_fields": {
"url.original": "^/.*$"
}
}
Before sending log events to the ingest pipeline, a data transformation process is applied. The process can be customized using an optional configuration stored as a YAML file with the suffix `-config.yml` (e.g. `test-access-sample.log-config.yml`):

```yml
multiline:
first_line_pattern: "^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}"
fields:
"@timestamp": "2020-04-28T11:07:58.223Z"
ecs:
version: "1.5.0"
event.category:
- "web"
dynamic_fields:
url.original: "^/.*$"
```

The `multiline` section ([raw files](#raw-files) only) configures the log file reader to correctly detect multiline log entries using the `first_line_pattern`. Use this property if your logs may be split into multiple lines, e.g. Java stack traces.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/elastic/go-elasticsearch/v7 v7.9.0
github.com/elastic/go-licenser v0.3.1
github.com/elastic/go-ucfg v0.8.3
github.com/elastic/package-spec/code/go v0.0.0-20210210152225-3f48d5aaa17e
github.com/elastic/package-spec/code/go v0.0.0-20210222225810-541116689fca
github.com/go-git/go-billy/v5 v5.0.0
github.com/go-git/go-git/v5 v5.1.0
github.com/go-openapi/strfmt v0.19.6 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ github.com/elastic/go-licenser v0.3.1 h1:RmRukU/JUmts+rpexAw0Fvt2ly7VVu6mw8z4HrE
github.com/elastic/go-licenser v0.3.1/go.mod h1:D8eNQk70FOCVBl3smCGQt/lv7meBeQno2eI1S5apiHQ=
github.com/elastic/go-ucfg v0.8.3 h1:leywnFjzr2QneZZWhE6uWd+QN/UpP0sdJRHYyuFvkeo=
github.com/elastic/go-ucfg v0.8.3/go.mod h1:iaiY0NBIYeasNgycLyTvhJftQlQEUO2hpF+FX0JKxzo=
github.com/elastic/package-spec/code/go v0.0.0-20210210152225-3f48d5aaa17e h1:kL1ypDLbxsEyPxkjmvccMau5Ap5s3yMk4qDO3xlbEos=
github.com/elastic/package-spec/code/go v0.0.0-20210210152225-3f48d5aaa17e/go.mod h1:dog1l3e8NoRYxuB8yIbbOWglE6GSQuU6ZL75wT9pKL8=
github.com/elastic/package-spec/code/go v0.0.0-20210222225810-541116689fca h1:dEAP2TACrsICd/pMzFlEx2llqqWcB68CjJRfnMhQL8E=
github.com/elastic/package-spec/code/go v0.0.0-20210222225810-541116689fca/go.mod h1:dog1l3e8NoRYxuB8yIbbOWglE6GSQuU6ZL75wT9pKL8=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
4 changes: 3 additions & 1 deletion internal/testrunner/runners/pipeline/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ func (r *runner) listTestCaseFiles() ([]string, error) {

var files []string
for _, fi := range fis {
if strings.HasSuffix(fi.Name(), expectedTestResultSuffix) || strings.HasSuffix(fi.Name(), configTestSuffix) {
if strings.HasSuffix(fi.Name(), expectedTestResultSuffix) ||
strings.HasSuffix(fi.Name(), configTestSuffixJSON) ||
strings.HasSuffix(fi.Name(), configTestSuffixYAML) {
continue
}
files = append(files, fi.Name())
Expand Down
42 changes: 30 additions & 12 deletions internal/testrunner/runners/pipeline/test_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,68 @@ import (
"os"
"path/filepath"

"gopkg.in/yaml.v3"

"github.com/pkg/errors"

"github.com/elastic/elastic-package/internal/testrunner"
)

const configTestSuffix = "-config.json"
const (
configTestSuffixJSON = "-config.json"
configTestSuffixYAML = "-config.yml"
)

type testConfig struct {
testrunner.SkippableConfig `config:",inline"`

Multiline *multiline `json:"multiline"`
Fields map[string]interface{} `json:"fields"`
DynamicFields map[string]string `json:"dynamic_fields"`
Multiline *multiline `json:"multiline" yaml:"multiline"`
Fields map[string]interface{} `json:"fields" yaml:"fields"`
DynamicFields map[string]string `json:"dynamic_fields" yaml:"dynamic_fields"`

// NumericKeywordFields holds a list of fields that have keyword
// type but can be ingested as numeric type.
NumericKeywordFields []string `json:"numeric_keyword_fields"`
}

type multiline struct {
FirstLinePattern string `json:"first_line_pattern"`
FirstLinePattern string `json:"first_line_pattern" yaml:"first_line_pattern"`
}

func readConfigForTestCase(testCasePath string) (testConfig, error) {
testCaseDir := filepath.Dir(testCasePath)
testCaseFile := filepath.Base(testCasePath)

var c testConfig
configData, err := ioutil.ReadFile(filepath.Join(testCaseDir, expectedTestConfigFile(testCaseFile)))
configData, err := ioutil.ReadFile(filepath.Join(testCaseDir, expectedTestConfigFile(testCaseFile, configTestSuffixYAML)))
if err != nil && !os.IsNotExist(err) {
return c, errors.Wrapf(err, "reading test config file failed (path: %s)", testCasePath)
return c, errors.Wrapf(err, "reading YAML-formatted test config file failed (path: %s)", testCasePath)
}

if configData == nil {
if configData != nil {
if err := yaml.Unmarshal(configData, &c); err != nil {
return c, errors.Wrap(err, "unmarshalling YAML-formatted test config failed")
}

return c, nil
}

err = json.Unmarshal(configData, &c)
if err != nil {
return c, errors.Wrap(err, "unmarshalling test config failed")
configData, err = ioutil.ReadFile(filepath.Join(testCaseDir, expectedTestConfigFile(testCaseFile, configTestSuffixJSON)))
if err != nil && !os.IsNotExist(err) {
return c, errors.Wrapf(err, "reading JSON-formatted test config file failed (path: %s)", testCasePath)
}

if configData != nil {
if err := json.Unmarshal(configData, &c); err != nil {
return c, errors.Wrap(err, "unmarshalling JSON-formatted test config failed")
}

return c, nil
}

return c, nil
}

func expectedTestConfigFile(testFile string) string {
func expectedTestConfigFile(testFile, configTestSuffix string) string {
return fmt.Sprintf("%s%s", testFile, configTestSuffix)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dynamic_fields:
event.ingested: ".*"

This file was deleted.

Loading