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

Improved Ingester out-of-order error for faster troubleshooting #1008

Merged
merged 7 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
33 changes: 27 additions & 6 deletions pkg/ingester/stream.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ingester

import (
"bytes"
"context"
"fmt"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -64,6 +66,11 @@ type chunkDesc struct {
lastUpdated time.Time
}

type entryWithError struct {
entry logproto.Entry
e error
}
wardbekker marked this conversation as resolved.
Show resolved Hide resolved

func newStream(fp model.Fingerprint, labels []client.LabelAdapter, blockSize int) *stream {
return &stream{
fp: fp,
Expand Down Expand Up @@ -96,11 +103,11 @@ func (s *stream) Push(_ context.Context, entries []logproto.Entry) error {
chunksCreatedTotal.Inc()
}

storedEntries := []logproto.Entry{}
var storedEntries []logproto.Entry
var failedEntriesWithError []entryWithError
wardbekker marked this conversation as resolved.
Show resolved Hide resolved

// Don't fail on the first append error - if samples are sent out of order,
// we still want to append the later ones.
var appendErr error
for i := range entries {
chunk := &s.chunks[len(s.chunks)-1]
if chunk.closed || !chunk.chunk.SpaceFor(&entries[i]) {
Expand All @@ -115,7 +122,7 @@ func (s *stream) Push(_ context.Context, entries []logproto.Entry) error {
chunk = &s.chunks[len(s.chunks)-1]
}
if err := chunk.chunk.Append(&entries[i]); err != nil {
appendErr = err
failedEntriesWithError = append(failedEntriesWithError, entryWithError{entries[i], err})
} else {
// send only stored entries to tailers
storedEntries = append(storedEntries, entries[i])
Expand Down Expand Up @@ -150,11 +157,25 @@ func (s *stream) Push(_ context.Context, entries []logproto.Entry) error {
}()
}

if appendErr == chunkenc.ErrOutOfOrder {
return httpgrpc.Errorf(http.StatusBadRequest, "entry out of order for stream: %s", client.FromLabelAdaptersToLabels(s.labels).String())
if len(failedEntriesWithError) > 0 {
// return bad http status request response with all failed entries
buf := bytes.Buffer{}
streamName := client.FromLabelAdaptersToLabels(s.labels).String()

for _, entryWithError := range failedEntriesWithError {
if entryWithError.e == chunkenc.ErrOutOfOrder {
fmt.Fprintf(&buf,
"entry with timestamp %s ignored, reason: '%s' for stream: %s,\n",
entryWithError.entry.Timestamp.String(), entryWithError.e, streamName)
}
}

fmt.Fprintf(&buf, "total ignored: %d out of %d", len(failedEntriesWithError), len(entries))

return httpgrpc.Errorf(http.StatusBadRequest, buf.String())
wardbekker marked this conversation as resolved.
Show resolved Hide resolved
}

return appendErr
return nil
}

// Returns an iterator.
Expand Down
21 changes: 19 additions & 2 deletions pkg/ingester/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,24 @@ func TestTransferOut(t *testing.T) {
assert.Len(t, ing.instances["test"].streams, 2)
}

// Create a new ingester and trasfer data to it
// verify we get out of order exception on adding an entry with older timestamps
_, err2 := ing.Push(ctx, &logproto.PushRequest{
Streams: []*logproto.Stream{
{
Entries: []logproto.Entry{
{Line: "out of order line", Timestamp: time.Unix(0, 0)},
{Line: "line 4", Timestamp: time.Unix(2, 0)},
},
Labels: `{foo="bar",bar="baz1"}`,
},
},
})

require.Error(t, err2)
require.Contains(t, err2.Error(), "out of order")
require.Contains(t, err2.Error(), "total ignored: 1 out of 2")

// Create a new ingester and transfer data to it
ing2 := f.getIngester(time.Second*60, t)
ing.Shutdown()

Expand Down Expand Up @@ -87,7 +104,7 @@ func TestTransferOut(t *testing.T) {

assert.Equal(
t,
[]string{"line 0", "line 1", "line 2", "line 3"},
[]string{"line 0", "line 1", "line 2", "line 3", "line 4"},
lines,
)
}
Expand Down