@@ -760,29 +760,29 @@ func (s *Agent) ApplyMetric(m tlstatshouse.MetricBytes, h data_model.MappedMetri
760760 // Simply writing everything we know about metric ingestion errors would easily double how much metrics data we write
761761 // So below is basically a compromise. All info is stored in MappingMetricHeader, if needed we can easily write more
762762 // by changing code below
763- //var shardId uint32
764- //weightMul := 1
765- //if h.MetricMeta != nil {
766- // ingestion statuses for unknown metric (metric not found) go to the first shard.
767- // for known metric, go to shard together with metric
768- //shardId, weightMul = s.shard(&h.Key, h.MetricMeta, scratch)
769- //}
770- if h .IngestionStatus != 0 {
771- // h.InvalidString was validated before mapping attempt.
772- // In case of utf decoding error, it contains hex representation of original string
773- s .AddCounterStringBytes (0 , format .BuiltinMetricMetaIngestionStatus ,
774- []int32 {h .Key .Tags [0 ], h .Key .Metric , h .IngestionStatus , h .IngestionTagKey },
775- h .InvalidString , 1 )
776- return
763+ var shardId uint32
764+ if h .MetricMeta != nil {
765+ // ingestion statuses for unknown metric (metric not found) go to the first shard.
766+ // for known metric with fixed shard, go to shard together with metric
767+ // for known metric with hash_by_tags strategy, go to random shard together with metric
768+ shardId = s .shard (& h .Key , h .MetricMeta , scratch )
777769 }
778- shardId := s .shard (& h .Key , h .MetricMeta , scratch )
779770 if shardId >= uint32 (len (s .Shards )) {
780- s .AddCounter (0 , format .BuiltinMetricMetaIngestionStatus ,
771+ shard := s .Shards [0 ]
772+ shard .AddCounterHostSrcIngestionStatus (0 , format .BuiltinMetricMetaIngestionStatus ,
781773 []int32 {h .Key .Tags [0 ], h .Key .Metric , format .TagValueIDSrcIngestionStatusErrShardingFailed , 0 },
782774 1 )
783775 return
784776 }
785777 shard := s .Shards [shardId ]
778+ if h .IngestionStatus != 0 {
779+ // h.InvalidString was validated before mapping attempt.
780+ // In case of utf decoding error, it contains hex representation of original string
781+ shard .AddCounterHostStringBytesSrcIngestionStatus (0 , format .BuiltinMetricMetaIngestionStatus ,
782+ []int32 {h .Key .Tags [0 ], h .Key .Metric , h .IngestionStatus , h .IngestionTagKey },
783+ h .InvalidString , 1 )
784+ return
785+ }
786786 var resolutionHash uint64
787787 if h .MetricMeta .EffectiveResolution != 1 { // sharding by metric and need resolution hash
788788 var scr []byte
@@ -799,36 +799,36 @@ func (s *Agent) ApplyMetric(m tlstatshouse.MetricBytes, h data_model.MappedMetri
799799 s .TimingsApplyMetric .AddValueCounter (time .Since (start ).Seconds (), 1 )
800800 }()
801801 // now set ok status
802- s . AddCounter (0 , format .BuiltinMetricMetaIngestionStatus ,
802+ shard . AddCounterHostSrcIngestionStatus (0 , format .BuiltinMetricMetaIngestionStatus ,
803803 []int32 {h .Key .Tags [0 ], h .Key .Metric , format .TagValueIDSrcIngestionStatusOKCached , h .IngestionTagKey },
804804 1 )
805805 // now set all warnings
806806 if h .NotFoundTagName != nil { // this is correct, can be set, but empty
807807 // NotFoundTagName is validated when discovered
808808 // This is warning, so written independent of ingestion status
809- s . AddCounterStringBytes (0 , format .BuiltinMetricMetaIngestionStatus ,
809+ shard . AddCounterHostStringBytesSrcIngestionStatus (0 , format .BuiltinMetricMetaIngestionStatus ,
810810 []int32 {h .Key .Tags [0 ], h .Key .Metric , format .TagValueIDSrcIngestionStatusWarnMapTagNameNotFound }, // tag ID not known
811811 h .NotFoundTagName , 1 )
812812 }
813813 if h .FoundDraftTagName != nil { // this is correct, can be set, but empty
814814 // FoundDraftTagName is validated when discovered
815815 // This is warning, so written independent of ingestion status
816- s . AddCounterStringBytes (0 , format .BuiltinMetricMetaIngestionStatus ,
816+ shard . AddCounterHostStringBytesSrcIngestionStatus (0 , format .BuiltinMetricMetaIngestionStatus ,
817817 []int32 {h .Key .Tags [0 ], h .Key .Metric , format .TagValueIDSrcIngestionStatusWarnMapTagNameFoundDraft }, // tag ID is known, but draft
818818 h .FoundDraftTagName , 1 )
819819 }
820820 if h .TagSetTwiceKey != 0 {
821- s . AddCounter (0 , format .BuiltinMetricMetaIngestionStatus ,
821+ shard . AddCounterHostSrcIngestionStatus (0 , format .BuiltinMetricMetaIngestionStatus ,
822822 []int32 {h .Key .Tags [0 ], h .Key .Metric , format .TagValueIDSrcIngestionStatusWarnMapTagSetTwice , h .TagSetTwiceKey },
823823 1 )
824824 }
825825 if h .InvalidRawTagKey != 0 {
826- s . AddCounterStringBytes (0 , format .BuiltinMetricMetaIngestionStatus ,
826+ shard . AddCounterHostStringBytesSrcIngestionStatus (0 , format .BuiltinMetricMetaIngestionStatus ,
827827 []int32 {h .Key .Tags [0 ], h .Key .Metric , format .TagValueIDSrcIngestionStatusWarnMapInvalidRawTagValue , h .InvalidRawTagKey },
828828 h .InvalidRawValue , 1 )
829829 }
830830 if h .LegacyCanonicalTagKey != 0 {
831- s . AddCounter (0 , format .BuiltinMetricMetaIngestionStatus ,
831+ shard . AddCounterHostSrcIngestionStatus (0 , format .BuiltinMetricMetaIngestionStatus ,
832832 []int32 {h .Key .Tags [0 ], h .Key .Metric , format .TagValueIDSrcIngestionStatusWarnDeprecatedKeyName , h .LegacyCanonicalTagKey },
833833 1 )
834834 }
0 commit comments