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

Add support for multiple inputs per dataset #346

Merged
merged 7 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add `all` query param to return all packages. By default is set false. [#301](https://github.com/elastic/integrations-registry/pull/301)
* Add `multiple` config for datasource. By default true. [#361](https://github.com/elastic/integrations-registry/pull/361)
* Add `removable` flag to package manifest. Default is true. [#359](https://github.com/elastic/integrations-registry/pull/359)
* Add stream template to package json. [#335](https://github.com/elastic/integrations-registry/pull/335)
* Add support for multiple inputs per dataset. [#346](https://github.com/elastic/integrations-registry/pull/346)

### Deprecated

Expand Down
4 changes: 4 additions & 0 deletions dev/packages/example/nginx-1.2.0/dataset/error/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ streams:
- input: logs
title: Nginx error logs
description: Collecting the Nginx error logs from file.
# Name of the stream file
template_path: stream.yml
vars:
- name: paths
required: true
Expand All @@ -23,6 +25,8 @@ streams:
- input: syslog
title: Nginx error logs
description: Collecting the Nginx error logs from syslog.
# Name of the stream file
template_path: syslog.yml
vars:
# Are udp and tcp syslog input two different inputs?
- name: protocol.udp.host
Expand Down
1 change: 1 addition & 0 deletions docs/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
}
],
"dataset": "bar",
"template_path": "stream.yml",
"template": "foo: bar\n"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
syslog: bar
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ streams:
- input: logs
title: Title of the stream
description: Description of the stream with more details.
template_path: logs.yml
vars:
- name: paths
required: true
Expand All @@ -21,3 +22,8 @@ streams:
os.windows:
default:
- c:/programdata/nginx/logs/*error.log*

- input: syslog
title: Title of the stream
description: Description of the stream with more details.
template_path: syslog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
syslog: bar
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ streams:
- input: logs
title: Title of the stream
description: Description of the stream with more details.
template_path: logs.yml
vars:
- name: paths
required: true
Expand All @@ -21,3 +22,8 @@ streams:
os.windows:
default:
- c:/programdata/nginx/logs/*error.log*

- input: syslog
title: Title of the stream
description: Description of the stream with more details.
template_path: syslog.yml
25 changes: 23 additions & 2 deletions testdata/public/package/datasources/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"/package/datasources/1.0.0/dataset/examplelog1/fields/stream.yml",
"/package/datasources/1.0.0/dataset/examplelog2/fields/stream.yml",
"/package/datasources/1.0.0/dataset/examplemetric/fields/stream.yml",
"/package/datasources/1.0.0/dataset/examplelog1/agent/stream/stream.yml",
"/package/datasources/1.0.0/dataset/examplelog1/agent/stream/logs.yml",
"/package/datasources/1.0.0/dataset/examplelog1/agent/stream/syslog.yml",
"/package/datasources/1.0.0/dataset/examplelog2/agent/stream/stream.yml",
"/package/datasources/1.0.0/dataset/examplemetric/agent/stream/stream.yml"
],
Expand Down Expand Up @@ -62,6 +63,13 @@
}
}
],
"template_path": "logs.yml",
"title": "Title of the stream",
"description": "Description of the stream with more details."
},
{
"input": "syslog",
"template_path": "syslog.yml",
"title": "Title of the stream",
"description": "Description of the stream with more details."
}
Expand Down Expand Up @@ -196,6 +204,7 @@
}
],
"dataset": "datasources.examplemetric",
"template_path": "stream.yml",
"template": "metric: foo\n",
"title": "Title of the stream",
"description": "Description of the stream with more details."
Expand Down Expand Up @@ -234,6 +243,7 @@
}
],
"dataset": "datasources.examplelog1",
"template_path": "logs.yml",
"template": "foo: bar\n",
"title": "Title of the stream",
"description": "Description of the stream with more details."
Expand Down Expand Up @@ -266,14 +276,25 @@
}
],
"dataset": "datasources.examplelog2",
"template_path": "stream.yml",
"template": "foo: bar\n",
"title": "Title of the stream",
"description": "Description of the stream with more details."
}
]
},
{
"type": "syslog"
"type": "syslog",
"streams": [
{
"input": "syslog",
"dataset": "datasources.examplelog1",
"template_path": "syslog.yml",
"template": "syslog: bar\n",
"title": "Title of the stream",
"description": "Description of the stream with more details."
}
]
}
],
"multiple": true
Expand Down
1 change: 1 addition & 0 deletions testdata/public/package/default-pipeline/0.0.2/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
}
],
"dataset": "default-pipeline.foo",
"template_path": "stream.yml",
"template": "foo: bar\n"
}
]
Expand Down
1 change: 1 addition & 0 deletions testdata/public/package/example/1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
}
],
"dataset": "bar",
"template_path": "stream.yml",
"template": "foo: bar\n"
}
]
Expand Down
1 change: 1 addition & 0 deletions testdata/public/package/multiple-false/0.0.1/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
}
],
"dataset": "multiple-false.foo",
"template_path": "stream.yml",
"template": "foo: bar\n"
}
]
Expand Down
14 changes: 8 additions & 6 deletions util/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ type Input struct {
}

type Stream struct {
Input string `config:"input" json:"input" validate:"required"`
Vars []Variable `config:"vars" json:"vars,omitempty" yaml:"vars,omitempty"`
Dataset string `config:"dataset" json:"dataset,omitempty" yaml:"dataset,omitempty"`
Template string `config:"template" json:"template,omitempty" yaml:"template,omitempty"`
Title string `config:"title" json:"title,omitempty" yaml:"title,omitempty"`
Description string `config:"description" json:"description,omitempty" yaml:"description,omitempty"`
Input string `config:"input" json:"input" validate:"required"`
Vars []Variable `config:"vars" json:"vars,omitempty" yaml:"vars,omitempty"`
Dataset string `config:"dataset" json:"dataset,omitempty" yaml:"dataset,omitempty"`
// TODO: This might cause issues when consuming the json as the key contains . (had been an issue in the past if I remember correctly)
TemplatePath string `config:"template_path" json:"template_path,omitempty" yaml:"template-path,omitempty"`
TemplateContent string `json:"template,omitempty"` // This is always generated in the json output
Title string `config:"title" json:"title,omitempty" yaml:"title,omitempty"`
Description string `config:"description" json:"description,omitempty" yaml:"description,omitempty"`
}

type Variable struct {
Expand Down
8 changes: 5 additions & 3 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,20 @@ func (p *Package) LoadDataSets(packagePath string) error {
for iK, _ := range datasource.Inputs {
for _, stream := range d.Streams {
if stream.Input == p.Datasources[dK].Inputs[iK].Type {
if stream.TemplatePath == "" {
stream.TemplatePath = "stream.yml"
}
stream.Dataset = d.ID
streamTemplate := filepath.Join(datasetBasePath, "agent", "stream", "stream.yml")
streamTemplate := filepath.Join(datasetBasePath, "agent", "stream", stream.TemplatePath)

streamTemplateData, err := ioutil.ReadFile(streamTemplate)
if err != nil {
return err
}

stream.Template = string(streamTemplateData)
stream.TemplateContent = string(streamTemplateData)

// Add template to stream

p.Datasources[dK].Inputs[iK].Streams = append(p.Datasources[dK].Inputs[iK].Streams, stream)
}
}
Expand Down