forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request grafana#69 from grafana/main
- Loading branch information
Showing
41 changed files
with
969 additions
and
571 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package stages | ||
|
||
import ( | ||
"github.com/grafana/loki/pkg/logql/log" | ||
) | ||
|
||
type decolorizeStage struct{} | ||
|
||
func newDecolorizeStage(_ interface{}) (Stage, error) { | ||
return &decolorizeStage{}, nil | ||
} | ||
|
||
// Run implements Stage | ||
func (m *decolorizeStage) Run(in chan Entry) chan Entry { | ||
decolorizer, _ := log.NewDecolorizer() | ||
out := make(chan Entry) | ||
go func() { | ||
defer close(out) | ||
for e := range in { | ||
decolorizedLine, _ := decolorizer.Process( | ||
e.Timestamp.Unix(), | ||
[]byte(e.Entry.Line), | ||
nil, | ||
) | ||
e.Entry.Line = string(decolorizedLine) | ||
out <- e | ||
} | ||
}() | ||
return out | ||
} | ||
|
||
// Name implements Stage | ||
func (m *decolorizeStage) Name() string { | ||
return StageTypeDecolorize | ||
} |
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,52 @@ | ||
package stages | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/stretchr/testify/assert" | ||
|
||
util_log "github.com/grafana/loki/pkg/util/log" | ||
) | ||
|
||
var testDecolorizePipeline = ` | ||
pipeline_stages: | ||
- decolorize: | ||
` | ||
|
||
func TestPipeline_Decolorize(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := map[string]struct { | ||
config string | ||
entry string | ||
expectedEntry string | ||
}{ | ||
"successfully run pipeline on non-colored text": { | ||
testDecolorizePipeline, | ||
"sample text", | ||
"sample text", | ||
}, | ||
"successfully run pipeline on colored text": { | ||
testDecolorizePipeline, | ||
"\033[0;32mgreen\033[0m \033[0;31mred\033[0m", | ||
"green red", | ||
}, | ||
} | ||
|
||
for testName, testData := range tests { | ||
testData := testData | ||
|
||
t.Run(testName, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
pl, err := NewPipeline(util_log.Logger, loadConfig(testData.config), nil, prometheus.DefaultRegisterer) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
out := processEntries(pl, newEntry(nil, nil, testData.entry, time.Now()))[0] | ||
assert.Equal(t, testData.expectedEntry, out.Line) | ||
}) | ||
} | ||
} |
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
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,39 @@ | ||
--- | ||
title: decolorize | ||
--- | ||
# `decolorize` stage | ||
|
||
The `decolorize` stage is a transform stage that lets you strip | ||
ANSI color codes from the log line, thus making it easier to | ||
parse logs further. | ||
|
||
There are examples below to help explain. | ||
|
||
## Decolorize stage schema | ||
|
||
```yaml | ||
decolorize: | ||
# Currently this stage has no configurable options | ||
``` | ||
|
||
## Examples | ||
|
||
The following is an example showing the use of the `decolorize` stage. | ||
|
||
Given the pipeline: | ||
|
||
```yaml | ||
- decolorize: | ||
``` | ||
Would turn each line having a color code into a non-colored one, e.g. | ||
``` | ||
[2022-11-04 22:17:57.811] \033[0;32http\033[0m: GET /_health (0 ms) 204 | ||
``` | ||
is turned into | ||
``` | ||
[2022-11-04 22:17:57.811] http: GET /_health (0 ms) 204 | ||
``` |
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
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
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
Oops, something went wrong.