From 56db10bdb4af1202aae6fe2e5baff5b8202f9ce3 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Wed, 29 May 2019 15:17:46 +0530 Subject: [PATCH 1/2] Reject entries based on age set in limits --- cmd/loki/loki-local-config.yaml | 2 ++ pkg/distributor/distributor.go | 18 ++++++++++++++++++ production/helm/loki-stack/Chart.yaml | 2 +- production/helm/loki/Chart.yaml | 2 +- production/helm/loki/values.yaml | 2 ++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/loki/loki-local-config.yaml b/cmd/loki/loki-local-config.yaml index 4e6978c494864..28e3c18b3b4ba 100644 --- a/cmd/loki/loki-local-config.yaml +++ b/cmd/loki/loki-local-config.yaml @@ -31,6 +31,8 @@ storage_config: limits_config: enforce_metric_name: false + reject_old_samples: true + reject_old_samples_max_age: 24h chunk_store_config: max_look_back_period: 0 diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index a768c98bb0d22..a0063b88b26ff 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -5,6 +5,7 @@ import ( "flag" "hash/fnv" "sync/atomic" + "time" cortex_client "github.com/cortexproject/cortex/pkg/ingester/client" "github.com/cortexproject/cortex/pkg/ring" @@ -21,6 +22,8 @@ import ( "github.com/grafana/loki/pkg/util" ) +const metricName = "logs" + var ( ingesterAppends = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: "loki", @@ -130,6 +133,21 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log continue } + entries := make([]logproto.Entry, 0, len(stream.Entries)) + for _, entry := range stream.Entries { + if err := d.overrides.ValidateSample(userID, metricName, cortex_client.Sample{ + TimestampMs: entry.Timestamp.UnixNano() / int64(time.Millisecond), + }); err != nil { + validationErr = err + continue + } + entries = append(entries, entry) + } + + if len(entries) == 0 { + continue + } + stream.Entries = entries keys = append(keys, tokenFor(userID, stream.Labels)) streams = append(streams, streamTracker{ stream: stream, diff --git a/production/helm/loki-stack/Chart.yaml b/production/helm/loki-stack/Chart.yaml index 1209a6ad8b40a..b4df444c686cb 100644 --- a/production/helm/loki-stack/Chart.yaml +++ b/production/helm/loki-stack/Chart.yaml @@ -1,5 +1,5 @@ name: loki-stack -version: 0.10.0 +version: 0.10.1 appVersion: 0.0.1 kubeVersion: "^1.10.0-0" description: "Loki: like Prometheus, but for logs." diff --git a/production/helm/loki/Chart.yaml b/production/helm/loki/Chart.yaml index d0ef9035a0572..22ce5789e6d2d 100644 --- a/production/helm/loki/Chart.yaml +++ b/production/helm/loki/Chart.yaml @@ -1,5 +1,5 @@ name: loki -version: 0.9.0 +version: 0.9.1 appVersion: 0.0.1 kubeVersion: "^1.10.0-0" description: "Loki: like Prometheus, but for logs." diff --git a/production/helm/loki/values.yaml b/production/helm/loki/values.yaml index c1825e85b9876..9dde8e706b38a 100644 --- a/production/helm/loki/values.yaml +++ b/production/helm/loki/values.yaml @@ -40,6 +40,8 @@ config: # consistentreads: true limits_config: enforce_metric_name: false + reject_old_samples: true + reject_old_samples_max_age: 24h schema_config: configs: - from: 2018-04-15 From fe0bfbdac86cbb8ce5a25182793a0e4e706e20d2 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Thu, 30 May 2019 15:08:21 +0530 Subject: [PATCH 2/2] Changed max samples age to 1 week and added the same to ksonnet --- cmd/loki/loki-local-config.yaml | 2 +- production/helm/loki/values.yaml | 2 +- production/ksonnet/loki/config.libsonnet | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/loki/loki-local-config.yaml b/cmd/loki/loki-local-config.yaml index 28e3c18b3b4ba..17e3511305ee5 100644 --- a/cmd/loki/loki-local-config.yaml +++ b/cmd/loki/loki-local-config.yaml @@ -32,7 +32,7 @@ storage_config: limits_config: enforce_metric_name: false reject_old_samples: true - reject_old_samples_max_age: 24h + reject_old_samples_max_age: 168h chunk_store_config: max_look_back_period: 0 diff --git a/production/helm/loki/values.yaml b/production/helm/loki/values.yaml index 9dde8e706b38a..e871de7ab1cb0 100644 --- a/production/helm/loki/values.yaml +++ b/production/helm/loki/values.yaml @@ -41,7 +41,7 @@ config: limits_config: enforce_metric_name: false reject_old_samples: true - reject_old_samples_max_age: 24h + reject_old_samples_max_age: 168h schema_config: configs: - from: 2018-04-15 diff --git a/production/ksonnet/loki/config.libsonnet b/production/ksonnet/loki/config.libsonnet index b1dd463c98450..7eaedd333b723 100644 --- a/production/ksonnet/loki/config.libsonnet +++ b/production/ksonnet/loki/config.libsonnet @@ -33,6 +33,8 @@ limits_config: { enforce_metric_name: false, + reject_old_samples: true, + reject_old_samples_max_age: '168h', }, ingester: {