Skip to content

Commit 61be097

Browse files
authored
renames only (#2051)
1 parent 7f19222 commit 61be097

File tree

7 files changed

+46
-47
lines changed

7 files changed

+46
-47
lines changed

cmd/statshouse/statshouse-tools.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,10 @@ func massUpdateMetadata() int {
718718
//if !strings.HasPrefix(meta.Name, "gbuteyko") {
719719
// continue
720720
//}
721-
if meta.ShardStrategy == format.ShardByTagsHash || meta.ShardStrategy == format.ShardFixed || meta.ShardStrategy == format.ShardBuiltin {
721+
if meta.ShardStrategy == format.ShardByTagsHash || meta.ShardStrategy == format.ShardFixed || meta.ShardStrategy == format.ShardBuiltinDist {
722722
continue
723723
}
724-
if meta.ShardStrategy != format.ShardByMetric && meta.ShardStrategy != "" {
724+
if meta.ShardStrategy != format.ShardByMetricID && meta.ShardStrategy != "" {
725725
_, _ = fmt.Fprintf(os.Stderr, "Metric %d (%q) unexpected strategy %s shard %d\n", meta.MetricID, meta.Name, meta.ShardStrategy, meta.ShardNum)
726726
continue
727727
}

internal/agent/agent.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

internal/aggregator/migration.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func getBuiltinShardingMetrics() map[int32]int {
3838
shardingMetrics := make(map[int32]int)
3939

4040
for metricID, metric := range format.BuiltinMetrics {
41-
if metric.ShardStrategy == format.ShardBuiltin {
41+
if metric.ShardStrategy == format.ShardBuiltinDist {
4242
// For metrics with MetricTagIndex > 0, use the specified tag
4343
// For metrics with MetricTagIndex = 0 (like contributors_log), they appear in all shards
4444
if metric.MetricTagIndex > 0 {
@@ -53,7 +53,7 @@ func getBuiltinShardingMetrics() map[int32]int {
5353
}
5454

5555
// getConditionForSelect returns the complete condition for SELECT queries
56-
// This handles both regular metrics and ShardBuiltin metrics in a single query
56+
// This handles both regular metrics and ShardBuiltinDist metrics in a single query
5757
func getConditionForSelect(totalShards int, shardKey int32, tagPrefix string) string {
5858
// Get all builtin metrics with special sharding
5959
shardingMetrics := getBuiltinShardingMetrics()
@@ -84,13 +84,13 @@ func getConditionForSelect(totalShards int, shardKey int32, tagPrefix string) st
8484
}
8585

8686
// getConditionForSelectV2 returns the complete condition for SELECT queries on V2 tables
87-
// This handles both regular metrics and ShardBuiltin metrics in a single query
87+
// This handles both regular metrics and ShardBuiltinDist metrics in a single query
8888
func getConditionForSelectV2(totalShards int, shardKey int32) string {
8989
return getConditionForSelect(totalShards, shardKey, "key")
9090
}
9191

9292
// getConditionForSelectV3 returns the complete condition for SELECT queries on V3 tables
93-
// This handles both regular metrics and ShardBuiltin metrics in a single query
93+
// This handles both regular metrics and ShardBuiltinDist metrics in a single query
9494
func getConditionForSelectV3(totalShards int, shardKey int32) string {
9595
return getConditionForSelect(totalShards, shardKey, "tag")
9696
}
@@ -232,7 +232,7 @@ func migrateSingleStep(httpClient *http.Client, khAddr, khUser, khPassword strin
232232

233233
// Step 1: Select data from V2 table for the given timestamp and shard
234234
// Include all aggregate fields - our parsers handle ClickHouse internal format correctly
235-
// For ShardBuiltin metrics, we need special sharding conditions
235+
// For ShardBuiltinDist metrics, we need special sharding conditions
236236
shardingCondition := getConditionForSelectV2(config.TotalShards, shardKey)
237237
selectQuery := fmt.Sprintf(`
238238
SELECT metric, time, key0, key1, key2, key3, key4, key5, key6, key7, key8, key9, key10, key11, key12, key13, key14, key15, skey,

internal/format/builtin_metrics.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Set only if greater than 1.`,
3131
RawKind: "int",
3232
}},
3333
PreKeyTagID: "1",
34-
ShardStrategy: ShardBuiltin, // sharded the same way as metric it describes
34+
ShardStrategy: ShardBuiltinDist, // sharded the same way as metric it describes
3535
MetricTagIndex: 1,
3636
}
3737

@@ -154,7 +154,7 @@ So avg() of this metric shows estimated full cardinality with or without groupin
154154
BuiltinKind: BuiltinKindMetric,
155155
}},
156156
PreKeyTagID: "4",
157-
ShardStrategy: ShardBuiltin, // sharded the same way as metric it describes
157+
ShardStrategy: ShardBuiltinDist, // sharded the same way as metric it describes
158158
MetricTagIndex: 4,
159159
}
160160

@@ -180,7 +180,7 @@ Set only if greater than 1.`,
180180
}),
181181
}},
182182
PreKeyTagID: "4",
183-
ShardStrategy: ShardBuiltin, // sharded the same way as metrtic it describes
183+
ShardStrategy: ShardBuiltinDist, // sharded the same way as metrtic it describes
184184
MetricTagIndex: 4,
185185
}
186186

@@ -243,7 +243,7 @@ This metric uses sampling budgets of metric it refers to, so flooding by errors
243243
Description: "tag_id",
244244
}},
245245
PreKeyTagID: "1",
246-
ShardStrategy: ShardBuiltin, // sharded the same way as metrtic it describes
246+
ShardStrategy: ShardBuiltinDist, // sharded the same way as metrtic it describes
247247
MetricTagIndex: 1,
248248
}
249249

@@ -702,7 +702,7 @@ var BuiltinMetricMetaBadges = &MetricMetaValue{
702702
BuiltinKind: BuiltinKindMetric,
703703
}},
704704
PreKeyTagID: "2",
705-
ShardStrategy: ShardBuiltin, // sharded the same way as metrtic it describes
705+
ShardStrategy: ShardBuiltinDist, // sharded the same way as metrtic it describes
706706
MetricTagIndex: 2,
707707
}
708708

@@ -1062,7 +1062,7 @@ To see which seconds change when, use __contributors_log_rev`,
10621062
Description: "timestamp",
10631063
RawKind: "timestamp",
10641064
}},
1065-
ShardStrategy: ShardBuiltin, // marshalled by aggregator but does not have metric tag
1065+
ShardStrategy: ShardBuiltinDist, // marshalled by aggregator but does not have metric tag
10661066
}
10671067

10681068
const BuiltinMetricIDContributorsLogRev = -62
@@ -1081,7 +1081,7 @@ Value is delta between second value and time it was inserted.`,
10811081
Description: "insert_timestamp",
10821082
RawKind: "timestamp",
10831083
}},
1084-
ShardStrategy: ShardBuiltin, // marshalled by aggregator but does not have metric tag
1084+
ShardStrategy: ShardBuiltinDist, // marshalled by aggregator but does not have metric tag
10851085
}
10861086

10871087
var BuiltinMetricMetaGroupSizeBeforeSampling = &MetricMetaValue{

internal/format/format.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ type MetricsGroup struct {
230230

231231
// possible sharding strategies
232232
const (
233-
ShardByTagsHash = "tags_hash"
234-
ShardFixed = "fixed_shard"
235-
ShardByMetric = "metric_id" // shard = metric_id % num_shards
236-
ShardBuiltin = "builtin" // for special builtin metrics that are written in all shards (only dist)
233+
ShardByTagsHash = "tags_hash" // TODO: remove after nginx metrics are moved out to its own shard
234+
ShardFixed = "fixed_shard" // should be the only strategy for all user metrics
235+
ShardByMetricID = "metric_id" // shard = metric_id % shardByMetricCount, for most built-in and hardware metrics.
236+
ShardBuiltinDist = "builtin" // for several builtin metrics which are written by aggregator into the same shard with the metrics they describe
237237
)
238238

239239
// This struct is immutable, it is accessed by mapping code without any locking
@@ -648,7 +648,7 @@ func (metric *MetricMetaValue) NewSharding(timestamp, newShardingStart int64) bo
648648
return false
649649
}
650650
switch metric.ShardStrategy {
651-
case ShardFixed, ShardByMetric, "":
651+
case ShardFixed, ShardByMetricID, "":
652652
return newShardingStart != 0 && timestamp >= newShardingStart
653653
default:
654654
return false
@@ -662,7 +662,7 @@ func (m *MetricMetaValue) Shard(numShards int) int {
662662
switch m.ShardStrategy {
663663
case ShardFixed:
664664
return int(m.ShardNum)
665-
case ShardByMetric, "":
665+
case ShardByMetricID, "":
666666
return int(uint32(m.MetricID) % uint32(numShards))
667667
default:
668668
return -1

internal/sharding/sharding.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ func Shard(key *data_model.Key, meta *format.MetricMetaValue, shardByMetricCount
1010
switch meta.ShardStrategy {
1111
case format.ShardFixed:
1212
return meta.ShardNum
13-
case "", format.ShardByMetric:
13+
case "", format.ShardByMetricID:
1414
shard := uint32(key.Metric) % shardByMetricCount
1515
return shard
16-
case format.ShardBuiltin:
16+
case format.ShardBuiltinDist:
1717
tagIndex := meta.MetricTagIndex
1818
// for builtin metrics we always use row values
1919
metric := key.Tags[tagIndex]

internal/sharding/sharding_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestShard(t *testing.T) {
5252

5353
{"ok-by-metric-id", args{
5454
key: metric1,
55-
meta: &format.MetricMetaValue{Name: "a", ShardStrategy: format.ShardByMetric},
55+
meta: &format.MetricMetaValue{Name: "a", ShardStrategy: format.ShardByMetricID},
5656
numShards: 16,
5757
}, 1},
5858

0 commit comments

Comments
 (0)