Skip to content

Commit b05c4f7

Browse files
authored
chore(logging): Add entry's timestamp when rejected with too far behind (#12933)
Signed-off-by: Kaviraj <[email protected]>
1 parent 5ada92b commit b05c4f7

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

pkg/chunkenc/interface.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var (
2424
)
2525

2626
type errTooFarBehind struct {
27+
// original timestmap of the entry itself.
28+
entryTs time.Time
29+
30+
// cutoff is the oldest acceptable timstamp of the `stream` that entry belongs to.
2731
cutoff time.Time
2832
}
2933

@@ -32,12 +36,12 @@ func IsErrTooFarBehind(err error) bool {
3236
return ok
3337
}
3438

35-
func ErrTooFarBehind(cutoff time.Time) error {
36-
return &errTooFarBehind{cutoff: cutoff}
39+
func ErrTooFarBehind(entryTs, cutoff time.Time) error {
40+
return &errTooFarBehind{entryTs: entryTs, cutoff: cutoff}
3741
}
3842

3943
func (m *errTooFarBehind) Error() string {
40-
return "entry too far behind, oldest acceptable timestamp is: " + m.cutoff.Format(time.RFC3339)
44+
return fmt.Sprintf("entry too far behind, entry timestamp is: %s, oldest acceptable timestamp is: %s", m.entryTs.Format(time.RFC3339), m.cutoff.Format(time.RFC3339))
4145
}
4246

4347
func IsOutOfOrderErr(err error) bool {

pkg/chunkenc/interface_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ func TestParseEncoding(t *testing.T) {
3131
}
3232

3333
func TestIsOutOfOrderErr(t *testing.T) {
34-
for _, err := range []error{ErrOutOfOrder, ErrTooFarBehind(time.Now())} {
34+
now := time.Now()
35+
36+
for _, err := range []error{ErrOutOfOrder, ErrTooFarBehind(now, now)} {
3537
require.Equal(t, true, IsOutOfOrderErr(err))
3638
}
3739
}

pkg/ingester/stream.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func (s *stream) validateEntries(entries []logproto.Entry, isReplay, rateLimitWh
394394
// The validity window for unordered writes is the highest timestamp present minus 1/2 * max-chunk-age.
395395
cutoff := highestTs.Add(-s.cfg.MaxChunkAge / 2)
396396
if !isReplay && s.unorderedWrites && !highestTs.IsZero() && cutoff.After(entries[i].Timestamp) {
397-
failedEntriesWithError = append(failedEntriesWithError, entryWithError{&entries[i], chunkenc.ErrTooFarBehind(cutoff)})
397+
failedEntriesWithError = append(failedEntriesWithError, entryWithError{&entries[i], chunkenc.ErrTooFarBehind(entries[i].Timestamp, cutoff)})
398398
s.writeFailures.Log(s.tenant, fmt.Errorf("%w for stream %s", failedEntriesWithError[len(failedEntriesWithError)-1].e, s.labels))
399399
outOfOrderSamples++
400400
outOfOrderBytes += lineBytes

pkg/ingester/stream_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ func TestMaxReturnedStreamsErrors(t *testing.T) {
8484
var expected bytes.Buffer
8585
for i := 0; i < tc.expectErrs; i++ {
8686
fmt.Fprintf(&expected,
87-
"entry with timestamp %s ignored, reason: 'entry too far behind, oldest acceptable timestamp is: %s',\n",
87+
"entry with timestamp %s ignored, reason: 'entry too far behind, entry timestamp is: %s, oldest acceptable timestamp is: %s',\n",
8888
time.Unix(int64(i), 0).String(),
89+
newLines[i].Timestamp.Format(time.RFC3339),
8990
time.Unix(int64(numLogs), 0).Format(time.RFC3339),
9091
)
9192
}

0 commit comments

Comments
 (0)