Skip to content

Commit

Permalink
Merge pull request grafana#69 from grafana/main
Browse files Browse the repository at this point in the history
  • Loading branch information
periklis authored Nov 8, 2022
2 parents a8e1f08 + a1d46d2 commit 5179433
Show file tree
Hide file tree
Showing 41 changed files with 969 additions and 571 deletions.
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

### All Changes

#### Loki

##### Enhancements

* [7602](https://github.com/grafana/loki/pull/7602) **vmax**: Add decolorize filter to easily parse colored logs.

##### Fixes

##### Changes

#### Promtail

* [7602](https://github.com/grafana/loki/pull/7602) **vmax**: Add decolorize stage to Promtail to easily parse colored logs.

##### Enhancements

##### Fixes

##### Changes

#### Fluent Bit

#### Loki Canary

#### Jsonnet

### Notes

This release was created from a branch starting at commit FIXME but it may also contain backported changes from main.

Check the history of the branch FIXME.

### Dependencies

* Go Version: FIXME

## 2.7.0

#### Loki
Expand All @@ -24,6 +60,7 @@
* [7264](https://github.com/grafana/loki/pull/7264) **bboreham**: Chunks: decode varints directly from byte buffer, for speed.
* [7263](https://github.com/grafana/loki/pull/7263) **bboreham**: Dependencies: klauspost/compress package to v1.15.11; improves performance.
* [7270](https://github.com/grafana/loki/pull/7270) **wilfriedroset**: Add support for `username` to redis cache configuration.
* [6952](https://github.com/grafana/loki/pull/6952) **DylanGuedes**: Experimental: Introduce a new feature named stream sharding.

##### Fixes
* [7453](https://github.com/grafana/loki/pull/7453) **periklis**: Add single compactor http client for delete and gennumber clients
Expand Down Expand Up @@ -63,6 +100,7 @@
##### Fixes
* [6766](https://github.com/grafana/loki/pull/6766) **kavirajk**: fix(logql): Make `LabelSampleExtractor` ignore processing the line if it doesn't contain that specific label. Fixes unwrap behavior explained in the issue https://github.com/grafana/loki/issues/6713
* [7016](https://github.com/grafana/loki/pull/7016) **chodges15**: Fix issue with dropping logs when a file based SD target's labels are updated
* [7461](https://github.com/grafana/loki/pull/7461) **MarNicGit**: Promtail: Fix collecting userdata field from Windows Event Log

##### Changes
* **quodlibetor**: Change Docker target discovery log level from `Error` to `Info`
Expand Down
35 changes: 35 additions & 0 deletions clients/pkg/logentry/stages/decolorize.go
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
}
52 changes: 52 additions & 0 deletions clients/pkg/logentry/stages/decolorize_test.go
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)
})
}
}
6 changes: 6 additions & 0 deletions clients/pkg/logentry/stages/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
StageTypePack = "pack"
StageTypeLabelAllow = "labelallow"
StageTypeStaticLabels = "static_labels"
StageTypeDecolorize = "decolorize"
)

// Processor takes an existing set of labels, timestamp and log entry and returns either a possibly mutated
Expand Down Expand Up @@ -209,6 +210,11 @@ func New(logger log.Logger, jobName *string, stageType string,
if err != nil {
return nil, err
}
case StageTypeDecolorize:
s, err = newDecolorizeStage(cfg)
if err != nil {
return nil, err
}
default:
return nil, errors.Errorf("Unknown stage type: %s", stageType)
}
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/windows/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func formatLine(cfg *scrapeconfig.WindowsEventsTargetConfig, event win_eventlog.
structuredEvent.EventData = string(event.EventData.InnerXML)
}
if !cfg.ExcludeUserData {
structuredEvent.UserData = string(event.EventData.InnerXML)
structuredEvent.UserData = string(event.UserData.InnerXML)
}
if event.Correlation.ActivityID != "" || event.Correlation.RelatedActivityID != "" {
structuredEvent.Correlation = &Correlation{
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/windows/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func Test_renderEntries(t *testing.T) {
Labels: model.LabelSet{"channel": "channel", "computer": "local", "job": "windows-events"},
Entry: logproto.Entry{
Timestamp: time.Unix(0, 1).UTC(),
Line: `{"source":"Application","channel":"channel","computer":"local","event_id":10,"version":10,"level":10,"task":10,"opCode":10,"keywords":"keywords","timeCreated":"1970-01-01T00:00:00.000000001Z","eventRecordID":11,"correlation":{"activityID":"some activity","relatedActivityID":"some related activity"},"execution":{"processId":1,"threadId":5},"security":{"userId":"1"},"user_data":"eventdata","event_data":"eventdata","message":"message"}`,
Line: `{"source":"Application","channel":"channel","computer":"local","event_id":10,"version":10,"level":10,"task":10,"opCode":10,"keywords":"keywords","timeCreated":"1970-01-01T00:00:00.000000001Z","eventRecordID":11,"correlation":{"activityID":"some activity","relatedActivityID":"some related activity"},"execution":{"processId":1,"threadId":5},"security":{"userId":"1"},"user_data":"userdata","event_data":"eventdata","message":"message"}`,
},
},
}, entries)
Expand Down
1 change: 1 addition & 0 deletions docs/sources/clients/promtail/stages/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Transform stages:

- [template](template/): Use Go templates to modify extracted data.
- [pack](pack/): Packs a log line in a JSON object allowing extracted values and labels to be placed inside the log line.
- [decolorize](decolorize/): Strips ANSI color sequences from the log line.

Action stages:

Expand Down
3 changes: 2 additions & 1 deletion docs/sources/clients/promtail/stages/cri.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ space-delimited values with the following components:

1. `time`: The timestamp string of the log
1. `stream`: Either stdout or stderr
1. `flags`: CRI flags including F or P
1. `log`: The contents of the log line

No whitespace is permitted between the components. In the following example,
Expand All @@ -39,7 +40,7 @@ For the given pipeline:
Given the following log line:

```
"2019-04-30T02:12:41.8443515Z stdout xx message"
"2019-04-30T02:12:41.8443515Z stdout F message"
```

The following key-value pairs would be created in the set of extracted data:
Expand Down
39 changes: 39 additions & 0 deletions docs/sources/clients/promtail/stages/decolorize.md
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
```
2 changes: 1 addition & 1 deletion docs/sources/installation/helm/install-scalable/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This Helm Chart installation runs the Grafana Loki cluster within a Kubernetes c

If object storge is configured, this chart configures Loki to run `read` and `write` targets in a [scalable](../../fundamentals/architecture/deployment-modes/#simple-scalable-deployment-mode), highly available architecture (3 replicas of each) designed to work with AWS S3 object storage. It will also configure meta-monitoring of metrics and logs.

It is not possible to run the scalable mode with the `fulesystem` storage.
It is not possible to run the scalable mode with the `filesystem` storage.

**Before you begin:**

Expand Down
4 changes: 2 additions & 2 deletions docs/sources/installation/helm/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ null
<tr>
<td>monitoring.serviceMonitor.metricsInstance.annotations</td>
<td>object</td>
<td>MerticsInstance annotations</td>
<td>MetricsInstance annotations</td>
<td><pre lang="json">
{}
</pre>
Expand All @@ -1996,7 +1996,7 @@ true
<tr>
<td>monitoring.serviceMonitor.metricsInstance.labels</td>
<td>object</td>
<td>Additional MatricsInstance labels</td>
<td>Additional MetricsInstance labels</td>
<td><pre lang="json">
{}
</pre>
Expand Down
10 changes: 10 additions & 0 deletions docs/sources/logql/log_queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ log stream selectors have been applied.

Line filter expressions have support matching IP addresses. See [Matching IP addresses](../ip/) for details.


### Removing color codes

Line filter expressions support stripping ANSI sequences (color codes) from
the line:

```
{job="example"} | decolorize
```

### Label filter expression

Label filter expression allows filtering log line using their original and extracted labels. It can contain multiple predicates.
Expand Down
19 changes: 19 additions & 0 deletions docs/sources/logql/query_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@ The result would be:
2020-10-23T20:32:18.068866235Z 624.008132ms traceID = 1980d41501b57b68 {cluster="ops-tools1", job="loki-ops/query-frontend"} |= "query_range"
```

It's possible to strip ANSI sequences from the log line, making it easier
to parse it further:

```
{job="example"} | decolorize
```

This way this log line:

```
[2022-11-04 22:17:57.811] \033[0;32http\033[0m: GET /_health (0 ms) 204
```

turns into:
```
[2022-11-04 22:17:57.811] http: GET /_health (0 ms) 204
```


## Unwrap examples

- Calculate the p99 of the nginx-ingress latency by path:
Expand Down
16 changes: 16 additions & 0 deletions docs/sources/operations/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ attempt to run a [LogCLI](../../tools/logcli/) query in as direct a manner as yo
- Adjust the [Grafana dataproxy timeout](https://grafana.com/docs/grafana/latest/administration/configuration/#dataproxy). Configure Grafana with a large enough dataproxy timeout.
- Check timeouts for reverse proxies or load balancers between your client and Grafana. Queries to Grafana are made from the your local browser with Grafana serving as a proxy (a dataproxy). Therefore, connections from your client to Grafana must have their timeout configured as well.

## Cache Generation errors
Loki cache generation number errors(Loki >= 2.6)

### error loading cache generation numbers

- Symptom:

- Loki exposed errors on log with `msg="error loading cache generation numbers" err="unexpected status code: 403"` or `msg="error getting cache gen numbers from the store"`

- Investigation:

- Check the metric `loki_delete_cache_gen_load_failures_total` on `/metrics`, which is an indicator for the occurrence of the problem. If the value is greater than 1, it means that there is a problem with that component.

- Try Http GET request to route: /loki/api/v1/cache/generation_numbers
- If response is equal as `"deletion is not available for this tenant"`, this means the deletion API is not enabled for the tenant. To enable this api, set `allow_deletes: true` for this tenant via the configuration settings. Check more docs: https://grafana.com/docs/loki/latest/operations/storage/logs-deletion/

## Troubleshooting targets

Promtail exposes two web pages that can be used to understand how its service
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ require (
github.com/segmentio/fasthash v1.0.3
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
github.com/sony/gobreaker v0.4.1
github.com/sony/gobreaker v0.5.0
github.com/spf13/afero v1.9.2
github.com/stretchr/testify v1.8.0
github.com/thanos-io/thanos v0.28.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,9 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d/go.mod h1:Cw4GTlQccdRGSEf6KiMju767x0NEHE0YIVPJSaXjlsw=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/soniah/gosnmp v1.25.0/go.mod h1:8YvfZxH388NIIw2A+X5z2Oh97VcNhtmxDLt5QeUzVuQ=
github.com/sony/gobreaker v0.4.1 h1:oMnRNZXX5j85zso6xCPRNPtmAycat+WcoKbklScLDgQ=
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
github.com/sony/gobreaker v0.5.0 h1:dRCvqm0P490vZPmy7ppEk2qCnCieBooFJ+YoXGYB+yg=
github.com/sony/gobreaker v0.5.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
github.com/soveran/redisurl v0.0.0-20180322091936-eb325bc7a4b8/go.mod h1:FVJ8jbHu7QrNFs3bZEsv/L5JjearIAY9N0oXh2wk+6Y=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
Expand Down
2 changes: 1 addition & 1 deletion operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ scorecard: generate go-generate bundle ## Run scorecard test

.PHONY: lint
lint: $(GOLANGCI_LINT) | generate ## Run golangci-lint on source code.
$(GOLANGCI_LINT) run ./...
$(GOLANGCI_LINT) run --timeout=5m ./...

.PHONY: lint-prometheus
lint-prometheus: $(PROMTOOL) ## Run promtool check against recording rules and alerts.
Expand Down
Loading

0 comments on commit 5179433

Please sign in to comment.