Skip to content

Commit ffe8108

Browse files
committed
Remove unused
1 parent 4a5c74f commit ffe8108

5 files changed

Lines changed: 66 additions & 498 deletions

File tree

cmd/statshouse/worker.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ import (
2121
"github.com/vkcom/statshouse/internal/metajournal"
2222
)
2323

24-
const (
25-
metricMapQueueSize = 1000
26-
)
27-
2824
type worker struct {
2925
sh2 *agent.Agent
3026
metricStorage *metajournal.MetricsStorage
@@ -131,14 +127,6 @@ func (w *worker) fillMetricMeta(args data_model.HandlerArgs, h *data_model.Mappe
131127
return false
132128
}
133129

134-
func (w *worker) handleMappedMetricUnlocked(m tlstatshouse.MetricBytes, h data_model.MappedMetricHeader) {
135-
if w.logPackets != nil {
136-
w.printMetric("uncached", m, h)
137-
}
138-
w.sh2.TimingsMappingSlow.AddValueCounter(time.Since(h.ReceiveTime).Seconds(), 1)
139-
w.sh2.ApplyMetric(m, h, format.TagValueIDSrcIngestionStatusOKUncached, nil) // will be allocation for resolution hash, but this is slow path
140-
}
141-
142130
func (w *worker) HandleParseError(pkt []byte, err error) {
143131
if w.logPackets != nil {
144132
w.logPackets("Error parsing packet: %v", err)

internal/agent/agent_loaders.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/vkcom/statshouse/internal/data_model/gen2/tlmetadata"
1616
"github.com/vkcom/statshouse/internal/data_model/gen2/tlstatshouse"
1717
"github.com/vkcom/statshouse/internal/format"
18-
"github.com/vkcom/statshouse/internal/pcache"
1918
"github.com/vkcom/statshouse/internal/vkgo/rpc"
2019
"github.com/vkcom/statshouse/internal/vkgo/srvfunc"
2120
)
@@ -101,70 +100,6 @@ func (s *Agent) LoadMetaMetricJournal(ctxParent context.Context, version int64,
101100
return ret.Events, ret.CurrentVersion, nil
102101
}
103102

104-
func (s *Agent) LoadOrCreateMapping(ctxParent context.Context, key string, floodLimitKey interface{}) (pcache.Value, time.Duration, error) {
105-
extra := rpc.InvokeReqExtra{FailIfNoConnection: true}
106-
// Use 2 alive random aggregators for mapping
107-
s0, s1 := s.getRandomLiveShardReplicas()
108-
if s0 == nil {
109-
s.AddValueCounter(0, format.BuiltinMetricMetaAgentMapping,
110-
[]int32{0, format.TagValueIDAggMappingMetaMetrics, format.TagValueIDAgentMappingStatusAllDead},
111-
0, 1)
112-
return nil, 0, fmt.Errorf("all aggregators are dead")
113-
}
114-
now := time.Now()
115-
116-
args := tlstatshouse.GetTagMapping2{
117-
Key: key,
118-
}
119-
s0.fillProxyHeader(&args.FieldsMask, &args.Header)
120-
args.SetCreate(true)
121-
122-
if floodLimitKey != nil {
123-
// cache passes nil floodLimitKey when updating existing records, so in theory, we will never need to actually create key
124-
// when extra is nil. But if we attempt to do it, will record attempts in common key for all metrics.
125-
e := floodLimitKey.(format.CreateMappingExtra)
126-
args.Metric = e.Metric
127-
args.ClientEnv = e.ClientEnv
128-
args.TagIdKey = e.TagIDKey
129-
}
130-
131-
var ret tlstatshouse.GetTagMappingResult
132-
133-
ctx, cancel := context.WithTimeout(ctxParent, data_model.AgentMappingTimeout1)
134-
defer cancel()
135-
s0client := s0.client()
136-
err := s0client.GetTagMapping2(ctx, args, &extra, &ret)
137-
if err == nil {
138-
s.AddValueCounter(0, format.BuiltinMetricMetaAgentMapping,
139-
[]int32{0, format.TagValueIDAggMappingMetaMetrics, format.TagValueIDAgentMappingStatusOKFirst},
140-
time.Since(now).Seconds(), 1)
141-
return pcache.Int32ToValue(ret.Value), time.Duration(ret.TtlNanosec), nil
142-
}
143-
if s1 == nil {
144-
s.AddValueCounter(0, format.BuiltinMetricMetaAgentMapping,
145-
[]int32{0, format.TagValueIDAggMappingMetaMetrics, format.TagValueIDAgentMappingStatusErrSingle},
146-
time.Since(now).Seconds(), 1)
147-
return nil, 0, fmt.Errorf("the only live aggregator %q returned error: %w", s0client.Address, err)
148-
}
149-
150-
s1.fillProxyHeader(&args.FieldsMask, &args.Header)
151-
152-
ctx2, cancel2 := context.WithTimeout(ctxParent, data_model.AgentMappingTimeout2)
153-
defer cancel2()
154-
s1client := s1.client()
155-
err2 := s1client.GetTagMapping2(ctx2, args, &extra, &ret)
156-
if err2 == nil {
157-
s.AddValueCounter(0, format.BuiltinMetricMetaAgentMapping,
158-
[]int32{0, format.TagValueIDAggMappingMetaMetrics, format.TagValueIDAgentMappingStatusOKSecond},
159-
time.Since(now).Seconds(), 1)
160-
return pcache.Int32ToValue(ret.Value), time.Duration(ret.TtlNanosec), nil
161-
}
162-
s.AddValueCounter(0, format.BuiltinMetricMetaAgentMapping,
163-
[]int32{0, format.TagValueIDAggMappingMetaMetrics, format.TagValueIDAgentMappingStatusErrBoth},
164-
time.Since(now).Seconds(), 1)
165-
return nil, 0, fmt.Errorf("two live aggregators %q %q returned errors: %v %w", s0client.Address, s1client.Address, err, err2)
166-
}
167-
168103
func (s *Agent) GetTagMappingBootstrap(ctxParent context.Context) ([]tlstatshouse.Mapping, time.Duration, error) {
169104
extra := rpc.InvokeReqExtra{FailIfNoConnection: true}
170105
// Use 2 alive random aggregators for mapping

internal/mapping/errors.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2025 V Kontakte LLC
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
package mapping
8+
9+
import (
10+
"fmt"
11+
"github.com/vkcom/statshouse/internal/data_model"
12+
"github.com/vkcom/statshouse/internal/data_model/gen2/tlstatshouse"
13+
"github.com/vkcom/statshouse/internal/format"
14+
)
15+
16+
func MapErrorFromHeader(m tlstatshouse.MetricBytes, h data_model.MappedMetricHeader) error {
17+
if h.IngestionStatus == 0 { // no errors
18+
return nil
19+
}
20+
ingestionTagName := format.TagIDTagToTagID(h.IngestionTagKey)
21+
envTag := h.Key.Tags[0] // TODO - we do not want to remember original string value somewhere yet (to print better errors here)
22+
switch h.IngestionStatus {
23+
case format.TagValueIDSrcIngestionStatusErrMetricNotFound:
24+
return fmt.Errorf("metric %q not found (envTag %d)", m.Name, envTag)
25+
case format.TagValueIDSrcIngestionStatusErrNanInfValue:
26+
return fmt.Errorf("NaN/Inf value for metric %q (envTag %d)", m.Name, envTag)
27+
case format.TagValueIDSrcIngestionStatusErrNanInfCounter:
28+
return fmt.Errorf("NaN/Inf counter for metric %q (envTag %d)", m.Name, envTag)
29+
case format.TagValueIDSrcIngestionStatusErrNegativeCounter:
30+
return fmt.Errorf("negative counter for metric %q (envTag %d)", m.Name, envTag)
31+
case format.TagValueIDSrcIngestionStatusErrMapOther:
32+
return nil // not written
33+
case format.TagValueIDSrcIngestionStatusErrMapInvalidRawTagValue:
34+
return fmt.Errorf("invalid raw tag value %q for key %q of metric %q (envTag %d)", h.InvalidString, ingestionTagName, m.Name, envTag)
35+
case format.TagValueIDSrcIngestionStatusErrMapTagValueCached:
36+
return fmt.Errorf("error mapping tag value (cached) %q for key %q of metric %q (envTag %d)", h.InvalidString, ingestionTagName, m.Name, envTag)
37+
case format.TagValueIDSrcIngestionStatusErrMapTagValue:
38+
return fmt.Errorf("failed to map tag value %q for key %q of metric %q (envTag %d)", h.InvalidString, ingestionTagName, m.Name, envTag)
39+
case format.TagValueIDSrcIngestionStatusErrMapGlobalQueueOverload:
40+
return fmt.Errorf("failed to map metric %q: too many metrics in queue (envTag %d)", m.Name, envTag)
41+
case format.TagValueIDSrcIngestionStatusErrMapPerMetricQueueOverload:
42+
return fmt.Errorf("failed to map metric %q: per-metric mapping queue overloaded (envTag %d)", m.Name, envTag)
43+
case format.TagValueIDSrcIngestionStatusErrMapTagValueEncoding:
44+
return fmt.Errorf("not utf-8 value %q (hex) for for key %q of metric %q (envTag %d)", h.InvalidString, ingestionTagName, m.Name, envTag)
45+
case format.TagValueIDSrcIngestionStatusOKLegacy:
46+
return nil // not written
47+
case format.TagValueIDSrcIngestionStatusErrMetricNonCanonical:
48+
return nil // not written
49+
case format.TagValueIDSrcIngestionStatusErrMetricDisabled:
50+
return fmt.Errorf("metric %q is disabled (envTag %d)", m.Name, envTag)
51+
case format.TagValueIDSrcIngestionStatusErrLegacyProtocol:
52+
return nil // not written
53+
case format.TagValueIDSrcIngestionStatusErrMetricNameEncoding:
54+
return fmt.Errorf("not utf-8 metric name %q (hex) (envTag %d)", h.InvalidString, envTag)
55+
case format.TagValueIDSrcIngestionStatusErrMapTagNameEncoding:
56+
return fmt.Errorf("not utf-8 name %q (hex) for key of metric %q (envTag %d)", h.InvalidString, m.Name, envTag)
57+
case format.TagValueIDSrcIngestionStatusErrValueUniqueBothSet:
58+
return fmt.Errorf("both value and unique fields set in metric event %q (envTag %d)", m.Name, envTag)
59+
case format.TagValueIDSrcIngestionStatusErrShardingFailed:
60+
return fmt.Errorf("metric %q shard is beyond configured shards (envTag %d)", m.Name, envTag)
61+
case format.TagValueIDSrcIngestionStatusErrMetricBuiltin:
62+
return fmt.Errorf("metric %q is builtin (envTag %d)", m.Name, envTag)
63+
default:
64+
return fmt.Errorf("unexpected error status %d with invalid string value %q for key %q of metric %q (envTag %d)", h.IngestionStatus, h.InvalidString, ingestionTagName, m.Name, envTag)
65+
}
66+
}

internal/mapping/metric_queue.go

Lines changed: 0 additions & 165 deletions
This file was deleted.

0 commit comments

Comments
 (0)