-
Notifications
You must be signed in to change notification settings - Fork 816
WIP: Support ingesting exemplars into TSDB when blocks storage is enabled #4104
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
Changes from 4 commits
ff2ec61
37098f6
5b59fec
9f0b9d8
1211fc6
5fb6589
9c9fcab
ec67f35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/prometheus/pkg/exemplar" | ||
"github.com/prometheus/prometheus/pkg/labels" | ||
"github.com/prometheus/prometheus/storage" | ||
"github.com/prometheus/prometheus/tsdb" | ||
|
@@ -751,6 +752,8 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor | |
var ( | ||
succeededSamplesCount = 0 | ||
failedSamplesCount = 0 | ||
succeededExemplarsCount = 0 | ||
failedExemplarsCount = 0 | ||
startAppend = time.Now() | ||
sampleOutOfBoundsCount = 0 | ||
sampleOutOfOrderCount = 0 | ||
|
@@ -847,6 +850,30 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor | |
return copiedLabels | ||
}) | ||
} | ||
|
||
// app.AppendExemplar currently doesn't create the series, it must | ||
// already exist. If it does not then drop. TODO(mdisibio) - better way to handle? | ||
if ref == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In prometheus we skip the exemplar and increment a counter, probably best to just do the same here. Because right now a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that is true. We have two choices, we could count them as failed or discarded due to validation. In this case I think failed is more appropriate because there isn't anything wrong with the exemplar itself, it is more that it couldn't be ingested due to a limitation in the current tsdb implementation. If/when tsdb AppendExemplar is updated to create the series then the same data would be ingested successfully. Update: Went with failed approach. |
||
continue | ||
} | ||
|
||
for _, ex := range ts.Exemplars { | ||
e := exemplar.Exemplar{ | ||
Value: ex.Value, | ||
Ts: ex.TimestampMs, | ||
HasTs: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we're ingesting via remote write, as long as all exemplars have the same value for this field (whether it's true or false) we would be able to dedupe properly |
||
Labels: cortexpb.FromLabelAdaptersToLabelsWithCopy(ex.Labels), | ||
} | ||
|
||
if _, err = app.AppendExemplar(ref, nil, e); err == nil { | ||
succeededExemplarsCount++ | ||
continue | ||
} | ||
|
||
// Error adding exemplar | ||
updateFirstPartial(func() error { return wrappedTSDBIngestErr(err, model.Time(ex.TimestampMs), ts.Labels) }) | ||
failedExemplarsCount++ | ||
} | ||
} | ||
|
||
// At this point all samples have been added to the appender, so we can track the time it took. | ||
|
@@ -868,6 +895,8 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor | |
// which will be converted into an HTTP 5xx and the client should/will retry. | ||
i.metrics.ingestedSamples.Add(float64(succeededSamplesCount)) | ||
i.metrics.ingestedSamplesFail.Add(float64(failedSamplesCount)) | ||
i.metrics.ingestedExemplars.Add(float64(succeededExemplarsCount)) | ||
i.metrics.ingestedExemplarsFail.Add(float64(failedExemplarsCount)) | ||
|
||
if sampleOutOfBoundsCount > 0 { | ||
validation.DiscardedSamples.WithLabelValues(sampleOutOfBounds, userID).Add(float64(sampleOutOfBoundsCount)) | ||
|
@@ -1479,6 +1508,7 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) { | |
WALSegmentSize: i.cfg.BlocksStorageConfig.TSDB.WALSegmentSizeBytes, | ||
SeriesLifecycleCallback: userDB, | ||
BlocksToDelete: userDB.blocksToDelete, | ||
MaxExemplars: i.cfg.BlocksStorageConfig.TSDB.MaxExemplars, | ||
}) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to open TSDB: %s", udir) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check if we need to sort the exemplars by timestamp as well (see the comment above the samples line)