Skip to content

Commit

Permalink
Add a way to select the stream under test in system test runner (#187)
Browse files Browse the repository at this point in the history
This provides a means to select a stream to test by input type.

Closes #186
  • Loading branch information
andrewkroh authored Dec 1, 2020
1 parent 9647620 commit 4a022f5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion docs/howto/system_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ Next, we must define configuration for each data stream that we want to system t
config.yml
```

The `config.yml` file allows you define values for package and data stream-level variables. For example, the `apache/access` data stream's `config.yml` is shown below.
The `config.yml` file allows you to define values for package and data stream-level variables. For example, the `apache/access` data stream's `config.yml` is shown below.

```
vars: ~
input: logfile
data_stream:
vars:
paths:
Expand All @@ -91,6 +92,11 @@ The `data_stream.vars` field corresponds to data stream-level variables for the

Notice the use of the `{{SERVICE_LOGS_DIR}}` placeholder. This corresponds to the `${SERVICE_LOGS_DIR}` variable we saw in the `docker-compose.yml` file earlier. In the above example, the net effect is as if the `/usr/local/apache2/logs/access.log*` files located inside the Apache integration service container become available at the same path from Elastic Agent's perspective.

When a data stream's manifest declares multiple streams with different inputs
you can use the `input` option to select the stream to test. The first stream
whose input type matches the `input` value will be tested. By default, the first
stream declared in the manifest will be tested.

#### Placeholders

The `SERVICE_LOGS_DIR` placeholder is not the only one available for use in a data stream's `config.yml` file. The complete list of available placeholders is shown below.
Expand Down
16 changes: 14 additions & 2 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ func createPackageDatastream(
ds packages.DataStreamManifest,
c testConfig,
) ingestmanager.PackageDataStream {
streamInput := ds.Streams[0].Input
stream := ds.Streams[getDataStreamIndex(c.Input, ds)]
streamInput := stream.Input
r := ingestmanager.PackageDataStream{
Name: fmt.Sprintf("%s-%s", pkg.Name, ds.Name),
Namespace: "ep",
Expand Down Expand Up @@ -386,7 +387,7 @@ func createPackageDatastream(

// Add dataStream-level vars
dsVars := ingestmanager.Vars{}
for _, dsVar := range ds.Streams[0].Vars {
for _, dsVar := range stream.Vars {
val := dsVar.Default

cfgVar, exists := c.DataStream.Vars[dsVar.Name]
Expand Down Expand Up @@ -427,6 +428,17 @@ func createPackageDatastream(
return r
}

// getDataStreamIndex returns the index of the data stream whose input name
// matches. Otherwise it returns the 0.
func getDataStreamIndex(inputName string, ds packages.DataStreamManifest) int {
for i, s := range ds.Streams {
if s.Input == inputName {
return i
}
}
return 0
}

func deleteDataStreamDocs(esClient *es.Client, dataStream string) error {
body := strings.NewReader(`{ "query": { "match_all": {} } }`)
_, err := esClient.DeleteByQuery([]string{dataStream}, body)
Expand Down
1 change: 1 addition & 0 deletions internal/testrunner/runners/system/test_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
const configFileName = "config.yml"

type testConfig struct {
Input string `config:"input"`
Vars map[string]packages.VarValue `config:"vars"`
DataStream struct {
Vars map[string]packages.VarValue `config:"vars"`
Expand Down

0 comments on commit 4a022f5

Please sign in to comment.