Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions point/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import (
"fmt"
"math"
"sort"
"testing"
T "testing"

"github.com/GuanceCloud/cliutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCheckMeasurement(t *testing.T) {
func TestCheckMeasurement(t *T.T) {
cases := []struct {
name,
measurement,
Expand Down
7 changes: 7 additions & 0 deletions point/easybatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (bp *BatchPoints) Reset() {
field.IsTag = false
field.Type = MetricType(0)
field.Unit = ""
field.Description = ""
field.Key = ""
field.Val = nil
}
Expand Down Expand Up @@ -257,6 +258,12 @@ func (bp *BatchPoints) unmarshalField(fc *easyproto.FieldContext, field *Field,
return fmt.Errorf("cannot unmarshal unit for Field")
}
field.Unit = s
case 12:
s, ok := fc.String()
if !ok {
return fmt.Errorf("cannot unmarshal Description for Field")
}
field.Description = s
}
}
return nil
Expand Down
18 changes: 12 additions & 6 deletions point/easyproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (kv *Field) marshalProtobuf(mm *easyproto.MessageMarshaler) {
mm.AppendBool(8, kv.IsTag)
mm.AppendInt32(9, int32(kv.Type))
mm.AppendString(10, kv.Unit)
mm.AppendString(12, kv.Description)
}

func (w *Warn) marshalProtobuf(mm *easyproto.MessageMarshaler) {
Expand Down Expand Up @@ -240,12 +241,12 @@ func unmarshalDebug(src []byte) (*Debug, error) {

func unmarshalField(src []byte) (*Field, error) {
var (
fc easyproto.FieldContext
key, unit string
isTag bool
f *Field
metricType MetricType
err error
fc easyproto.FieldContext
key, unit, desc string
isTag bool
f *Field
metricType MetricType
err error
)

for len(src) > 0 {
Expand Down Expand Up @@ -304,12 +305,17 @@ func unmarshalField(src []byte) (*Field, error) {
if x, ok := fc.String(); ok {
unit = x
}
case 12:
if x, ok := fc.String(); ok {
desc = x
}
default: // pass
}
}

if f != nil {
f.Unit = unit
f.Description = desc
f.Type = metricType
f.IsTag = isTag
}
Expand Down
8 changes: 4 additions & 4 deletions point/easyproto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestEasyproto(t *T.T) {
var kvs KVs
kvs = kvs.Add("f1", 123)
kvs = kvs.Add("f2", 1.23)
kvs = kvs.Add("f3", uint(42), WithKVUnit("year"), WithKVType(GAUGE))
kvs = kvs.Add("f3", uint(42), WithKVUnit("year"), WithKVType(GAUGE), WithKVDesc("desc"))
kvs = kvs.Add("f4", false)
kvs = kvs.Add("f5", []byte("binary-data"))
kvs = kvs.Add("f6", "text-data")
Expand Down Expand Up @@ -98,9 +98,9 @@ func TestEasyproto(t *T.T) {

t.Run("easyproto-unmarshal", func(t *T.T) {
var kvs KVs
kvs = kvs.Add("f1", 123, WithKVUnit("dollar"), WithKVType(GAUGE))
kvs = kvs.Add("f2", 1.23, WithKVUnit("byte"), WithKVType(COUNT))
kvs = kvs.Add("f3", uint(42))
kvs = kvs.Add("f1", 123, WithKVUnit("dollar"), WithKVType(GAUGE), WithKVDesc("desc"))
kvs = kvs.Add("f2", 1.23, WithKVUnit("byte"), WithKVType(COUNT), WithKVDesc("desc"))
kvs = kvs.Add("f3", uint(42), WithKVDesc("field f3 is uint"))
kvs = kvs.Add("f4", false)
kvs = kvs.Add("f5", []byte("binary-data"))
kvs = kvs.Add("f6", "text-data")
Expand Down
3 changes: 1 addition & 2 deletions point/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package point
import (
"encoding/json"
"fmt"
"testing"
T "testing"
"time"

Expand Down Expand Up @@ -89,7 +88,7 @@ func TestJSONUnmarshal(t *T.T) {
})
}

func TestJSONPointMarhsal(t *testing.T) {
func TestJSONPointMarhsal(t *T.T) {
var kvs KVs

EnableMixedArrayField = true
Expand Down
8 changes: 8 additions & 0 deletions point/kvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func clearKV(kv *Field) *Field {
kv.IsTag = false
kv.Type = UNSPECIFIED
kv.Unit = ""
kv.Description = ""
return kv
}

Expand Down Expand Up @@ -486,6 +487,13 @@ func WithKVUnit(u string) KVOption {
}
}

// WithKVDesc set value's description.
func WithKVDesc(desc string) KVOption {
return func(kv *Field) {
kv.Description = desc
}
}

// WithKVType set field type(count/gauge/rate).
func WithKVType(t MetricType) KVOption {
return func(kv *Field) {
Expand Down
6 changes: 3 additions & 3 deletions point/kvs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ func TestKVsAdd(t *T.T) {

t.Run("add-v2", func(t *T.T) {
var kvs KVs
kvs = kvs.Add("f1", 123, WithKVUnit("dollar"), WithKVType(GAUGE))
kvs = kvs.Add("cap", 123, WithKVUnit("bytes"), WithKVType(COUNT))
kvs = kvs.Add("f1", 123, WithKVUnit("dollar"), WithKVType(GAUGE), WithKVDesc("dollar"))
kvs = kvs.Add("cap", 123, WithKVUnit("bytes"), WithKVType(COUNT), WithKVDesc("B"))

t.Logf("kvs: %s", kvs.Pretty())
})
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestNewKVs(t *T.T) {
kvs = kvs.SetKV(NewKV(`t3`, []byte("v2"), WithKVTagSet(true)))

kvs = kvs.SetKV(NewKV(`f1`, "foo"))
kvs = kvs.SetKV(NewKV(`f2`, 123, WithKVUnit("MB"), WithKVType(COUNT)))
kvs = kvs.SetKV(NewKV(`f2`, 123, WithKVUnit("MB"), WithKVType(COUNT), WithKVDesc("desc")))
kvs = kvs.SetKV(NewKV(`f3`, 3.14, WithKVUnit("some"), WithKVType(GAUGE)))

assert.Equal(t, 6, len(kvs))
Expand Down
6 changes: 3 additions & 3 deletions point/new_point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ func TestNewPoint(t *T.T) {
}
}

func TestPointKeySorted(t *testing.T) {
t.Run("sorted", func(t *testing.T) {
func TestPointKeySorted(t *T.T) {
t.Run("sorted", func(t *T.T) {
pt, err := NewPointDeprecated("basic",
map[string]string{
"t1": "v1",
Expand Down Expand Up @@ -756,7 +756,7 @@ func BenchmarkV2NewPoint(b *T.B) {
})
}

func FuzzPLPBEquality(f *testing.F) {
func FuzzPLPBEquality(f *T.F) {
cases := []struct {
measurement string
tagk string
Expand Down
21 changes: 10 additions & 11 deletions point/pbpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"math"
"strings"
"testing"
T "testing"
"time"

Expand All @@ -20,7 +19,7 @@ import (

var name = "abc"

func BenchmarkMarshal(b *testing.B) {
func BenchmarkMarshal(b *T.B) {
cases := []struct {
name string
repeat int
Expand All @@ -37,7 +36,7 @@ func BenchmarkMarshal(b *testing.B) {
}

for _, tc := range cases {
b.Run(tc.name+"_pb-marshal", func(b *testing.B) {
b.Run(tc.name+"_pb-marshal", func(b *T.B) {
pbpts := RandPBPoints(tc.repeat)

for i := 0; i < b.N; i++ {
Expand All @@ -47,7 +46,7 @@ func BenchmarkMarshal(b *testing.B) {
}
})

b.Run(tc.name+"_lp-marshal", func(b *testing.B) {
b.Run(tc.name+"_lp-marshal", func(b *T.B) {
pts := RandPoints(tc.repeat)
for i := 0; i < b.N; i++ {
arr := []string{}
Expand All @@ -61,7 +60,7 @@ func BenchmarkMarshal(b *testing.B) {

b.Logf("----------------------------------------------")

b.Run(tc.name+"_pb-unmarshal", func(b *testing.B) {
b.Run(tc.name+"_pb-unmarshal", func(b *T.B) {
pbpts := RandPBPoints(tc.repeat)

pb, err := proto.Marshal(pbpts)
Expand All @@ -75,7 +74,7 @@ func BenchmarkMarshal(b *testing.B) {
}
})

b.Run(tc.name+"_lp-unmarshal", func(b *testing.B) {
b.Run(tc.name+"_lp-unmarshal", func(b *T.B) {
pts := RandPoints(tc.repeat)
arr := []string{}
for i := 0; i < len(pts); i++ {
Expand All @@ -92,7 +91,7 @@ func BenchmarkMarshal(b *testing.B) {
}
}

func TestPBPointJSON(t *testing.T) {
func TestPBPointJSON(t *T.T) {
cases := []struct {
name string
tags map[string]string
Expand Down Expand Up @@ -159,7 +158,7 @@ func TestPBPointJSON(t *testing.T) {
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Run(tc.name, func(t *T.T) {
pt, err := NewPointDeprecated(tc.name, tc.tags, tc.fields, WithEncoding(Protobuf), WithTime(tc.time), WithKeySorted(true))

assert.NoError(t, err)
Expand Down Expand Up @@ -225,7 +224,7 @@ func TestPBPointJSON(t *testing.T) {
}
}

func TestPBPointPayload(t *testing.T) {
func TestPBPointPayload(t *T.T) {
cases := []struct {
name string
repeat int
Expand Down Expand Up @@ -267,7 +266,7 @@ func TestPBPointPayload(t *testing.T) {
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Run(tc.name, func(t *T.T) {
lppts := RandPoints(tc.repeat)
pbpts := RandPBPoints(tc.repeat)

Expand Down Expand Up @@ -308,7 +307,7 @@ func TestPBPointPayload(t *testing.T) {
}

// nolint:ineffassign
func TestPBPointPayloadSize(t *testing.T) {
func TestPBPointPayloadSize(t *T.T) {
type tcase struct {
name string
n int
Expand Down
1 change: 1 addition & 0 deletions point/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func (p *Point) Size() int {
n += 8 // time
n += 4 // MetricType: uint32
n += len(kv.Unit)
n += len(kv.Description)

switch kv.Val.(type) {
case *Field_I, *Field_F, *Field_U:
Expand Down
Loading