-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmapped_metric_header.go
76 lines (63 loc) · 3.04 KB
/
mapped_metric_header.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2022 V Kontakte LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package data_model
import (
"time"
"github.com/vkcom/statshouse/internal/data_model/gen2/tlstatshouse"
"github.com/vkcom/statshouse/internal/format"
)
type HandlerArgs struct {
MetricBytes *tlstatshouse.MetricBytes
Description string
ScrapeInterval int
MapCallback MapCallbackFunc
FromStatsHouse bool // mark metric which is produced by agent but used our common metric flow (host metrics)
}
type MapCallbackFunc func(tlstatshouse.MetricBytes, MappedMetricHeader)
type MappedMetricHeader struct {
ReceiveTime time.Time // Saved at mapping start and used where we need time.Now. This is different to MetricBatch.T, which is sent by clients
MetricInfo *format.MetricMetaValue
Key Key
SValue []byte // reference to memory inside tlstatshouse.MetricBytes.
HostTag int32
CheckedTagIndex int // we check tags one by one, remembering position here, between invocations of mapTags
ValuesChecked bool // infs, nans, etc. This might be expensive, so done only once
IsKeySet [format.MaxTags]bool // report setting keys more than once.
IsSKeySet bool
IsHKeySet bool
// errors below
IngestionStatus int32 // if error happens, this will be != 0. errors are in fast path, so there must be no allocations
InvalidString []byte // reference to memory inside tlstatshouse.MetricBytes. If more than 1 problem, reports the last one
IngestionTagKey int32 // +TagIDShift, as required by "tag_id" in builtin metric. Contains error tad ID for IngestionStatus != 0, or any tag which caused uncached load IngestionStatus == 0
// warnings below
NotFoundTagName []byte // reference to memory inside tlstatshouse.MetricBytes. If more than 1 problem, reports the last one
FoundDraftTagName []byte // reference to memory inside tlstatshouse.MetricBytes. If more than 1 problem, reports the last one
TagSetTwiceKey int32 // +TagIDShift, as required by "tag_id" in builtin metric. If more than 1, remembers some
LegacyCanonicalTagKey int32 // +TagIDShift, as required by "tag_id" in builtin metric. If more than 1, remembers some
InvalidRawValue []byte // reference to memory inside tlstatshouse.MetricBytes. If more than 1 problem, reports the last one
InvalidRawTagKey int32 // key of InvalidRawValue
}
// TODO - implement InvalidRawValue and InvalidRawTagKey
func (h *MappedMetricHeader) SetKey(index int, id int32, tagIDKey int32) {
if index == format.HostTagIndex {
h.HostTag = id
if h.IsHKeySet {
h.TagSetTwiceKey = tagIDKey
}
h.IsHKeySet = true
} else {
h.Key.Keys[index] = id
if h.IsKeySet[index] {
h.TagSetTwiceKey = tagIDKey
}
h.IsKeySet[index] = true
}
}
func (h *MappedMetricHeader) SetInvalidString(ingestionStatus int32, tagIDKey int32, invalidString []byte) {
h.IngestionStatus = ingestionStatus
h.IngestionTagKey = tagIDKey
h.InvalidString = invalidString
}