@@ -1122,19 +1122,21 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
11221122 // Keep track of some stats which are tracked only if the samples will be
11231123 // successfully committed
11241124 var (
1125- succeededSamplesCount = 0
1126- failedSamplesCount = 0
1127- succeededExemplarsCount = 0
1128- failedExemplarsCount = 0
1129- startAppend = time .Now ()
1130- sampleOutOfBoundsCount = 0
1131- sampleOutOfOrderCount = 0
1132- sampleTooOldCount = 0
1133- newValueForTimestampCount = 0
1134- perUserSeriesLimitCount = 0
1135- perLabelSetSeriesLimitCount = 0
1136- perMetricSeriesLimitCount = 0
1137- nativeHistogramCount = 0
1125+ succeededSamplesCount = 0
1126+ failedSamplesCount = 0
1127+ succeededHistogramsCount = 0
1128+ failedHistogramsCount = 0
1129+ succeededExemplarsCount = 0
1130+ failedExemplarsCount = 0
1131+ startAppend = time .Now ()
1132+ sampleOutOfBoundsCount = 0
1133+ sampleOutOfOrderCount = 0
1134+ sampleTooOldCount = 0
1135+ newValueForTimestampCount = 0
1136+ perUserSeriesLimitCount = 0
1137+ perLabelSetSeriesLimitCount = 0
1138+ perMetricSeriesLimitCount = 0
1139+ discardedNativeHistogramCount = 0
11381140
11391141 updateFirstPartial = func (errFn func () error ) {
11401142 if firstPartialErr == nil {
@@ -1215,6 +1217,8 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
12151217
12161218 // To find out if any sample was added to this series, we keep old value.
12171219 oldSucceededSamplesCount := succeededSamplesCount
1220+ // To find out if any histogram was added to this series, we keep old value.
1221+ oldSucceededHistogramsCount := succeededHistogramsCount
12181222
12191223 for _ , s := range ts .Samples {
12201224 var err error
@@ -1266,19 +1270,19 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
12661270
12671271 if ref != 0 {
12681272 if _ , err = app .AppendHistogram (ref , copiedLabels , hp .TimestampMs , h , fh ); err == nil {
1269- succeededSamplesCount ++
1273+ succeededHistogramsCount ++
12701274 continue
12711275 }
12721276 } else {
12731277 // Copy the label set because both TSDB and the active series tracker may retain it.
12741278 copiedLabels = cortexpb .FromLabelAdaptersToLabelsWithCopy (ts .Labels )
12751279 if ref , err = app .AppendHistogram (0 , copiedLabels , hp .TimestampMs , h , fh ); err == nil {
1276- succeededSamplesCount ++
1280+ succeededHistogramsCount ++
12771281 continue
12781282 }
12791283 }
12801284
1281- failedSamplesCount ++
1285+ failedHistogramsCount ++
12821286
12831287 if rollback := handleAppendFailure (err , hp .TimestampMs , ts .Labels , copiedLabels ); ! rollback {
12841288 continue
@@ -1290,12 +1294,12 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
12901294 return nil , wrapWithUser (err , userID )
12911295 }
12921296 } else {
1293- nativeHistogramCount += len (ts .Histograms )
1297+ discardedNativeHistogramCount += len (ts .Histograms )
12941298 }
1295-
1296- if i .cfg .ActiveSeriesMetricsEnabled && succeededSamplesCount > oldSucceededSamplesCount {
1299+ shouldUpdateSeries := ( succeededSamplesCount > oldSucceededSamplesCount ) || ( succeededHistogramsCount > oldSucceededHistogramsCount )
1300+ if i .cfg .ActiveSeriesMetricsEnabled && shouldUpdateSeries {
12971301 db .activeSeries .UpdateSeries (tsLabels , tsLabelsHash , startAppend , func (l labels.Labels ) labels.Labels {
1298- // we must already have copied the labels if succeededSamplesCount has been incremented.
1302+ // we must already have copied the labels if succeededSamplesCount or succeededHistogramsCount has been incremented.
12991303 return copiedLabels
13001304 })
13011305 }
@@ -1343,8 +1347,8 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
13431347 }
13441348 i .TSDBState .appenderCommitDuration .Observe (time .Since (startCommit ).Seconds ())
13451349
1346- // If only invalid samples are pushed, don't change "last update", as TSDB was not modified.
1347- if succeededSamplesCount > 0 {
1350+ // If only invalid samples or histograms are pushed, don't change "last update", as TSDB was not modified.
1351+ if succeededSamplesCount > 0 || succeededHistogramsCount > 0 {
13481352 db .setLastUpdate (time .Now ())
13491353 }
13501354
@@ -1353,6 +1357,8 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
13531357 // which will be converted into an HTTP 5xx and the client should/will retry.
13541358 i .metrics .ingestedSamples .Add (float64 (succeededSamplesCount ))
13551359 i .metrics .ingestedSamplesFail .Add (float64 (failedSamplesCount ))
1360+ i .metrics .ingestedHistograms .Add (float64 (succeededHistogramsCount ))
1361+ i .metrics .ingestedHistogramsFail .Add (float64 (failedHistogramsCount ))
13561362 i .metrics .ingestedExemplars .Add (float64 (succeededExemplarsCount ))
13571363 i .metrics .ingestedExemplarsFail .Add (float64 (failedExemplarsCount ))
13581364
@@ -1378,20 +1384,20 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
13781384 i .validateMetrics .DiscardedSamples .WithLabelValues (perLabelsetSeriesLimit , userID ).Add (float64 (perLabelSetSeriesLimitCount ))
13791385 }
13801386
1381- if ! i .cfg .BlocksStorageConfig .TSDB .EnableNativeHistograms && nativeHistogramCount > 0 {
1382- i .validateMetrics .DiscardedSamples .WithLabelValues (nativeHistogramSample , userID ).Add (float64 (nativeHistogramCount ))
1387+ if ! i .cfg .BlocksStorageConfig .TSDB .EnableNativeHistograms && discardedNativeHistogramCount > 0 {
1388+ i .validateMetrics .DiscardedSamples .WithLabelValues (nativeHistogramSample , userID ).Add (float64 (discardedNativeHistogramCount ))
13831389 }
13841390
13851391 // Distributor counts both samples, metadata and histograms, so for consistency ingester does the same.
1386- i .ingestionRate .Add (int64 (succeededSamplesCount + ingestedMetadata ))
1392+ i .ingestionRate .Add (int64 (succeededSamplesCount + succeededHistogramsCount + ingestedMetadata ))
13871393
13881394 switch req .Source {
13891395 case cortexpb .RULE :
1390- db .ingestedRuleSamples .Add (int64 (succeededSamplesCount ))
1396+ db .ingestedRuleSamples .Add (int64 (succeededSamplesCount + succeededHistogramsCount ))
13911397 case cortexpb .API :
13921398 fallthrough
13931399 default :
1394- db .ingestedAPISamples .Add (int64 (succeededSamplesCount ))
1400+ db .ingestedAPISamples .Add (int64 (succeededSamplesCount + succeededHistogramsCount ))
13951401 }
13961402
13971403 if firstPartialErr != nil {
@@ -1400,7 +1406,7 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
14001406 if errors .As (firstPartialErr , & ve ) {
14011407 code = ve .code
14021408 }
1403- level .Debug (logutil .WithContext (ctx , i .logger )).Log ("msg" , "partial failures to push" , "totalSamples" , succeededSamplesCount + failedSamplesCount , "failedSamples" , failedSamplesCount , "firstPartialErr" , firstPartialErr )
1409+ level .Debug (logutil .WithContext (ctx , i .logger )).Log ("msg" , "partial failures to push" , "totalSamples" , succeededSamplesCount + failedSamplesCount , "failedSamples" , failedSamplesCount , "totalHistograms" , succeededHistogramsCount + failedHistogramsCount , "failedHistograms" , failedHistogramsCount , " firstPartialErr" , firstPartialErr )
14041410 return & cortexpb.WriteResponse {}, httpgrpc .Errorf (code , wrapWithUser (firstPartialErr , userID ).Error ())
14051411 }
14061412
0 commit comments