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

receive: Improved Performance for err path. #4085

Merged
merged 1 commit into from
Apr 21, 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
2 changes: 1 addition & 1 deletion pkg/receive/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ func Heap(dir string) (err error) {
return err
}

f, err := os.Create(filepath.Join(dir, "impr5-go1.16.3.pprof"))
f, err := os.Create(filepath.Join(dir, "errimpr1-go1.16.3.pprof"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it only for testing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I provably should remove those before merging but those are super useful for checking leaks (:

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/receive/hashring.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (s simpleHashring) GetN(tenant string, ts *prompb.TimeSeries, n uint64) (st
return "", &insufficientNodesError{have: uint64(len(s)), want: n + 1}
}

// TODO(bwplotka): This might be not needed, double check.
sort.Slice(ts.Labels, func(i, j int) bool { return ts.Labels[i].Name < ts.Labels[j].Name })

return s[(labelpb.HashWithPrefix(tenant, ts.Labels)+n)%uint64(len(s))], nil
Expand Down
19 changes: 9 additions & 10 deletions pkg/receive/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,32 @@ func (r *Writer) Write(ctx context.Context, tenantID string, wreq *prompb.WriteR
switch err {
case storage.ErrOutOfOrderSample:
numOutOfOrder++
level.Debug(r.logger).Log("msg", "Out of order sample", "lset", lset.String(), "sample", s.String())
level.Debug(r.logger).Log("msg", "Out of order sample", "lset", lset, "sample", s)
case storage.ErrDuplicateSampleForTimestamp:
numDuplicates++
level.Debug(r.logger).Log("msg", "Duplicate sample for timestamp", "lset", lset.String(), "sample", s.String())
level.Debug(r.logger).Log("msg", "Duplicate sample for timestamp", "lset", lset, "sample", s)
onprem marked this conversation as resolved.
Show resolved Hide resolved
case storage.ErrOutOfBounds:
numOutOfBounds++
level.Debug(r.logger).Log("msg", "Out of bounds metric", "lset", lset.String(), "sample", s.String())
level.Debug(r.logger).Log("msg", "Out of bounds metric", "lset", lset, "sample", s)
}
}
}

if numOutOfOrder > 0 {
level.Warn(r.logger).Log("msg", "Error on ingesting out-of-order samples", "num_dropped", numOutOfOrder)
errs.Add(errors.Wrapf(storage.ErrOutOfOrderSample, "failed to non-fast add %d samples", numOutOfOrder))
level.Warn(r.logger).Log("msg", "Error on ingesting out-of-order samples", "numDropped", numOutOfOrder)
errs.Add(errors.Wrapf(storage.ErrOutOfOrderSample, "add %d samples", numOutOfOrder))
}
if numDuplicates > 0 {
level.Warn(r.logger).Log("msg", "Error on ingesting samples with different value but same timestamp", "num_dropped", numDuplicates)
errs.Add(errors.Wrapf(storage.ErrDuplicateSampleForTimestamp, "failed to non-fast add %d samples", numDuplicates))
level.Warn(r.logger).Log("msg", "Error on ingesting samples with different value but same timestamp", "numDropped", numDuplicates)
errs.Add(errors.Wrapf(storage.ErrDuplicateSampleForTimestamp, "add %d samples", numDuplicates))
}
if numOutOfBounds > 0 {
level.Warn(r.logger).Log("msg", "Error on ingesting samples that are too old or are too far into the future", "num_dropped", numOutOfBounds)
errs.Add(errors.Wrapf(storage.ErrOutOfBounds, "failed to non-fast add %d samples", numOutOfBounds))
level.Warn(r.logger).Log("msg", "Error on ingesting samples that are too old or are too far into the future", "numDropped", numOutOfBounds)
errs.Add(errors.Wrapf(storage.ErrOutOfBounds, "add %d samples", numOutOfBounds))
}

if err := app.Commit(); err != nil {
errs.Add(errors.Wrap(err, "commit samples"))
}

return errs.Err()
}