@@ -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+ succeededHistogramCount = 0
1128+ failedHistogramCount = 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 {
@@ -1213,8 +1215,10 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
12131215 tsLabelsHash := tsLabels .Hash ()
12141216 ref , copiedLabels := app .GetRef (tsLabels , tsLabelsHash )
12151217
1216- // To find out if any sample was added to this series, we keep old value.
1218+ // To find out if any sample was added to this series, we keep fold value.
12171219 oldSucceededSamplesCount := succeededSamplesCount
1220+ // To find out if any histogram was added to this series, we keep old value.
1221+ oldSucceededHistogramsCount := succeededHistogramCount
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+ succeededHistogramCount ++
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+ succeededHistogramCount ++
12771281 continue
12781282 }
12791283 }
12801284
1281- failedSamplesCount ++
1285+ failedHistogramCount ++
12821286
12831287 if rollback := handleAppendFailure (err , hp .TimestampMs , ts .Labels , copiedLabels ); ! rollback {
12841288 continue
@@ -1290,7 +1294,7 @@ 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 }
12951299
12961300 if i .cfg .ActiveSeriesMetricsEnabled && succeededSamplesCount > oldSucceededSamplesCount {
@@ -1300,6 +1304,13 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
13001304 })
13011305 }
13021306
1307+ if i .cfg .ActiveSeriesMetricsEnabled && succeededHistogramCount > oldSucceededHistogramsCount {
1308+ db .activeSeries .UpdateSeries (tsLabels , tsLabelsHash , startAppend , func (l labels.Labels ) labels.Labels {
1309+ // we must already have copied the labels if succeededHistogramCount has been incremented.
1310+ return copiedLabels
1311+ })
1312+ }
1313+
13031314 maxExemplarsForUser := i .getMaxExemplars (userID )
13041315 if maxExemplarsForUser > 0 {
13051316 // app.AppendExemplar currently doesn't create the series, it must
@@ -1344,7 +1355,7 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
13441355 i .TSDBState .appenderCommitDuration .Observe (time .Since (startCommit ).Seconds ())
13451356
13461357 // If only invalid samples are pushed, don't change "last update", as TSDB was not modified.
1347- if succeededSamplesCount > 0 {
1358+ if succeededSamplesCount > 0 || succeededHistogramCount > 0 {
13481359 db .setLastUpdate (time .Now ())
13491360 }
13501361
@@ -1353,6 +1364,8 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
13531364 // which will be converted into an HTTP 5xx and the client should/will retry.
13541365 i .metrics .ingestedSamples .Add (float64 (succeededSamplesCount ))
13551366 i .metrics .ingestedSamplesFail .Add (float64 (failedSamplesCount ))
1367+ i .metrics .ingestedHistograms .Add (float64 (succeededHistogramCount ))
1368+ i .metrics .ingestedHistogramsFail .Add (float64 (failedHistogramCount ))
13561369 i .metrics .ingestedExemplars .Add (float64 (succeededExemplarsCount ))
13571370 i .metrics .ingestedExemplarsFail .Add (float64 (failedExemplarsCount ))
13581371
@@ -1378,20 +1391,20 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
13781391 i .validateMetrics .DiscardedSamples .WithLabelValues (perLabelsetSeriesLimit , userID ).Add (float64 (perLabelSetSeriesLimitCount ))
13791392 }
13801393
1381- if ! i .cfg .BlocksStorageConfig .TSDB .EnableNativeHistograms && nativeHistogramCount > 0 {
1382- i .validateMetrics .DiscardedSamples .WithLabelValues (nativeHistogramSample , userID ).Add (float64 (nativeHistogramCount ))
1394+ if ! i .cfg .BlocksStorageConfig .TSDB .EnableNativeHistograms && discardedNativeHistogramCount > 0 {
1395+ i .validateMetrics .DiscardedSamples .WithLabelValues (nativeHistogramSample , userID ).Add (float64 (discardedNativeHistogramCount ))
13831396 }
13841397
13851398 // Distributor counts both samples, metadata and histograms, so for consistency ingester does the same.
1386- i .ingestionRate .Add (int64 (succeededSamplesCount + ingestedMetadata ))
1399+ i .ingestionRate .Add (int64 (succeededSamplesCount + succeededHistogramCount + ingestedMetadata ))
13871400
13881401 switch req .Source {
13891402 case cortexpb .RULE :
13901403 db .ingestedRuleSamples .Add (int64 (succeededSamplesCount ))
13911404 case cortexpb .API :
13921405 fallthrough
13931406 default :
1394- db .ingestedAPISamples .Add (int64 (succeededSamplesCount ))
1407+ db .ingestedAPISamples .Add (int64 (succeededSamplesCount + succeededHistogramCount ))
13951408 }
13961409
13971410 if firstPartialErr != nil {
@@ -1400,7 +1413,7 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
14001413 if errors .As (firstPartialErr , & ve ) {
14011414 code = ve .code
14021415 }
1403- level .Debug (logutil .WithContext (ctx , i .logger )).Log ("msg" , "partial failures to push" , "totalSamples" , succeededSamplesCount + failedSamplesCount , "failedSamples" , failedSamplesCount , "firstPartialErr" , firstPartialErr )
1416+ level .Debug (logutil .WithContext (ctx , i .logger )).Log ("msg" , "partial failures to push" , "totalSamples" , succeededSamplesCount + succeededHistogramCount + failedSamplesCount + failedHistogramCount , "failedSamples" , failedSamplesCount , "failedHistogram" , failedHistogramCount , "firstPartialErr" , firstPartialErr )
14041417 return & cortexpb.WriteResponse {}, httpgrpc .Errorf (code , wrapWithUser (firstPartialErr , userID ).Error ())
14051418 }
14061419
0 commit comments