-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to pass inlined pipeline stages to the docker driver. (#2076)
* Allows to pass inlined pipeline stages to the docker driver. Fixes #1296 Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * doc. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
- Loading branch information
1 parent
9803eab
commit c2f100c
Showing
4 changed files
with
190 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/cortexproject/cortex/pkg/util" | ||
"github.com/docker/docker/daemon/logger" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/grafana/loki/pkg/logentry/stages" | ||
) | ||
|
||
var pipelineString = ` | ||
- regex: | ||
expression: '(level|lvl|severity)=(?P<level>\w+)' | ||
- labels: | ||
level: | ||
` | ||
var pipeline = PipelineConfig{ | ||
PipelineStages: []interface{}{ | ||
map[interface{}]interface{}{ | ||
"regex": map[interface{}]interface{}{ | ||
"expression": "(level|lvl|severity)=(?P<level>\\w+)", | ||
}, | ||
}, | ||
map[interface{}]interface{}{ | ||
"labels": map[interface{}]interface{}{ | ||
"level": nil, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
func Test_parsePipeline(t *testing.T) { | ||
f, err := ioutil.TempFile("/tmp", "Test_parsePipeline") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(f.Name()) | ||
|
||
_, err = f.Write([]byte(fmt.Sprintf("pipeline_stages:\n%s", pipelineString))) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
tests := []struct { | ||
name string | ||
logCtx logger.Info | ||
want PipelineConfig | ||
wantErr bool | ||
}{ | ||
{"no config", logger.Info{Config: map[string]string{}}, PipelineConfig{}, false}, | ||
{"double config", logger.Info{Config: map[string]string{cfgPipelineStagesFileKey: "", cfgPipelineStagesKey: ""}}, PipelineConfig{}, true}, | ||
{"string config", logger.Info{Config: map[string]string{cfgPipelineStagesKey: pipelineString}}, pipeline, false}, | ||
{"string wrong", logger.Info{Config: map[string]string{cfgPipelineStagesKey: "pipelineString"}}, PipelineConfig{}, true}, | ||
{"file config", logger.Info{Config: map[string]string{cfgPipelineStagesFileKey: f.Name()}}, pipeline, false}, | ||
{"file wrong", logger.Info{Config: map[string]string{cfgPipelineStagesFileKey: "foo"}}, PipelineConfig{}, true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := parsePipeline(tt.logCtx) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("parsePipeline() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("parsePipeline() = %v, want %v", got, tt.want) | ||
} | ||
|
||
// all configs are supposed to be valid | ||
name := "foo" | ||
_, err = stages.NewPipeline(util.Logger, got.PipelineStages, &name, prometheus.DefaultRegisterer) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: "3" | ||
services: | ||
nginx: | ||
image: grafana/grafana | ||
logging: | ||
driver: loki | ||
options: | ||
loki-url: http://host.docker.internal:3100/loki/api/v1/push | ||
loki-pipeline-stages: | | ||
- regex: | ||
expression: '(level|lvl|severity)=(?P<level>\w+)' | ||
- labels: | ||
level: | ||
ports: | ||
- "3000:3000" |