Skip to content

Commit 4014f2f

Browse files
committed
SH-455 refactoring legacy tags
1 parent f04c446 commit 4014f2f

5 files changed

Lines changed: 74 additions & 22 deletions

File tree

cmd/statshouse-api/statshouse-api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/VKCOM/statshouse-go"
26+
"github.com/VKCOM/statshouse/internal/vkgo/srvfunc"
2627
"github.com/cloudflare/tableflip"
2728
"github.com/gorilla/handlers"
2829

@@ -35,7 +36,6 @@ import (
3536
"github.com/VKCOM/statshouse/internal/util"
3637
"github.com/VKCOM/statshouse/internal/vkgo/build"
3738
"github.com/VKCOM/statshouse/internal/vkgo/rpc"
38-
"github.com/VKCOM/statshouse/internal/vkgo/srvfunc"
3939
"github.com/VKCOM/statshouse/internal/vkgo/vkuth"
4040
)
4141

@@ -397,6 +397,7 @@ func run() int {
397397
heartbeatTags := statshouse.Tags{
398398
1: "4",
399399
2: fmt.Sprint(format.TagValueIDHeartbeatEventStart),
400+
4: fmt.Sprint(build.CommitTag()),
400401
6: fmt.Sprint(build.CommitTimestamp()),
401402
7: srvfunc.HostnameForStatshouse(),
402403
}

cmd/statshouse-igp/ingress_proxy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ func (p *proxyConn) reportRequestSize(req *proxyRequest) {
594594
1: format.TagValueIDComponentIngressProxy,
595595
2: int32(req.tag()),
596596
6: p.clientCryptoKeyID,
597+
7: p.hostnameID.Load(),
597598
8: p.clientProtocolVersion,
598599
}, float64(req.size), 1)
599600
}

internal/agent/agent.go

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,38 @@ func (s *Agent) addBuiltins(nowUnix uint32) {
662662
}
663663

664664
func (s *Agent) addBuiltInsHeartbeatsLocked(nowUnix uint32, count float64) {
665-
uptimeSec := float64(nowUnix - s.startTimestamp)
666-
667-
s.AddValueCounterString(nowUnix, &s.builtinMetricMetaHeartbeatVersion,
668-
[]int32{0, s.componentTag, s.heartBeatEventType},
665+
var (
666+
owner string
667+
uptimeSec = float64(nowUnix - s.startTimestamp)
668+
)
669+
if s.envLoader != nil {
670+
e := s.envLoader.Load()
671+
owner = e.Owner
672+
}
673+
s.AddValueCounterStringV2(nowUnix, &s.builtinMetricMetaHeartbeatVersion,
674+
[]int32{
675+
1: s.componentTag,
676+
2: s.heartBeatEventType,
677+
4: int32(build.CommitTag()),
678+
6: int32(build.CommitTimestamp()),
679+
},
680+
[]string{
681+
7: string(s.hostName),
682+
9: owner,
683+
},
669684
build.Commit(), uptimeSec, count)
670-
s.AddValueCounterString(nowUnix, &s.builtinMetricMetaHeartbeatArgs,
671-
[]int32{0, s.componentTag, s.heartBeatEventType, s.argsHash, 0, 0, 0, 0, 0, s.argsLen},
685+
s.AddValueCounterStringV2(nowUnix, &s.builtinMetricMetaHeartbeatArgs,
686+
[]int32{
687+
1: s.componentTag,
688+
2: s.heartBeatEventType,
689+
3: s.argsHash,
690+
4: int32(build.CommitTag()),
691+
6: int32(build.CommitTimestamp()),
692+
},
693+
[]string{
694+
7: string(s.hostName),
695+
9: owner,
696+
},
672697
s.args, uptimeSec, count)
673698
}
674699

@@ -945,6 +970,33 @@ func (s *Agent) AddValueCounterStringHostAERA(t uint32, metricInfo *format.Metri
945970
shard.AddValueCounterStringHost(&key, resolutionHash, topValue, value, counter, hostTag, metricInfo, weightMul)
946971
}
947972

973+
func (s *Agent) AddValueCounterStringV2(t uint32, metricInfo *format.MetricMetaValue, tags []int32, stags []string, str string, value float64, counter float64) {
974+
s.AddValueCounterStringV2HostAERA(t, metricInfo, tags, stags, data_model.TagUnion{S: str, I: 0}, value, counter, data_model.TagUnionBytes{}, format.AgentEnvRouteArch{})
975+
}
976+
977+
func (s *Agent) AddValueCounterStringV2HostAERA(t uint32, metricInfo *format.MetricMetaValue, tags []int32, stags []string, topValue data_model.TagUnion, value float64, counter float64, hostTag data_model.TagUnionBytes, aera format.AgentEnvRouteArch) {
978+
if counter <= 0 {
979+
return
980+
}
981+
key := data_model.Key{Timestamp: t, Metric: metricInfo.MetricID} // panics if metricInfo nil
982+
copy(key.Tags[:], tags)
983+
copy(key.STags[:], stags)
984+
if metricInfo.WithAggregatorID {
985+
key.Tags[format.AggHostTag] = s.AggregatorHost
986+
key.Tags[format.AggShardTag] = s.AggregatorShardKey
987+
key.Tags[format.AggReplicaTag] = s.AggregatorReplicaKey
988+
}
989+
if metricInfo.WithAgentEnvRouteArch {
990+
key.Tags[format.AgentEnvTag] = aera.AgentEnv
991+
key.Tags[format.RouteTag] = aera.Route
992+
key.Tags[format.BuildArchTag] = aera.BuildArch
993+
}
994+
shardId, _, weightMul, resolutionHash := s.shard(&key, metricInfo, nil)
995+
// resolutionHash will be 0 for built-in metrics, we are OK with this
996+
shard := s.Shards[shardId]
997+
shard.AddValueCounterStringHost(&key, resolutionHash, topValue, value, counter, hostTag, metricInfo, weightMul)
998+
}
999+
9481000
func (s *Agent) MergeItemValue(t uint32, metricInfo *format.MetricMetaValue, tags []int32, item *data_model.ItemValue) {
9491001
if item.Count() <= 0 {
9501002
return

internal/aggregator/aggregator_handlers.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ func (a *Aggregator) handleClient(ctx context.Context, hctx *rpc.HandlerContext)
5050
str = err.Error()
5151
}
5252
a.sh2.AddValueCounterString(uint32(hctx.RequestTime.Unix()), format.BuiltinMetricMetaRPCRequests,
53-
[]int32{0, format.TagValueIDComponentAggregator, int32(tag), status, 0, 0, keyIDTag, 0, protocol},
54-
str, float64(requestLen), 1)
53+
[]int32{
54+
1: format.TagValueIDComponentAggregator,
55+
2: int32(tag),
56+
3: status,
57+
6: keyIDTag,
58+
7: a.aggregatorHost,
59+
8: protocol,
60+
}, str, float64(requestLen), 1)
5561
return err
5662
}
5763

@@ -502,17 +508,12 @@ func (a *Aggregator) handleSendSourceBucketAny(hctx *rpc.HandlerContext, args tl
502508
k.Tags[format.RouteTag] = aera.Route
503509
k.Tags[format.BuildArchTag] = aera.BuildArch
504510
}
511+
if k.Metric == format.BuiltinMetricIDHeartbeatVersion || k.Metric == format.BuiltinMetricIDHeartbeatArgs {
512+
k.Tags[8] = int32(addrIPV4)
513+
}
514+
515+
// TODO - remove
505516
switch k.Metric {
506-
case format.BuiltinMetricIDAgentHeartbeatVersion:
507-
// Remap legacy metric to a new one
508-
k.Metric = format.BuiltinMetricIDHeartbeatVersion
509-
k.Tags[2] = k.Tags[1]
510-
k.Tags[1] = format.TagValueIDComponentAgent
511-
case format.BuiltinMetricIDAgentHeartbeatArgs:
512-
// Remap legacy metric to a new one
513-
k.Metric = format.BuiltinMetricIDHeartbeatArgs
514-
k.Tags[2] = k.Tags[1]
515-
k.Tags[1] = format.TagValueIDComponentAgent
516517
case format.BuiltinMetricIDHeartbeatVersion, format.BuiltinMetricIDHeartbeatArgs:
517518
// In case of agent we need to set IP anyway, so set other keys here, not by source
518519
// In case of api other tags are already set, so don't overwrite them

internal/format/builtin_metrics.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,6 @@ var BuiltinMetricMetaPromScrapeTime = &MetricMetaValue{
806806
},
807807
}
808808

809-
const BuiltinMetricIDAgentHeartbeatVersion = -41 // TODO - remove
810-
const BuiltinMetricIDAgentHeartbeatArgs = -42 // TODO - remove, this metric was writing larger than allowed strings to DB in the past
811-
812809
var BuiltinMetricMetaUsageMemory = &MetricMetaValue{
813810
Name: "__usage_mem",
814811
Kind: MetricKindValue,

0 commit comments

Comments
 (0)