@@ -683,9 +683,9 @@ func (s *Agent) addBuiltInsHeartbeatsLocked(nowUnix uint32, count float64) {
683683 }
684684 vKey .STags [9 ] = owner
685685
686- vShardId := s .shard (& vKey , & s .builtinMetricMetaHeartbeatVersion , nil )
686+ vShardNum := s .shard (& vKey , & s .builtinMetricMetaHeartbeatVersion , nil )
687687 // resolutionHash will be 0 for built-in metrics, we are OK with this
688- vShard := s .Shards [vShardId ]
688+ vShard := s .Shards [vShardNum ]
689689 vShard .AddValueCounterStringHost (& vKey , 0 , data_model.TagUnion {S : build .Commit ()}, uptimeSec , count , data_model.TagUnionBytes {}, & s .builtinMetricMetaHeartbeatVersion )
690690
691691 aKey := data_model.Key {
@@ -697,9 +697,9 @@ func (s *Agent) addBuiltInsHeartbeatsLocked(nowUnix uint32, count float64) {
697697 aKey .Tags [3 ] = s .argsHash
698698 aKey .Tags [9 ] = s .argsLen
699699
700- aShardId := s .shard (& aKey , & s .builtinMetricMetaHeartbeatArgs , nil )
700+ aShardNum := s .shard (& aKey , & s .builtinMetricMetaHeartbeatArgs , nil )
701701 // resolutionHash will be 0 for built-in metrics, we are OK with this
702- aShard := s .Shards [aShardId ]
702+ aShard := s .Shards [aShardNum ]
703703 aShard .AddValueCounterStringHost (& aKey , 0 , data_model.TagUnion {S : s .args }, uptimeSec , count , data_model.TagUnionBytes {}, & s .builtinMetricMetaHeartbeatArgs )
704704}
705705
@@ -760,21 +760,20 @@ 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
763+ shard := s . Shards [ 0 ]
764764 if h .MetricMeta != nil {
765765 // ingestion statuses for unknown metric (metric not found) go to the first shard.
766766 // for known metric with fixed shard, go to shard together with metric
767767 // for known metric with hash_by_tags strategy, go to random shard together with metric
768- shardId = s .shard (& h .Key , h .MetricMeta , scratch )
769- }
770- if shardId >= uint32 ( len ( s . Shards )) {
771- shard := s . Shards [0 ]
772- shard . AddCounterHostSrcIngestionStatus ( 0 , format . BuiltinMetricMetaIngestionStatus ,
773- [] int32 { h . Key . Tags [ 0 ], h . Key . Metric , format . TagValueIDSrcIngestionStatusErrShardingFailed , 0 },
774- 1 )
775- return
768+ shardNum : = s .shard (& h .Key , h .MetricMeta , scratch )
769+ if shardNum >= uint32 ( len ( s . Shards )) {
770+ shard . AddCounterHostSrcIngestionStatus ( 0 , format . BuiltinMetricMetaIngestionStatus ,
771+ [] int32 { h . Key . Tags [0 ], h . Key . Metric , format . TagValueIDSrcIngestionStatusErrShardingFailed , 0 },
772+ 1 )
773+ return
774+ }
775+ shard = s . Shards [ shardNum ]
776776 }
777- shard := s .Shards [shardId ]
778777 if h .IngestionStatus != 0 {
779778 // h.InvalidString was validated before mapping attempt.
780779 // In case of utf decoding error, it contains hex representation of original string
@@ -892,9 +891,9 @@ func (s *Agent) AddCounterHostAERA(t uint32, metricInfo *format.MetricMetaValue,
892891 key .Tags [format .RouteTag ] = aera .Route
893892 key .Tags [format .BuildArchTag ] = aera .BuildArch
894893 }
895- shardId := s .shard (& key , metricInfo , nil )
894+ shardNum := s .shard (& key , metricInfo , nil )
896895 // resolutionHash will be 0 for built-in metrics, we are OK with this
897- shard := s .Shards [shardId ]
896+ shard := s .Shards [shardNum ]
898897 shard .AddCounterHost (& key , 0 , count , hostTag , metricInfo )
899898}
900899
@@ -920,9 +919,9 @@ func (s *Agent) AddCounterHostStringBytesAERA(t uint32, metricInfo *format.Metri
920919 key .Tags [format .RouteTag ] = aera .Route
921920 key .Tags [format .BuildArchTag ] = aera .BuildArch
922921 }
923- shardId := s .shard (& key , metricInfo , nil )
922+ shardNum := s .shard (& key , metricInfo , nil )
924923 // resolutionHash will be 0 for built-in metrics, we are OK with this
925- shard := s .Shards [shardId ]
924+ shard := s .Shards [shardNum ]
926925 shard .AddCounterHostStringBytes (& key , 0 , data_model.TagUnionBytes {S : str , I : 0 }, count , hostTag , metricInfo )
927926}
928927
@@ -951,9 +950,9 @@ func (s *Agent) AddValueCounterHostAERA(t uint32, metricInfo *format.MetricMetaV
951950 key .Tags [format .RouteTag ] = aera .Route
952951 key .Tags [format .BuildArchTag ] = aera .BuildArch
953952 }
954- shardId := s .shard (& key , metricInfo , nil )
953+ shardNum := s .shard (& key , metricInfo , nil )
955954 // resolutionHash will be 0 for built-in metrics, we are OK with this
956- shard := s .Shards [shardId ]
955+ shard := s .Shards [shardNum ]
957956 shard .AddValueCounterHost (& key , 0 , value , counter , hostTag , metricInfo )
958957}
959958
@@ -978,9 +977,9 @@ func (s *Agent) AddValueCounterStringHostAERA(t uint32, metricInfo *format.Metri
978977 key .Tags [format .RouteTag ] = aera .Route
979978 key .Tags [format .BuildArchTag ] = aera .BuildArch
980979 }
981- shardId := s .shard (& key , metricInfo , nil )
980+ shardNum := s .shard (& key , metricInfo , nil )
982981 // resolutionHash will be 0 for built-in metrics, we are OK with this
983- shard := s .Shards [shardId ]
982+ shard := s .Shards [shardNum ]
984983 shard .AddValueCounterStringHost (& key , 0 , topValue , value , counter , hostTag , metricInfo )
985984}
986985
@@ -995,9 +994,9 @@ func (s *Agent) MergeItemValue(t uint32, metricInfo *format.MetricMetaValue, tag
995994 key .Tags [format .AggShardTag ] = s .AggregatorShardKey
996995 key .Tags [format .AggReplicaTag ] = s .AggregatorReplicaKey
997996 }
998- shardId := s .shard (& key , metricInfo , nil )
997+ shardNum := s .shard (& key , metricInfo , nil )
999998 // resolutionHash will be 0 for built-in metrics, we are OK with this
1000- shard := s .Shards [shardId ]
999+ shard := s .Shards [shardNum ]
10011000 shard .MergeItemValue (& key , 0 , item , metricInfo )
10021001}
10031002
0 commit comments