diff --git a/point/check_test.go b/point/check_test.go index 31e335e9..b5c906dd 100644 --- a/point/check_test.go +++ b/point/check_test.go @@ -9,7 +9,6 @@ import ( "fmt" "math" "sort" - "testing" T "testing" "github.com/GuanceCloud/cliutils" @@ -17,7 +16,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestCheckMeasurement(t *testing.T) { +func TestCheckMeasurement(t *T.T) { cases := []struct { name, measurement, diff --git a/point/easybatch.go b/point/easybatch.go index 332b37e5..56b4701f 100644 --- a/point/easybatch.go +++ b/point/easybatch.go @@ -36,6 +36,7 @@ func (bp *BatchPoints) Reset() { field.IsTag = false field.Type = MetricType(0) field.Unit = "" + field.Description = "" field.Key = "" field.Val = nil } @@ -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 diff --git a/point/easyproto.go b/point/easyproto.go index d8d84ae3..ac68ddbc 100644 --- a/point/easyproto.go +++ b/point/easyproto.go @@ -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) { @@ -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 { @@ -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 } diff --git a/point/easyproto_test.go b/point/easyproto_test.go index dd452421..c1637b42 100644 --- a/point/easyproto_test.go +++ b/point/easyproto_test.go @@ -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") @@ -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") diff --git a/point/json_test.go b/point/json_test.go index 52982425..b8e73530 100644 --- a/point/json_test.go +++ b/point/json_test.go @@ -8,7 +8,6 @@ package point import ( "encoding/json" "fmt" - "testing" T "testing" "time" @@ -89,7 +88,7 @@ func TestJSONUnmarshal(t *T.T) { }) } -func TestJSONPointMarhsal(t *testing.T) { +func TestJSONPointMarhsal(t *T.T) { var kvs KVs EnableMixedArrayField = true diff --git a/point/kvs.go b/point/kvs.go index bd053841..6c1bc386 100644 --- a/point/kvs.go +++ b/point/kvs.go @@ -156,6 +156,7 @@ func clearKV(kv *Field) *Field { kv.IsTag = false kv.Type = UNSPECIFIED kv.Unit = "" + kv.Description = "" return kv } @@ -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) { diff --git a/point/kvs_test.go b/point/kvs_test.go index a8a02c7f..3dda6f07 100644 --- a/point/kvs_test.go +++ b/point/kvs_test.go @@ -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()) }) @@ -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)) diff --git a/point/new_point_test.go b/point/new_point_test.go index 1651fdef..5bae5f92 100644 --- a/point/new_point_test.go +++ b/point/new_point_test.go @@ -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", @@ -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 diff --git a/point/pbpoint_test.go b/point/pbpoint_test.go index 39a644a8..b87f25b8 100644 --- a/point/pbpoint_test.go +++ b/point/pbpoint_test.go @@ -9,7 +9,6 @@ import ( "encoding/json" "math" "strings" - "testing" T "testing" "time" @@ -20,7 +19,7 @@ import ( var name = "abc" -func BenchmarkMarshal(b *testing.B) { +func BenchmarkMarshal(b *T.B) { cases := []struct { name string repeat int @@ -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++ { @@ -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{} @@ -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) @@ -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++ { @@ -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 @@ -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) @@ -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 @@ -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) @@ -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 diff --git a/point/point.go b/point/point.go index ce59e87b..2de9ae61 100644 --- a/point/point.go +++ b/point/point.go @@ -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: diff --git a/point/point.pb.go b/point/point.pb.go index 42d3301e..c4f8c4dd 100644 --- a/point/point.pb.go +++ b/point/point.pb.go @@ -190,6 +190,7 @@ func (m *AnyDemo) GetDemo() string { type BasicTypes struct { // Types that are valid to be assigned to X: + // // *BasicTypes_I // *BasicTypes_U // *BasicTypes_F @@ -416,6 +417,7 @@ type Field struct { // See https://developers.google.com/protocol-buffers/docs/proto3#json // // Types that are valid to be assigned to Val: + // // *Field_I // *Field_U // *Field_F @@ -427,7 +429,8 @@ type Field struct { IsTag bool `protobuf:"varint,8,opt,name=is_tag,proto3" json:"is_tag,omitempty"` Type MetricType `protobuf:"varint,9,opt,name=type,proto3,enum=point.MetricType" json:"type,omitempty"` // field unit name - Unit string `protobuf:"bytes,10,opt,name=unit,proto3" json:"unit,omitempty"` + Unit string `protobuf:"bytes,10,opt,name=unit,proto3" json:"unit,omitempty"` + Description string `protobuf:"bytes,12,opt,name=description,proto3" json:"description,omitempty"` } func (m *Field) Reset() { *m = Field{} } @@ -583,6 +586,13 @@ func (m *Field) GetUnit() string { return "" } +func (m *Field) GetDescription() string { + if m != nil { + return m.Description + } + return "" +} + // XXX_OneofWrappers is for the internal use of the proto package. func (*Field) XXX_OneofWrappers() []interface{} { return []interface{}{ @@ -787,50 +797,51 @@ func init() { func init() { proto.RegisterFile("point.proto", fileDescriptor_dbb1a16d5866e018) } var fileDescriptor_dbb1a16d5866e018 = []byte{ - // 681 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x53, 0x41, 0x6f, 0xd3, 0x4a, - 0x10, 0xf6, 0x66, 0xed, 0x38, 0x99, 0x54, 0x7d, 0xfb, 0xf6, 0x55, 0x4f, 0xfb, 0xfa, 0x84, 0x65, - 0x4c, 0x2b, 0xa2, 0xaa, 0x4a, 0x11, 0x5c, 0x10, 0x88, 0x43, 0xd2, 0x24, 0x25, 0x40, 0x4b, 0xe4, - 0x36, 0x02, 0x71, 0x41, 0x1b, 0xb2, 0x89, 0x2c, 0x12, 0x27, 0xd8, 0x49, 0x8b, 0x6f, 0xfc, 0x04, - 0x7e, 0x02, 0x47, 0x7e, 0x0a, 0xc7, 0x1e, 0x7b, 0xa4, 0xe9, 0x85, 0x63, 0xaf, 0xdc, 0xd0, 0xac, - 0xdd, 0x14, 0xa2, 0x1e, 0xac, 0x99, 0x6f, 0xbf, 0x99, 0xd9, 0x99, 0x6f, 0xc7, 0x50, 0x9a, 0x8c, - 0x83, 0x70, 0x5a, 0x99, 0x44, 0xe3, 0xe9, 0x98, 0x5b, 0x1a, 0xac, 0xff, 0x37, 0x18, 0x8f, 0x07, - 0x43, 0xb5, 0xa3, 0x0f, 0xbb, 0xb3, 0xfe, 0x8e, 0x0c, 0x93, 0x34, 0xc2, 0xfb, 0x1f, 0xac, 0xba, - 0xea, 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f, 0x5f, 0x04, 0x00, 0x00, + // 701 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x53, 0x41, 0x6f, 0xd3, 0x48, + 0x14, 0xf6, 0x64, 0xec, 0x38, 0x79, 0xa9, 0xba, 0xde, 0xd9, 0x6a, 0x35, 0xdb, 0xd5, 0x5a, 0x5e, + 0x6f, 0xab, 0x8d, 0xaa, 0x2a, 0x45, 0x70, 0x41, 0x20, 0x0e, 0x49, 0x93, 0x94, 0x00, 0x2d, 0x91, + 0xdb, 0x08, 0xc4, 0x05, 0x4d, 0x9a, 0x49, 0x64, 0x91, 0xd8, 0xc6, 0x76, 0x5a, 0x7c, 0xe3, 0x27, + 0x70, 0xe7, 0xc2, 0x91, 0x9f, 0xc2, 0xb1, 0xc7, 0x1e, 0x69, 0x7a, 0xe1, 0xd8, 0x9f, 0x80, 0xde, + 0xc4, 0x4d, 0x4b, 0xd4, 0x83, 0xf5, 0xde, 0x37, 0xdf, 0x9b, 0x37, 0xef, 0x7d, 0xef, 0x19, 0x2a, + 0x51, 0xe8, 0x07, 0x69, 0x2d, 0x8a, 0xc3, 0x34, 0x64, 0x86, 0x02, 0xeb, 0x7f, 0x8d, 0xc2, 0x70, + 0x34, 0x96, 0x3b, 0xea, 0xb0, 0x3f, 0x1d, 0xee, 0x88, 0x20, 0x9b, 0x47, 0xb8, 0x7f, 0x83, 0xd1, + 0x94, 0xfd, 0xe9, 0x88, 0x31, 0xd0, 0xfd, 0x60, 0x18, 0x72, 0xe2, 0x90, 0x6a, 0xd9, 0x53, 0xbe, + 0xfb, 0x0f, 0x98, 0xf5, 0x20, 0x6b, 0xca, 0x49, 0x88, 0xf4, 0x40, 0x4e, 0x16, 0x34, 0xfa, 0xee, + 0x7b, 0x80, 0x86, 0x48, 0xfc, 0xe3, 0xa3, 0x2c, 0x92, 0x09, 0x5b, 0x05, 0xe2, 0x2b, 0x9a, 0x3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xcc, 0x50, 0x50, 0x66, + 0x00, 0x79, 0x6d, 0x69, 0x68, 0x3a, 0x16, 0x41, 0xd3, 0xb3, 0x0a, 0x68, 0xda, 0x16, 0x45, 0xd3, + 0xb0, 0x74, 0x34, 0x4d, 0xcb, 0x60, 0x26, 0xd0, 0x83, 0xce, 0x0b, 0xab, 0x88, 0xf8, 0xd0, 0x32, + 0xd1, 0xd4, 0xad, 0xd2, 0xd6, 0x13, 0x80, 0x9b, 0xf9, 0xb0, 0xdf, 0xa0, 0xd2, 0x3b, 0x38, 0xec, + 0xb6, 0x76, 0x3b, 0xed, 0x4e, 0xab, 0x69, 0x69, 0xac, 0x0c, 0xc6, 0xee, 0xcb, 0xde, 0xc1, 0x91, + 0x45, 0x58, 0x09, 0x74, 0xaf, 0x7e, 0xd4, 0xb2, 0x0a, 0x78, 0xb8, 0x57, 0xef, 0xed, 0xb5, 0x2c, + 0xda, 0x68, 0x9f, 0x5d, 0xd8, 0xda, 0xf9, 0x85, 0xad, 0x5d, 0x5d, 0xd8, 0xe4, 0xe3, 0xcc, 0x26, + 0x5f, 0x67, 0x36, 0xf9, 0x36, 0xb3, 0xc9, 0xd9, 0xcc, 0x26, 0xdf, 0x67, 0x36, 0xf9, 0x31, 0xb3, + 0xb5, 0xab, 0x99, 0x4d, 0x3e, 0x5d, 0xda, 0xda, 0xd9, 0xa5, 0xad, 0x9d, 0x5f, 0xda, 0x5a, 0xc3, + 0x50, 0xcd, 0x74, 0xc9, 0x1b, 0x73, 0xe7, 0xb1, 0xea, 0xaf, 0x5f, 0x54, 0x4b, 0xf6, 0xe0, 0x67, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x5b, 0x14, 0x0f, 0xee, 0x81, 0x04, 0x00, 0x00, } func (x KeyType) String() string { @@ -1167,6 +1178,9 @@ func (this *Field) Equal(that interface{}) bool { if this.Unit != that1.Unit { return false } + if this.Description != that1.Description { + return false + } return true } func (this *Field_I) Equal(that interface{}) bool { @@ -1562,7 +1576,7 @@ func (this *Field) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 15) + s := make([]string, 0, 16) s = append(s, "&point.Field{") s = append(s, "Key: "+fmt.Sprintf("%#v", this.Key)+",\n") if this.Val != nil { @@ -1571,6 +1585,7 @@ func (this *Field) GoString() string { s = append(s, "IsTag: "+fmt.Sprintf("%#v", this.IsTag)+",\n") s = append(s, "Type: "+fmt.Sprintf("%#v", this.Type)+",\n") s = append(s, "Unit: "+fmt.Sprintf("%#v", this.Unit)+",\n") + s = append(s, "Description: "+fmt.Sprintf("%#v", this.Description)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -1963,6 +1978,13 @@ func (m *Field) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintPoint(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x62 + } if m.Val != nil { { size := m.Val.Size() @@ -2427,6 +2449,10 @@ func (m *Field) Size() (n int) { if l > 0 { n += 1 + l + sovPoint(uint64(l)) } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovPoint(uint64(l)) + } return n } @@ -2707,6 +2733,7 @@ func (this *Field) String() string { `IsTag:` + fmt.Sprintf("%v", this.IsTag) + `,`, `Type:` + fmt.Sprintf("%v", this.Type) + `,`, `Unit:` + fmt.Sprintf("%v", this.Unit) + `,`, + `Description:` + fmt.Sprintf("%v", this.Description) + `,`, `}`, }, "") return s @@ -3762,6 +3789,38 @@ func (m *Field) Unmarshal(dAtA []byte) error { } m.Val = &Field_S{string(dAtA[iNdEx:postIndex])} iNdEx = postIndex + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoint + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPoint + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPoint + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipPoint(dAtA[iNdEx:]) diff --git a/point/point.proto b/point/point.proto index 3d547e8f..2229d5ae 100644 --- a/point/point.proto +++ b/point/point.proto @@ -87,6 +87,7 @@ message Field { // field unit name string unit = 10; // metric unit, such as bytes(B), duration(ms/us) and so on. + string description = 12; // metric desc. } // Warn used to attach some warning message during building the point. diff --git a/point/point_test.go b/point/point_test.go index 471479ef..85bc428c 100644 --- a/point/point_test.go +++ b/point/point_test.go @@ -154,6 +154,7 @@ func TestGet(t *T.T) { // get non-tag key pt.pt.Fields = KVs(pt.pt.Fields).SetKV(NewKV(`f1`, 1.23, WithKVUnit("bytes"), + WithKVDesc("f1 is bytes"), WithKVTagSet(true), // set failed WithKVType(COUNT))) assert.Equal(t, "", pt.GetTag(`f1`)) @@ -627,7 +628,7 @@ func TestPBJSON(t *T.T) { kvs := KVs(pt.pt.Fields) kvs = kvs.SetTag(`t1`, `v1`). - SetKV(NewKV(`f2`, 3.14, WithKVUnit("kb"), WithKVType(COUNT))) + SetKV(NewKV(`f2`, 3.14, WithKVUnit("kb"), WithKVType(COUNT), WithKVDesc("desc"))) pt.pt.Fields = kvs j, _ := pt.PBJson()