Skip to content

Commit

Permalink
fix: change cortex_discarded_samples_total label to sample-timestamp-…
Browse files Browse the repository at this point in the history
…too-old

This change was made in order to match err-mimir-sample-timestamp-too-old event logs
  • Loading branch information
NickAnge committed Nov 12, 2024
1 parent 0271ea0 commit 27b7229
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const (
reasonSampleTooOld = "sample-too-old"
reasonSampleTooFarInFuture = "sample-too-far-in-future"
reasonNewValueForTimestamp = "new-value-for-timestamp"
reasonSampleOutOfBounds = "sample-out-of-bounds"
reasonSampleTimestampTooOld = "sample-timestamp-too-old"
reasonPerUserSeriesLimit = "per_user_series_limit"
reasonPerMetricSeriesLimit = "per_metric_series_limit"
reasonInvalidNativeHistogram = "invalid-native-histogram"
Expand Down Expand Up @@ -959,7 +959,7 @@ type pushStats struct {
failedSamplesCount int
succeededExemplarsCount int
failedExemplarsCount int
sampleOutOfBoundsCount int
sampleTimestampTooOldCount int
sampleOutOfOrderCount int
sampleTooOldCount int
sampleTooFarInFutureCount int
Expand Down Expand Up @@ -1189,7 +1189,7 @@ func (i *Ingester) PushWithCleanup(ctx context.Context, req *mimirpb.WriteReques
stats.failedSamplesCount++
},
func(timestamp int64, labels []mimirpb.LabelAdapter) {
stats.sampleOutOfBoundsCount++
stats.sampleTimestampTooOldCount++
updateFirstPartial(i.errorSamplers.sampleTimestampTooOld, func() softError {
return newSampleTimestampTooOldError(model.Time(timestamp), labels)
})
Expand Down Expand Up @@ -1336,8 +1336,8 @@ func (i *Ingester) PushWithCleanup(ctx context.Context, req *mimirpb.WriteReques
}

func (i *Ingester) updateMetricsFromPushStats(userID string, group string, stats *pushStats, samplesSource mimirpb.WriteRequest_SourceEnum, db *userTSDB, discarded *discardedMetrics) {
if stats.sampleOutOfBoundsCount > 0 {
discarded.sampleOutOfBounds.WithLabelValues(userID, group).Add(float64(stats.sampleOutOfBoundsCount))
if stats.sampleTimestampTooOldCount > 0 {
discarded.sampleTimestampTooOld.WithLabelValues(userID, group).Add(float64(stats.sampleTimestampTooOldCount))
}
if stats.sampleOutOfOrderCount > 0 {
discarded.sampleOutOfOrder.WithLabelValues(userID, group).Add(float64(stats.sampleOutOfOrderCount))
Expand Down Expand Up @@ -1405,7 +1405,7 @@ func (i *Ingester) pushSamplesToAppender(userID string, timeseries []mimirpb.Pre
allOutOfBoundsHistograms(ts.Histograms, minAppendTime) {

stats.failedSamplesCount += len(ts.Samples) + len(ts.Histograms)
stats.sampleOutOfBoundsCount += len(ts.Samples) + len(ts.Histograms)
stats.sampleTimestampTooOldCount += len(ts.Samples) + len(ts.Histograms)

var firstTimestamp int64
if len(ts.Samples) > 0 {
Expand All @@ -1426,7 +1426,7 @@ func (i *Ingester) pushSamplesToAppender(userID string, timeseries []mimirpb.Pre
len(ts.Samples) > 0 && allOutOfBoundsFloats(ts.Samples, minAppendTime) {

stats.failedSamplesCount += len(ts.Samples)
stats.sampleOutOfBoundsCount += len(ts.Samples)
stats.sampleTimestampTooOldCount += len(ts.Samples)

firstTimestamp := ts.Samples[0].TimestampMs

Expand Down
8 changes: 4 additions & 4 deletions pkg/ingester/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (m *ingesterMetrics) deletePerUserCustomTrackerMetrics(userID string, custo
}

type discardedMetrics struct {
sampleOutOfBounds *prometheus.CounterVec
sampleTimestampTooOld *prometheus.CounterVec
sampleOutOfOrder *prometheus.CounterVec
sampleTooOld *prometheus.CounterVec
sampleTooFarInFuture *prometheus.CounterVec
Expand All @@ -432,7 +432,7 @@ type discardedMetrics struct {

func newDiscardedMetrics(r prometheus.Registerer) *discardedMetrics {
return &discardedMetrics{
sampleOutOfBounds: validation.DiscardedSamplesCounter(r, reasonSampleOutOfBounds),
sampleTimestampTooOld: validation.DiscardedSamplesCounter(r, reasonSampleTimestampTooOld),
sampleOutOfOrder: validation.DiscardedSamplesCounter(r, reasonSampleOutOfOrder),
sampleTooOld: validation.DiscardedSamplesCounter(r, reasonSampleTooOld),
sampleTooFarInFuture: validation.DiscardedSamplesCounter(r, reasonSampleTooFarInFuture),
Expand All @@ -444,7 +444,7 @@ func newDiscardedMetrics(r prometheus.Registerer) *discardedMetrics {
}

func (m *discardedMetrics) DeletePartialMatch(filter prometheus.Labels) {
m.sampleOutOfBounds.DeletePartialMatch(filter)
m.sampleTimestampTooOld.DeletePartialMatch(filter)
m.sampleOutOfOrder.DeletePartialMatch(filter)
m.sampleTooOld.DeletePartialMatch(filter)
m.sampleTooFarInFuture.DeletePartialMatch(filter)
Expand All @@ -455,7 +455,7 @@ func (m *discardedMetrics) DeletePartialMatch(filter prometheus.Labels) {
}

func (m *discardedMetrics) DeleteLabelValues(userID string, group string) {
m.sampleOutOfBounds.DeleteLabelValues(userID, group)
m.sampleTimestampTooOld.DeleteLabelValues(userID, group)
m.sampleOutOfOrder.DeleteLabelValues(userID, group)
m.sampleTooOld.DeleteLabelValues(userID, group)
m.sampleTooFarInFuture.DeleteLabelValues(userID, group)
Expand Down

0 comments on commit 27b7229

Please sign in to comment.