Skip to content

Commit 3660fad

Browse files
committed
update again to latest MT version
in particular grafana/metrictank#894 grafana/metrictank#911
1 parent 88d6f01 commit 3660fad

File tree

5 files changed

+41
-18
lines changed

5 files changed

+41
-18
lines changed

archive.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
// Archive represents a metric archive
1111
// the zero value represents a raw metric
1212
// any non-zero value represents a certain
13-
// aggregation method (lower 4 bits) and
14-
// aggregation span (higher 4 bits)
15-
type Archive uint8
13+
// aggregation method (lower 8 bits) and
14+
// aggregation span (higher 8 bits)
15+
type Archive uint16
1616

1717
// important: caller must make sure to call IsSpanValid first
1818
func NewArchive(method Method, span uint32) Archive {
19-
code := spanHumanToCode[span]
20-
return Archive(uint8(method) | code<<4)
19+
code := uint16(spanHumanToCode[span])
20+
return Archive(uint16(method) | code<<8)
2121
}
2222

2323
// String returns the traditional key suffix like sum_600 etc
@@ -31,7 +31,7 @@ func (a Archive) Method() Method {
3131
}
3232

3333
func (a Archive) Span() uint32 {
34-
return spanCodeToHuman[uint8(a>>4)]
34+
return spanCodeToHuman[uint8(a>>8)]
3535
}
3636

3737
func IsSpanValid(span uint32) bool {
@@ -76,7 +76,7 @@ var spanCodeToHuman map[uint8]uint32
7676

7777
func init() {
7878
// all the aggregation spans we support, their index position in this slice is their code
79-
spans := []uint32{2, 5, 10, 15, 30, 60, 90, 120, 150, 300, 600, 900, 1200, 1800, 45 * 60, 3600, 3600 + 30*60, 2 * 3600, 3 * 3600, 4 * 3600, 5 * 3600, 6 * 3600}
79+
spans := []uint32{2, 5, 10, 15, 30, 60, 90, 120, 150, 300, 600, 900, 1200, 1800, 45 * 60, 3600, 3600 + 30*60, 2 * 3600, 3 * 3600, 4 * 3600, 5 * 3600, 6 * 3600, 8 * 3600, 12 * 3600, 24 * 3600}
8080

8181
spanHumanToCode = make(map[uint32]uint8)
8282
spanCodeToHuman = make(map[uint8]uint32)

archive_test.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ func TestArchive(t *testing.T) {
1010
expStr string
1111
}
1212
cases := []c{
13-
{Avg, 15, 0x31, "avg_15"},
14-
{Cnt, 120, 0x76, "cnt_120"},
13+
{Avg, 15, 0x301, "avg_15"},
14+
{Cnt, 120, 0x706, "cnt_120"},
15+
{Cnt, 3600, 0xF06, "cnt_3600"},
16+
{Lst, 7200, 0x1103, "lst_7200"},
17+
{Min, 6 * 3600, 0x1505, "min_21600"},
18+
{Cnt, 2, 0x6, "cnt_2"},
19+
{Avg, 5, 0x101, "avg_5"},
20+
{Cnt, 3600 + 30*60, 0x1006, "cnt_5400"},
1521
}
1622
for i, cas := range cases {
1723
arch := NewArchive(cas.method, cas.span)
@@ -22,5 +28,13 @@ func TestArchive(t *testing.T) {
2228
if str != cas.expStr {
2329
t.Fatalf("case %d: expected string %q, got %q", i, cas.expStr, str)
2430
}
31+
method := arch.Method()
32+
if method != cas.method {
33+
t.Fatalf("case %d: expected method %v, got %v", i, cas.method, method)
34+
}
35+
span := arch.Span()
36+
if span != cas.span {
37+
t.Fatalf("case %d: expected span %v, got %v", i, cas.span, span)
38+
}
2539
}
2640
}

metric.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type MetricDataArray []*MetricData
107107

108108
type MetricDefinition struct {
109109
Id MKey `json:"mkey"`
110-
OrgId int `json:"org_id"`
110+
OrgId uint32 `json:"org_id"`
111111
Name string `json:"name"`
112112
Interval int `json:"interval"`
113113
Unit string `json:"unit"`
@@ -235,7 +235,7 @@ func MetricDefinitionFromMetricData(d *MetricData) *MetricDefinition {
235235
md := &MetricDefinition{
236236
Id: mkey,
237237
Name: d.Name,
238-
OrgId: d.OrgId,
238+
OrgId: uint32(d.OrgId),
239239
Mtype: d.Mtype,
240240
Interval: d.Interval,
241241
LastUpdate: d.Time,

metric_gen.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func (z *MetricDefinition) DecodeMsg(dc *msgp.Reader) (err error) {
453453
return
454454
}
455455
case "OrgId":
456-
z.OrgId, err = dc.ReadInt()
456+
z.OrgId, err = dc.ReadUint32()
457457
if err != nil {
458458
return
459459
}
@@ -531,7 +531,7 @@ func (z *MetricDefinition) EncodeMsg(en *msgp.Writer) (err error) {
531531
if err != nil {
532532
return
533533
}
534-
err = en.WriteInt(z.OrgId)
534+
err = en.WriteUint32(z.OrgId)
535535
if err != nil {
536536
return
537537
}
@@ -619,7 +619,7 @@ func (z *MetricDefinition) MarshalMsg(b []byte) (o []byte, err error) {
619619
}
620620
// string "OrgId"
621621
o = append(o, 0xa5, 0x4f, 0x72, 0x67, 0x49, 0x64)
622-
o = msgp.AppendInt(o, z.OrgId)
622+
o = msgp.AppendUint32(o, z.OrgId)
623623
// string "Name"
624624
o = append(o, 0xa4, 0x4e, 0x61, 0x6d, 0x65)
625625
o = msgp.AppendString(o, z.Name)
@@ -669,7 +669,7 @@ func (z *MetricDefinition) UnmarshalMsg(bts []byte) (o []byte, err error) {
669669
return
670670
}
671671
case "OrgId":
672-
z.OrgId, bts, err = msgp.ReadIntBytes(bts)
672+
z.OrgId, bts, err = msgp.ReadUint32Bytes(bts)
673673
if err != nil {
674674
return
675675
}
@@ -733,7 +733,7 @@ func (z *MetricDefinition) UnmarshalMsg(bts []byte) (o []byte, err error) {
733733

734734
// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
735735
func (z *MetricDefinition) Msgsize() (s int) {
736-
s = 1 + 3 + z.Id.Msgsize() + 6 + msgp.IntSize + 5 + msgp.StringPrefixSize + len(z.Name) + 9 + msgp.IntSize + 5 + msgp.StringPrefixSize + len(z.Unit) + 6 + msgp.StringPrefixSize + len(z.Mtype) + 5 + msgp.ArrayHeaderSize
736+
s = 1 + 3 + z.Id.Msgsize() + 6 + msgp.Uint32Size + 5 + msgp.StringPrefixSize + len(z.Name) + 9 + msgp.IntSize + 5 + msgp.StringPrefixSize + len(z.Unit) + 6 + msgp.StringPrefixSize + len(z.Mtype) + 5 + msgp.ArrayHeaderSize
737737
for za0001 := range z.Tags {
738738
s += msgp.StringPrefixSize + len(z.Tags[za0001])
739739
}

msg/msg.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,19 @@ func WritePointMsg(point schema.MetricPoint, buf []byte, version Format) (o []by
111111
return nil, fmt.Errorf(errFmtUnsupportedFormat, version)
112112
}
113113

114-
func IsPointMsg(data []byte) bool {
114+
func IsPointMsg(data []byte) (Format, bool) {
115115
l := len(data)
116+
if l == 0 {
117+
return 0, false
118+
}
116119
version := Format(data[0])
117-
return (l == 29 && version == FormatMetricPointWithoutOrg) || (l == 33 && version == FormatMetricPoint)
120+
if l == 29 && version == FormatMetricPointWithoutOrg {
121+
return FormatMetricPointWithoutOrg, true
122+
}
123+
if l == 33 && version == FormatMetricPoint {
124+
return FormatMetricPoint, true
125+
}
126+
return 0, false
118127
}
119128

120129
func ReadPointMsg(data []byte, defaultOrg uint32) ([]byte, schema.MetricPoint, error) {

0 commit comments

Comments
 (0)