Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discard/ooo #4104

Merged
merged 2 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/ingester/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (i *instance) consumeChunk(ctx context.Context, ls labels.Labels, chunk *lo
if !ok {

sortedLabels := i.index.Add(cortexpb.FromLabelsToLabelAdapters(ls), fp)
stream = newStream(i.cfg, fp, sortedLabels, i.metrics)
stream = newStream(i.cfg, i.instanceID, fp, sortedLabels, i.metrics)
i.streamsByFP[fp] = stream
i.streams[stream.labelsString] = stream
i.streamsCreatedTotal.Inc()
Expand Down Expand Up @@ -243,7 +243,7 @@ func (i *instance) getOrCreateStream(pushReqStream logproto.Stream, lock bool, r
fp := i.getHashForLabels(labels)

sortedLabels := i.index.Add(cortexpb.FromLabelsToLabelAdapters(labels), fp)
stream = newStream(i.cfg, fp, sortedLabels, i.metrics)
stream = newStream(i.cfg, i.instanceID, fp, sortedLabels, i.metrics)
i.streams[pushReqStream.Labels] = stream
i.streamsByFP[fp] = stream

Expand Down
4 changes: 2 additions & 2 deletions pkg/ingester/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func Test_SeriesQuery(t *testing.T) {
for _, testStream := range testStreams {
stream, err := instance.getOrCreateStream(testStream, false, recordPool.GetRecord())
require.NoError(t, err)
chunk := newStream(cfg, 0, nil, NilMetrics).NewChunk()
chunk := newStream(cfg, "fake", 0, nil, NilMetrics).NewChunk()
for _, entry := range testStream.Entries {
err = chunk.Append(&entry)
require.NoError(t, err)
Expand Down Expand Up @@ -333,7 +333,7 @@ func Benchmark_instance_addNewTailer(b *testing.B) {
lbs := makeRandomLabels()
b.Run("addTailersToNewStream", func(b *testing.B) {
for n := 0; n < b.N; n++ {
inst.addTailersToNewStream(newStream(nil, 0, lbs, NilMetrics))
inst.addTailersToNewStream(newStream(nil, "fake", 0, lbs, NilMetrics))
}
})
}
Expand Down
21 changes: 19 additions & 2 deletions pkg/ingester/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logql/log"
"github.com/grafana/loki/pkg/logqlmodel/stats"
"github.com/grafana/loki/pkg/validation"
)

var (
Expand Down Expand Up @@ -63,7 +64,8 @@ type line struct {
}

type stream struct {
cfg *Config
cfg *Config
tenant string
// Newest chunk at chunks[n-1].
// Not thread-safe; assume accesses to this are locked by caller.
chunks []chunkDesc
Expand Down Expand Up @@ -109,14 +111,15 @@ type entryWithError struct {
e error
}

func newStream(cfg *Config, fp model.Fingerprint, labels labels.Labels, metrics *ingesterMetrics) *stream {
func newStream(cfg *Config, tenant string, fp model.Fingerprint, labels labels.Labels, metrics *ingesterMetrics) *stream {
return &stream{
cfg: cfg,
fp: fp,
labels: labels,
labelsString: labels.String(),
tailers: map[uint32]*tailer{},
metrics: metrics,
tenant: tenant,
}
}

Expand Down Expand Up @@ -193,6 +196,14 @@ func (s *stream) Push(
var storedEntries []logproto.Entry
failedEntriesWithError := []entryWithError{}

var outOfOrderSamples, outOfOrderBytes int
defer func() {
if outOfOrderSamples > 0 {
validation.DiscardedSamples.WithLabelValues(validation.OutOfOrder, s.tenant).Add(float64(outOfOrderSamples))
validation.DiscardedBytes.WithLabelValues(validation.OutOfOrder, s.tenant).Add(float64(outOfOrderBytes))
}
}()

// Don't fail on the first append error - if samples are sent out of order,
// we still want to append the later ones.
for i := range entries {
Expand Down Expand Up @@ -232,8 +243,14 @@ func (s *stream) Push(
// The validity window for unordered writes is the highest timestamp present minus 1/2 * max-chunk-age.
if s.cfg.UnorderedWrites && !s.highestTs.IsZero() && s.highestTs.Add(-s.cfg.MaxChunkAge/2).After(entries[i].Timestamp) {
failedEntriesWithError = append(failedEntriesWithError, entryWithError{&entries[i], chunkenc.ErrOutOfOrder})
outOfOrderSamples++
outOfOrderBytes += len(entries[i].Line)
} else if err := chunk.chunk.Append(&entries[i]); err != nil {
failedEntriesWithError = append(failedEntriesWithError, entryWithError{&entries[i], err})
if err == chunkenc.ErrOutOfOrder {
outOfOrderSamples++
outOfOrderBytes += len(entries[i].Line)
}
} else {
storedEntries = append(storedEntries, entries[i])
s.lastLine.ts = entries[i].Timestamp
Expand Down
6 changes: 5 additions & 1 deletion pkg/ingester/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestMaxReturnedStreamsErrors(t *testing.T) {
cfg.MaxReturnedErrors = tc.limit
s := newStream(
cfg,
"fake",
model.Fingerprint(0),
labels.Labels{
{Name: "foo", Value: "bar"},
Expand Down Expand Up @@ -76,6 +77,7 @@ func TestMaxReturnedStreamsErrors(t *testing.T) {
func TestPushDeduplication(t *testing.T) {
s := newStream(
defaultConfig(),
"fake",
model.Fingerprint(0),
labels.Labels{
{Name: "foo", Value: "bar"},
Expand All @@ -98,6 +100,7 @@ func TestPushDeduplication(t *testing.T) {
func TestPushRejectOldCounter(t *testing.T) {
s := newStream(
defaultConfig(),
"fake",
model.Fingerprint(0),
labels.Labels{
{Name: "foo", Value: "bar"},
Expand Down Expand Up @@ -185,6 +188,7 @@ func TestUnorderedPush(t *testing.T) {
cfg.MaxChunkAge = 10 * time.Second
s := newStream(
&cfg,
"fake",
model.Fingerprint(0),
labels.Labels{
{Name: "foo", Value: "bar"},
Expand Down Expand Up @@ -260,7 +264,7 @@ func Benchmark_PushStream(b *testing.B) {
labels.Label{Name: "job", Value: "loki-dev/ingester"},
labels.Label{Name: "container", Value: "ingester"},
}
s := newStream(&Config{}, model.Fingerprint(0), ls, NilMetrics)
s := newStream(&Config{}, "fake", model.Fingerprint(0), ls, NilMetrics)
t, err := newTailer("foo", `{namespace="loki-dev"}`, &fakeTailServer{})
require.NoError(b, err)

Expand Down
1 change: 1 addition & 0 deletions pkg/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
// because the limit of active streams has been reached.
StreamLimit = "stream_limit"
StreamLimitErrorMsg = "Maximum active stream limit exceeded, reduce the number of active streams (reduce labels or reduce label values), or contact your Loki administrator to see if the limit can be increased"
OutOfOrder = "out_of_order"
// GreaterThanMaxSampleAge is a reason for discarding log lines which are older than the current time - `reject_old_samples_max_age`
GreaterThanMaxSampleAge = "greater_than_max_sample_age"
GreaterThanMaxSampleAgeErrorMsg = "entry for stream '%s' has timestamp too old: %v"
Expand Down