@@ -706,7 +706,7 @@ func (d *Distributor) prepareSeriesKeysV2(ctx context.Context, req *cortexpbv2.W
706
706
return seriesKeys , validatedTimeseries , int64 (validatedMetadata ), int64 (validatedFloatSamples ), int64 (validatedHistogramSamples ), int64 (validatedExemplars ), firstPartialErr , nil
707
707
}
708
708
709
- func (d * Distributor ) doBatchV2 (ctx context.Context , req * cortexpbv2.WriteRequest , subRing ring.ReadRing , keys []uint32 , validatedTimeseries []cortexpbv2.TimeSeries , userID string ) error {
709
+ func (d * Distributor ) doBatchV2 (ctx context.Context , req * cortexpbv2.WriteRequest , subRing ring.ReadRing , keys []uint32 , validatedTimeseries []cortexpbv2.TimeSeries , userID string , stats * WriteStats ) error {
710
710
span , _ := opentracing .StartSpanFromContext (ctx , "doBatchV2" )
711
711
defer span .Finish ()
712
712
@@ -736,13 +736,13 @@ func (d *Distributor) doBatchV2(ctx context.Context, req *cortexpbv2.WriteReques
736
736
timeseries = append (timeseries , validatedTimeseries [i ])
737
737
}
738
738
739
- return d .sendV2 (localCtx , req .Symbols , ingester , timeseries , req .Source )
739
+ return d .sendV2 (localCtx , req .Symbols , ingester , timeseries , req .Source , stats )
740
740
}, func () {
741
741
cancel ()
742
742
})
743
743
}
744
744
745
- func (d * Distributor ) sendV2 (ctx context.Context , symbols []string , ingester ring.InstanceDesc , timeseries []cortexpbv2.TimeSeries , source cortexpbv2.WriteRequest_SourceEnum ) error {
745
+ func (d * Distributor ) sendV2 (ctx context.Context , symbols []string , ingester ring.InstanceDesc , timeseries []cortexpbv2.TimeSeries , source cortexpbv2.WriteRequest_SourceEnum , stats * WriteStats ) error {
746
746
h , err := d .ingesterPool .GetClientFor (ingester .Addr )
747
747
if err != nil {
748
748
return err
@@ -760,7 +760,7 @@ func (d *Distributor) sendV2(ctx context.Context, symbols []string, ingester rin
760
760
req .Timeseries = timeseries
761
761
req .Source = source
762
762
763
- _ , err = c .PushV2 (ctx , & req )
763
+ resp , err : = c .PushV2 (ctx , & req )
764
764
765
765
if len (timeseries ) > 0 {
766
766
d .ingesterAppends .WithLabelValues (id , typeSamples ).Inc ()
@@ -774,6 +774,13 @@ func (d *Distributor) sendV2(ctx context.Context, symbols []string, ingester rin
774
774
}
775
775
}
776
776
777
+ if resp != nil {
778
+ // track stats
779
+ stats .SetSamples (resp .Samples )
780
+ stats .SetHistograms (resp .Histograms )
781
+ stats .SetExemplars (resp .Exemplars )
782
+ }
783
+
777
784
return err
778
785
}
779
786
@@ -885,7 +892,6 @@ func (d *Distributor) PushV2(ctx context.Context, req *cortexpbv2.WriteRequest)
885
892
}
886
893
887
894
if d .cfg .InstanceLimits .MaxIngestionRate > 0 {
888
- fmt .Println ("V2 d.ingestionRate.Rate()" , d .ingestionRate .Rate ())
889
895
if rate := d .ingestionRate .Rate (); rate >= d .cfg .InstanceLimits .MaxIngestionRate {
890
896
return nil , errMaxSamplesPushRateLimitReached
891
897
}
@@ -935,13 +941,20 @@ func (d *Distributor) PushV2(ctx context.Context, req *cortexpbv2.WriteRequest)
935
941
936
942
keys := seriesKeys
937
943
938
- err = d .doBatchV2 (ctx , req , subRing , keys , validatedTimeseries , userID )
944
+ s := WriteStats {}
945
+
946
+ err = d .doBatchV2 (ctx , req , subRing , keys , validatedTimeseries , userID , & s )
939
947
if err != nil {
940
948
return nil , err
941
949
}
942
950
943
- // TODO(Sungjin1212) track stat
944
- return & cortexpbv2.WriteResponse {}, firstPartialErr
951
+ resp := & cortexpbv2.WriteResponse {
952
+ Samples : s .LoadSamples (),
953
+ Histograms : s .LoadHistogram (),
954
+ Exemplars : s .LoadExemplars (),
955
+ }
956
+
957
+ return resp , firstPartialErr
945
958
}
946
959
947
960
// Push implements client.IngesterServer
@@ -981,7 +994,6 @@ func (d *Distributor) Push(ctx context.Context, req *cortexpb.WriteRequest) (*co
981
994
}
982
995
983
996
if d .cfg .InstanceLimits .MaxIngestionRate > 0 {
984
- fmt .Println ("V1 d.ingestionRate.Rate()" , d .ingestionRate .Rate ())
985
997
if rate := d .ingestionRate .Rate (); rate >= d .cfg .InstanceLimits .MaxIngestionRate {
986
998
return nil , errMaxSamplesPushRateLimitReached
987
999
}
0 commit comments