From 40287588c7fb79c93e45d17e6ca4dedb69119d52 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 11 Jul 2023 14:09:11 +0200 Subject: [PATCH] Use slice of labels for json and proto structures --- pkg/loghttp/entry.go | 47 +- pkg/loghttp/query.go | 15 +- pkg/loghttp/query_test.go | 36 +- pkg/push/go.mod | 1 + pkg/push/push.pb.go | 408 +++++++++++++++--- pkg/push/push.proto | 10 +- pkg/push/types.go | 239 +++++++++- pkg/util/marshal/legacy/marshal_test.go | 29 +- pkg/util/marshal/marshal_test.go | 18 +- pkg/util/marshal/query.go | 49 +-- pkg/util/unmarshal/legacy/unmarshal_test.go | 15 +- pkg/util/unmarshal/unmarshal_test.go | 10 +- .../grafana/loki/pkg/push/push.pb.go | 408 +++++++++++++++--- .../grafana/loki/pkg/push/push.proto | 10 +- .../github.com/grafana/loki/pkg/push/types.go | 239 +++++++++- 15 files changed, 1303 insertions(+), 231 deletions(-) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index 28d92b6b4dcf..c76e26856c72 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -8,8 +8,7 @@ import ( "github.com/buger/jsonparser" jsoniter "github.com/json-iterator/go" "github.com/modern-go/reflect2" - - "github.com/grafana/loki/pkg/logproto" + "github.com/prometheus/prometheus/model/labels" ) func init() { @@ -20,21 +19,7 @@ func init() { type Entry struct { Timestamp time.Time Line string - NonIndexedLabels LabelSet -} - -func (e Entry) ToProto() logproto.Entry { - // If there are no labels, we return empty string instead of '{}'. - var nonIndexedLabels string - if len(e.NonIndexedLabels) > 0 { - nonIndexedLabels = e.NonIndexedLabels.String() - } - - return logproto.Entry{ - Timestamp: e.Timestamp, - Line: e.Line, - NonIndexedLabels: nonIndexedLabels, - } + NonIndexedLabels labels.Labels } func (e *Entry) UnmarshalJSON(data []byte) error { @@ -72,17 +57,21 @@ func (e *Entry) UnmarshalJSON(data []byte) error { parseError = jsonparser.MalformedObjectError return } - e.NonIndexedLabels = make(LabelSet) + var nonIndexedLabels labels.Labels if err := jsonparser.ObjectEach(value, func(key []byte, value []byte, dataType jsonparser.ValueType, _ int) error { if dataType != jsonparser.String { return jsonparser.MalformedStringError } - e.NonIndexedLabels[yoloString(key)] = yoloString(value) + nonIndexedLabels = append(nonIndexedLabels, labels.Label{ + Name: yoloString(key), + Value: yoloString(value), + }) return nil }); err != nil { parseError = err return } + e.NonIndexedLabels = nonIndexedLabels } i++ }) @@ -104,7 +93,7 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { i := 0 var ts time.Time var line string - var labels LabelSet + var nonIndexedLabels labels.Labels ok := iter.ReadArrayCB(func(iter *jsoniter.Iterator) bool { var ok bool switch i { @@ -120,10 +109,12 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { } return true case 2: - labels = make(LabelSet) iter.ReadMapCB(func(iter *jsoniter.Iterator, labelName string) bool { labelValue := iter.ReadString() - labels[labelName] = labelValue + nonIndexedLabels = append(nonIndexedLabels, labels.Label{ + Name: labelName, + Value: labelValue, + }) return true }) i++ @@ -140,7 +131,7 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { *((*[]Entry)(ptr)) = append(*((*[]Entry)(ptr)), Entry{ Timestamp: ts, Line: line, - NonIndexedLabels: labels, + NonIndexedLabels: nonIndexedLabels, }) return true } @@ -180,14 +171,12 @@ func (EntryEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { if len(e.NonIndexedLabels) > 0 { stream.WriteMore() stream.WriteObjectStart() - var idx int - for lName, lValue := range e.NonIndexedLabels { - if idx > 0 { + for i, lbl := range e.NonIndexedLabels { + if i > 0 { stream.WriteMore() } - stream.WriteObjectField(lName) - stream.WriteString(lValue) - idx++ + stream.WriteObjectField(lbl.Name) + stream.WriteString(lbl.Value) } stream.WriteObjectEnd() } diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index 6f905029ab66..566b2d68de9f 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -8,6 +8,7 @@ import ( "unsafe" "github.com/grafana/loki/pkg/storage/stores/index/seriesvolume" + "github.com/prometheus/prometheus/model/labels" "github.com/buger/jsonparser" json "github.com/json-iterator/go" @@ -156,19 +157,22 @@ func unmarshalHTTPToLogProtoEntry(data []byte) (logproto.Entry, error) { } e.Line = v case 2: // nonIndexedLabels - nonIndexedLabels := make(LabelSet) + var nonIndexedLabels labels.Labels err := jsonparser.ObjectEach(value, func(key, val []byte, dataType jsonparser.ValueType, _ int) error { if dataType != jsonparser.String { return jsonparser.MalformedStringError } - nonIndexedLabels[yoloString(key)] = yoloString(val) + nonIndexedLabels = append(nonIndexedLabels, labels.Label{ + Name: yoloString(key), + Value: yoloString(val), + }) return nil }) if err != nil { parseError = err return } - e.NonIndexedLabels = nonIndexedLabels.String() + e.NonIndexedLabels = nonIndexedLabels } i++ }) @@ -238,10 +242,7 @@ func (s Streams) ToProto() []logproto.Stream { } result := make([]logproto.Stream, 0, len(s)) for _, s := range s { - entries := make([]logproto.Entry, len(s.Entries), len(s.Entries)) - for i, e := range s.Entries { - entries[i] = e.ToProto() - } + entries := *(*[]logproto.Entry)(unsafe.Pointer(&s.Entries)) result = append(result, logproto.Stream{Labels: s.Labels.String(), Entries: entries}) } return result diff --git a/pkg/loghttp/query_test.go b/pkg/loghttp/query_test.go index 5bd2e2cce69b..fb0ab15604bb 100644 --- a/pkg/loghttp/query_test.go +++ b/pkg/loghttp/query_test.go @@ -8,6 +8,7 @@ import ( "time" jsoniter "github.com/json-iterator/go" + "github.com/prometheus/prometheus/model/labels" "github.com/stretchr/testify/require" "github.com/grafana/loki/pkg/logproto" @@ -153,14 +154,20 @@ func TestStreams_ToProto(t *testing.T) { Labels: map[string]string{"foo": "bar"}, Entries: []Entry{ {Timestamp: time.Unix(0, 1), Line: "1"}, - {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }}, }, }, { Labels: map[string]string{"foo": "bar", "lvl": "error"}, Entries: []Entry{ {Timestamp: time.Unix(0, 3), Line: "3"}, - {Timestamp: time.Unix(0, 4), Line: "4", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 4), Line: "4", NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }}, }, }, }, @@ -169,14 +176,20 @@ func TestStreams_ToProto(t *testing.T) { Labels: `{foo="bar"}`, Entries: []logproto.Entry{ {Timestamp: time.Unix(0, 1), Line: "1"}, - {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}.String()}, + {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }}, }, }, { Labels: `{foo="bar", lvl="error"}`, Entries: []logproto.Entry{ {Timestamp: time.Unix(0, 3), Line: "3"}, - {Timestamp: time.Unix(0, 4), Line: "4", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}.String()}, + {Timestamp: time.Unix(0, 4), Line: "4", NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }}, }, }, }, @@ -210,7 +223,10 @@ func Test_QueryResponseUnmarshal(t *testing.T) { Labels: LabelSet{"foo": "bar"}, Entries: []Entry{ {Timestamp: time.Unix(0, 1), Line: "1"}, - {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }}, }, }, }, @@ -230,7 +246,10 @@ func Test_QueryResponseUnmarshal(t *testing.T) { Labels: LabelSet{"foo": "bar"}, Entries: []Entry{ {Timestamp: time.Unix(0, 1), Line: "log line 1"}, - {Timestamp: time.Unix(0, 2), Line: "some log line 2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 2), Line: "some log line 2", NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }}, }, }, Stream{ @@ -240,7 +259,10 @@ func Test_QueryResponseUnmarshal(t *testing.T) { {Timestamp: time.Unix(0, 2), Line: "2"}, {Timestamp: time.Unix(0, 2), Line: "2"}, {Timestamp: time.Unix(0, 2), Line: "2"}, - {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }}, }, }, }, diff --git a/pkg/push/go.mod b/pkg/push/go.mod index e99a33d3e7ad..d83e55f7a04c 100644 --- a/pkg/push/go.mod +++ b/pkg/push/go.mod @@ -4,6 +4,7 @@ go 1.19 require ( github.com/gogo/protobuf v1.3.2 + github.com/prometheus/prometheus v0.45.0 github.com/stretchr/testify v1.8.1 google.golang.org/grpc v1.52.0 ) diff --git a/pkg/push/push.pb.go b/pkg/push/push.pb.go index 79849186a8ef..6fae3c1e7f73 100644 --- a/pkg/push/push.pb.go +++ b/pkg/push/push.pb.go @@ -164,16 +164,67 @@ func (m *StreamAdapter) GetHash() uint64 { return 0 } +type LabelPairAdapter struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *LabelPairAdapter) Reset() { *m = LabelPairAdapter{} } +func (*LabelPairAdapter) ProtoMessage() {} +func (*LabelPairAdapter) Descriptor() ([]byte, []int) { + return fileDescriptor_35ec442956852c9e, []int{3} +} +func (m *LabelPairAdapter) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LabelPairAdapter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LabelPairAdapter.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *LabelPairAdapter) XXX_Merge(src proto.Message) { + xxx_messageInfo_LabelPairAdapter.Merge(m, src) +} +func (m *LabelPairAdapter) XXX_Size() int { + return m.Size() +} +func (m *LabelPairAdapter) XXX_DiscardUnknown() { + xxx_messageInfo_LabelPairAdapter.DiscardUnknown(m) +} + +var xxx_messageInfo_LabelPairAdapter proto.InternalMessageInfo + +func (m *LabelPairAdapter) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *LabelPairAdapter) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + type EntryAdapter struct { - Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` - Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` - NonIndexedLabels string `protobuf:"bytes,3,opt,name=nonIndexedLabels,proto3" json:"nonIndexedLabels,omitempty"` + Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` + NonIndexedLabels []LabelPairAdapter `protobuf:"bytes,3,rep,name=nonIndexedLabels,proto3" json:"nonIndexedLabels,omitempty"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } func (*EntryAdapter) ProtoMessage() {} func (*EntryAdapter) Descriptor() ([]byte, []int) { - return fileDescriptor_35ec442956852c9e, []int{3} + return fileDescriptor_35ec442956852c9e, []int{4} } func (m *EntryAdapter) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -216,53 +267,57 @@ func (m *EntryAdapter) GetLine() string { return "" } -func (m *EntryAdapter) GetNonIndexedLabels() string { +func (m *EntryAdapter) GetNonIndexedLabels() []LabelPairAdapter { if m != nil { return m.NonIndexedLabels } - return "" + return nil } func init() { proto.RegisterType((*PushRequest)(nil), "logproto.PushRequest") proto.RegisterType((*PushResponse)(nil), "logproto.PushResponse") proto.RegisterType((*StreamAdapter)(nil), "logproto.StreamAdapter") + proto.RegisterType((*LabelPairAdapter)(nil), "logproto.LabelPairAdapter") proto.RegisterType((*EntryAdapter)(nil), "logproto.EntryAdapter") } func init() { proto.RegisterFile("pkg/push/push.proto", fileDescriptor_35ec442956852c9e) } var fileDescriptor_35ec442956852c9e = []byte{ - // 460 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x52, 0xcf, 0x6e, 0xd3, 0x30, - 0x1c, 0x8e, 0xdb, 0xd2, 0x6d, 0xee, 0x18, 0xc8, 0xb0, 0x51, 0x22, 0x64, 0x57, 0x39, 0xf5, 0x00, - 0x89, 0x54, 0x0e, 0x9c, 0x1b, 0x09, 0x69, 0x20, 0x0e, 0x28, 0x20, 0x90, 0xb8, 0xa5, 0xd4, 0x73, - 0xa2, 0x25, 0x76, 0x88, 0x1d, 0x89, 0xdd, 0x78, 0x84, 0xf1, 0x16, 0x3c, 0x07, 0xa7, 0x1d, 0x7b, - 0x9c, 0x38, 0x04, 0x9a, 0x5e, 0x50, 0x4e, 0x7b, 0x04, 0x14, 0x27, 0xa6, 0x63, 0x5c, 0x9c, 0xcf, - 0xbf, 0x7f, 0xdf, 0x97, 0xef, 0x67, 0x78, 0x2f, 0x3b, 0x65, 0x5e, 0x56, 0xc8, 0x48, 0x1f, 0x6e, - 0x96, 0x0b, 0x25, 0xd0, 0x6e, 0x22, 0x98, 0x46, 0xf6, 0x7d, 0x26, 0x98, 0xd0, 0xd0, 0x6b, 0x50, - 0x9b, 0xb7, 0x09, 0x13, 0x82, 0x25, 0xd4, 0xd3, 0xb7, 0x45, 0x71, 0x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 0x12, 0x73, 0x3a, 0xee, 0xe9, 0x5f, 0xdb, 0xad, 0x4b, 0xa2, 0xef, 0x81, 0x3e, 0xd1, - 0x4b, 0x78, 0x97, 0x0b, 0xfe, 0x82, 0x2f, 0xe9, 0x67, 0xba, 0x7c, 0xd5, 0x9a, 0xd0, 0xd7, 0x95, - 0xb8, 0x2e, 0x89, 0x7d, 0x33, 0xf7, 0x58, 0xa4, 0xb1, 0xa2, 0x69, 0xa6, 0xce, 0x82, 0xff, 0xfa, - 0x66, 0x73, 0x38, 0x6c, 0x8c, 0xa6, 0x39, 0x7a, 0x06, 0x07, 0x0d, 0x42, 0x87, 0x5b, 0x8f, 0xae, - 0xed, 0xd6, 0x3e, 0xba, 0x19, 0xee, 0x36, 0x63, 0xf9, 0xef, 0x56, 0x6b, 0x6c, 0x5d, 0xae, 0xb1, - 0x75, 0xb5, 0xc6, 0xe0, 0x4b, 0x85, 0xc1, 0xb7, 0x0a, 0x83, 0x8b, 0x0a, 0x83, 0x55, 0x85, 0xc1, - 0xaf, 0x0a, 0x83, 0xdf, 0x15, 0xb6, 0xae, 0x2a, 0x0c, 0xce, 0x37, 0xd8, 0x5a, 0x6d, 0xb0, 0x75, - 0xb9, 0xc1, 0xd6, 0x87, 0x09, 0x8b, 0x55, 0x54, 0x2c, 0xdc, 0x8f, 0x22, 0xf5, 0x58, 0x1e, 0x9e, - 0x84, 0x3c, 0xf4, 0x12, 0x71, 0x1a, 0x7b, 0xe6, 0xa1, 0x2e, 0x86, 0x9a, 0xed, 0xe9, 0x9f, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x4e, 0xea, 0x30, 0x31, 0xbb, 0x02, 0x00, 0x00, + // 498 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x53, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0xf5, 0x26, 0x6e, 0xda, 0x4e, 0x4a, 0xa9, 0x96, 0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0x1d, 0x4f, 0xa0, 0x57, 0xad, 0x91, 0x65, 0xf8, 0x39, 0xe8, + 0x15, 0xc2, 0x47, 0x6b, 0x8d, 0x3b, 0x5f, 0x8e, 0x71, 0xbc, 0x49, 0x37, 0x7b, 0xd7, 0xdc, 0xb7, + 0xf3, 0x05, 0xd1, 0x6e, 0x16, 0x44, 0xbb, 0x5d, 0x10, 0xf4, 0xb5, 0x24, 0xe8, 0x7b, 0x49, 0xd0, + 0x75, 0x49, 0xd0, 0xbc, 0x24, 0xe8, 0x57, 0x49, 0xd0, 0xef, 0x92, 0x68, 0xb7, 0x25, 0x41, 0x57, + 0x4b, 0xa2, 0xcd, 0x97, 0x44, 0xbb, 0x59, 0x12, 0xed, 0xfd, 0xd0, 0x0f, 0x65, 0x90, 0x4f, 0xed, + 0x0f, 0x3c, 0x76, 0xfc, 0x8c, 0x9e, 0xd3, 0x84, 0x3a, 0x11, 0xbf, 0x08, 0x9d, 0xf6, 0x37, 0x98, + 0xf6, 0x94, 0xda, 0xb3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x9b, 0x6f, 0x19, 0xc8, 0x19, 0x03, + 0x00, 0x00, } func (this *PushRequest) Equal(that interface{}) bool { @@ -350,6 +405,33 @@ func (this *StreamAdapter) Equal(that interface{}) bool { } return true } +func (this *LabelPairAdapter) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*LabelPairAdapter) + if !ok { + that2, ok := that.(LabelPairAdapter) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Name != that1.Name { + return false + } + if this.Value != that1.Value { + return false + } + return true +} func (this *EntryAdapter) Equal(that interface{}) bool { if that == nil { return this == nil @@ -375,9 +457,14 @@ func (this *EntryAdapter) Equal(that interface{}) bool { if this.Line != that1.Line { return false } - if this.NonIndexedLabels != that1.NonIndexedLabels { + if len(this.NonIndexedLabels) != len(that1.NonIndexedLabels) { return false } + for i := range this.NonIndexedLabels { + if !this.NonIndexedLabels[i].Equal(&that1.NonIndexedLabels[i]) { + return false + } + } return true } func (this *PushRequest) GoString() string { @@ -417,6 +504,17 @@ func (this *StreamAdapter) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *LabelPairAdapter) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&push.LabelPairAdapter{") + s = append(s, "Name: "+fmt.Sprintf("%#v", this.Name)+",\n") + s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *EntryAdapter) GoString() string { if this == nil { return "nil" @@ -425,7 +523,13 @@ func (this *EntryAdapter) GoString() string { s = append(s, "&push.EntryAdapter{") s = append(s, "Timestamp: "+fmt.Sprintf("%#v", this.Timestamp)+",\n") s = append(s, "Line: "+fmt.Sprintf("%#v", this.Line)+",\n") - s = append(s, "NonIndexedLabels: "+fmt.Sprintf("%#v", this.NonIndexedLabels)+",\n") + if this.NonIndexedLabels != nil { + vs := make([]*LabelPairAdapter, len(this.NonIndexedLabels)) + for i := range vs { + vs[i] = &this.NonIndexedLabels[i] + } + s = append(s, "NonIndexedLabels: "+fmt.Sprintf("%#v", vs)+",\n") + } s = append(s, "}") return strings.Join(s, "") } @@ -627,6 +731,43 @@ func (m *StreamAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *LabelPairAdapter) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *LabelPairAdapter) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LabelPairAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintPush(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintPush(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *EntryAdapter) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -648,11 +789,18 @@ func (m *EntryAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.NonIndexedLabels) > 0 { - i -= len(m.NonIndexedLabels) - copy(dAtA[i:], m.NonIndexedLabels) - i = encodeVarintPush(dAtA, i, uint64(len(m.NonIndexedLabels))) - i-- - dAtA[i] = 0x1a + for iNdEx := len(m.NonIndexedLabels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.NonIndexedLabels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPush(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } if len(m.Line) > 0 { i -= len(m.Line) @@ -729,6 +877,23 @@ func (m *StreamAdapter) Size() (n int) { return n } +func (m *LabelPairAdapter) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } + l = len(m.Value) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } + return n +} + func (m *EntryAdapter) Size() (n int) { if m == nil { return 0 @@ -741,9 +906,11 @@ func (m *EntryAdapter) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.NonIndexedLabels) - if l > 0 { - n += 1 + l + sovPush(uint64(l)) + if len(m.NonIndexedLabels) > 0 { + for _, e := range m.NonIndexedLabels { + l = e.Size() + n += 1 + l + sovPush(uint64(l)) + } } return n } @@ -790,14 +957,30 @@ func (this *StreamAdapter) String() string { }, "") return s } +func (this *LabelPairAdapter) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&LabelPairAdapter{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `Value:` + fmt.Sprintf("%v", this.Value) + `,`, + `}`, + }, "") + return s +} func (this *EntryAdapter) String() string { if this == nil { return "nil" } + repeatedStringForNonIndexedLabels := "[]LabelPairAdapter{" + for _, f := range this.NonIndexedLabels { + repeatedStringForNonIndexedLabels += strings.Replace(strings.Replace(f.String(), "LabelPairAdapter", "LabelPairAdapter", 1), `&`, ``, 1) + "," + } + repeatedStringForNonIndexedLabels += "}" s := strings.Join([]string{`&EntryAdapter{`, `Timestamp:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Timestamp), "Timestamp", "types.Timestamp", 1), `&`, ``, 1) + `,`, `Line:` + fmt.Sprintf("%v", this.Line) + `,`, - `NonIndexedLabels:` + fmt.Sprintf("%v", this.NonIndexedLabels) + `,`, + `NonIndexedLabels:` + repeatedStringForNonIndexedLabels + `,`, `}`, }, "") return s @@ -1088,6 +1271,123 @@ func (m *StreamAdapter) Unmarshal(dAtA []byte) error { } return nil } +func (m *LabelPairAdapter) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: LabelPairAdapter: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LabelPairAdapter: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + 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 ErrInvalidLengthPush + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPush + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + 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 ErrInvalidLengthPush + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPush + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Value = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPush(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPush + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPush + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *EntryAdapter) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1186,7 +1486,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPush @@ -1196,23 +1496,25 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthPush } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthPush } if postIndex > l { return io.ErrUnexpectedEOF } - m.NonIndexedLabels = string(dAtA[iNdEx:postIndex]) + m.NonIndexedLabels = append(m.NonIndexedLabels, LabelPairAdapter{}) + if err := m.NonIndexedLabels[len(m.NonIndexedLabels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/pkg/push/push.proto b/pkg/push/push.proto index 49be9a257726..1e0a3649bdb8 100644 --- a/pkg/push/push.proto +++ b/pkg/push/push.proto @@ -30,6 +30,11 @@ message StreamAdapter { uint64 hash = 3 [(gogoproto.jsontag) = "-"]; } +message LabelPairAdapter { + string name = 1; + string value = 2; +} + message EntryAdapter { google.protobuf.Timestamp timestamp = 1 [ (gogoproto.stdtime) = true, @@ -37,5 +42,8 @@ message EntryAdapter { (gogoproto.jsontag) = "ts" ]; string line = 2 [(gogoproto.jsontag) = "line"]; - string nonIndexedLabels = 3 [(gogoproto.jsontag) = "nonIndexedLabels,omitempty"]; + repeated LabelPairAdapter nonIndexedLabels = 3 [ + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "nonIndexedLabels,omitempty" + ]; } diff --git a/pkg/push/types.go b/pkg/push/types.go index 5c687d09738e..836609aa4eef 100644 --- a/pkg/push/types.go +++ b/pkg/push/types.go @@ -4,6 +4,8 @@ import ( "fmt" "io" "time" + + "github.com/prometheus/prometheus/model/labels" ) // Stream contains a unique labels set as a string and a set of entries for it. @@ -17,9 +19,48 @@ type Stream struct { // Entry is a log entry with a timestamp. type Entry struct { - Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` - Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` - NonIndexedLabels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` + Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` + NonIndexedLabels labels.Labels `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` +} + +type LabelAdapter labels.Label + +func (m *LabelAdapter) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *LabelAdapter) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LabelAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintPush(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintPush(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } func (m *Stream) Marshal() (dAtA []byte, err error) { @@ -92,11 +133,18 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.NonIndexedLabels) > 0 { - i -= len(m.NonIndexedLabels) - copy(dAtA[i:], m.NonIndexedLabels) - i = encodeVarintPush(dAtA, i, uint64(len(m.NonIndexedLabels))) - i-- - dAtA[i] = 0x1a + for iNdEx := len(m.NonIndexedLabels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := (*LabelAdapter)(&m.NonIndexedLabels[iNdEx]).MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPush(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } if len(m.Line) > 0 { i -= len(m.Line) @@ -353,6 +401,126 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPush + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPush + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NonIndexedLabels = append(m.NonIndexedLabels, labels.Label{}) + if err := (*LabelAdapter)(&m.NonIndexedLabels[len(m.NonIndexedLabels)-1]).Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPush(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPush + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPush + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *LabelAdapter) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: LabelPairAdapter: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LabelPairAdapter: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + 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 ErrInvalidLengthPush + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPush + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { @@ -379,7 +547,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.NonIndexedLabels = string(dAtA[iNdEx:postIndex]) + m.Value = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -440,7 +608,26 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.NonIndexedLabels) + if len(m.NonIndexedLabels) > 0 { + for _, e := range m.NonIndexedLabels { + l = (*LabelAdapter)(&e).Size() + n += 1 + l + sovPush(uint64(l)) + } + } + return n +} + +func (m *LabelAdapter) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } + l = len(m.Value) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -505,7 +692,37 @@ func (m *Entry) Equal(that interface{}) bool { if m.Line != that1.Line { return false } - if m.NonIndexedLabels != that1.NonIndexedLabels { + for i := range m.NonIndexedLabels { + if !(*LabelAdapter)(&m.NonIndexedLabels[i]).Equal(&that1.NonIndexedLabels[i]) { + return false + } + } + return true +} + +func (m *LabelAdapter) Equal(that interface{}) bool { + if that == nil { + return m == nil + } + + that1, ok := that.(*LabelPairAdapter) + if !ok { + that2, ok := that.(LabelPairAdapter) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return m == nil + } else if m == nil { + return false + } + if m.Name != that1.Name { + return false + } + if m.Value != that1.Value { return false } return true diff --git a/pkg/util/marshal/legacy/marshal_test.go b/pkg/util/marshal/legacy/marshal_test.go index eca3f6eab98c..0ae8bf60f290 100644 --- a/pkg/util/marshal/legacy/marshal_test.go +++ b/pkg/util/marshal/legacy/marshal_test.go @@ -7,6 +7,7 @@ import ( "time" json "github.com/json-iterator/go" + "github.com/prometheus/prometheus/model/labels" "github.com/stretchr/testify/require" loghttp "github.com/grafana/loki/pkg/loghttp/legacy" @@ -28,9 +29,12 @@ var queryTests = []struct { Line: "super line", }, { - Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), - Line: "super line with labels", - NonIndexedLabels: `{foo="a", bar="b"}`, + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }, }, }, Labels: `{test="test"}`, @@ -48,7 +52,10 @@ var queryTests = []struct { { "ts": "2019-09-13T18:32:23.380001319Z", "line": "super line with labels", - "labels": "{foo=\"a\", bar=\"b\"}" + "labels": { + "foo": "a", + "bar": "b" + } } ] } @@ -175,9 +182,12 @@ var tailTests = []struct { Line: "super line", }, { - Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), - Line: "super line with labels", - NonIndexedLabels: `{foo="a", bar="b"}`, + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }, }, }, Labels: "{test=\"test\"}", @@ -202,7 +212,10 @@ var tailTests = []struct { { "ts": "2019-09-13T18:32:23.380001319Z", "line": "super line with labels", - "labels": "{foo=\"a\", bar=\"b\"}" + "labels": { + "foo": "a", + "bar": "b" + } } ] } diff --git a/pkg/util/marshal/marshal_test.go b/pkg/util/marshal/marshal_test.go index dae110927cbe..40be7a7c472f 100644 --- a/pkg/util/marshal/marshal_test.go +++ b/pkg/util/marshal/marshal_test.go @@ -35,9 +35,12 @@ var queryTests = []struct { Line: "super line", }, { - Timestamp: time.Unix(0, 123456789012346), - Line: "super line with labels", - NonIndexedLabels: `{foo="a", bar="b"}`, + Timestamp: time.Unix(0, 123456789012346), + Line: "super line with labels", + NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }, }, }, Labels: `{test="test"}`, @@ -495,9 +498,12 @@ var tailTests = []struct { Line: "super line", }, { - Timestamp: time.Unix(0, 123456789012346), - Line: "super line with labels", - NonIndexedLabels: `{foo="a", bar="b"}`, + Timestamp: time.Unix(0, 123456789012346), + Line: "super line with labels", + NonIndexedLabels: labels.Labels{ + {Name: "foo", Value: "a"}, + {Name: "bar", Value: "b"}, + }, }, }, Labels: "{test=\"test\"}", diff --git a/pkg/util/marshal/query.go b/pkg/util/marshal/query.go index a39d40958835..8930b879c6f2 100644 --- a/pkg/util/marshal/query.go +++ b/pkg/util/marshal/query.go @@ -3,6 +3,7 @@ package marshal import ( "fmt" "strconv" + "unsafe" jsoniter "github.com/json-iterator/go" "github.com/pkg/errors" @@ -13,7 +14,6 @@ import ( "github.com/grafana/loki/pkg/loghttp" "github.com/grafana/loki/pkg/logproto" - "github.com/grafana/loki/pkg/logql/syntax" "github.com/grafana/loki/pkg/logqlmodel" ) @@ -91,39 +91,20 @@ func NewStream(s logproto.Stream) (loghttp.Stream, error) { return loghttp.Stream{}, errors.Wrapf(err, "err while creating labelset for %s", s.Labels) } - ret := loghttp.Stream{ - Labels: labels, - Entries: make([]loghttp.Entry, len(s.Entries)), + // Avoid a nil entries slice to be consistent with the decoding + entries := []loghttp.Entry{} + if len(s.Entries) > 0 { + entries = *(*[]loghttp.Entry)(unsafe.Pointer(&s.Entries)) } - for i, e := range s.Entries { - ret.Entries[i], err = NewEntry(e) - if err != nil { - return loghttp.Stream{}, err - } + ret := loghttp.Stream{ + Labels: labels, + Entries: entries, } return ret, nil } -// NewEntry constructs an Entry from a logproto.Entry -func NewEntry(e logproto.Entry) (loghttp.Entry, error) { - var labels loghttp.LabelSet - if e.NonIndexedLabels != "" { - lbls, err := syntax.ParseLabels(e.NonIndexedLabels) - if err != nil { - return loghttp.Entry{}, errors.Wrapf(err, "err while creating labelset for entry %s", e.NonIndexedLabels) - } - labels = lbls.Map() - } - - return loghttp.Entry{ - Timestamp: e.Timestamp, - Line: e.Line, - NonIndexedLabels: labels, - }, nil -} - func NewScalar(s promql.Scalar) loghttp.Scalar { return loghttp.Scalar{ Timestamp: model.Time(s.T), @@ -329,21 +310,15 @@ func encodeStream(stream logproto.Stream, s *jsoniter.Stream) error { s.WriteRaw(`"`) s.WriteMore() s.WriteStringWithHTMLEscaped(e.Line) - if e.NonIndexedLabels != "" { + if len(e.NonIndexedLabels) > 0 { s.WriteMore() s.WriteObjectStart() - labels, err = parser.ParseMetric(e.NonIndexedLabels) - if err != nil { - return err - } - - for i, l := range labels { + for i, lbl := range e.NonIndexedLabels { if i > 0 { s.WriteMore() } - - s.WriteObjectField(l.Name) - s.WriteString(l.Value) + s.WriteObjectField(lbl.Name) + s.WriteString(lbl.Value) } s.WriteObjectEnd() } diff --git a/pkg/util/unmarshal/legacy/unmarshal_test.go b/pkg/util/unmarshal/legacy/unmarshal_test.go index 691ac140786c..5492b22fa683 100644 --- a/pkg/util/unmarshal/legacy/unmarshal_test.go +++ b/pkg/util/unmarshal/legacy/unmarshal_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/prometheus/prometheus/model/labels" "github.com/stretchr/testify/require" "github.com/grafana/loki/pkg/logproto" @@ -26,9 +27,12 @@ var pushTests = []struct { Line: "super line", }, { - Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), - Line: "super line with labels", - NonIndexedLabels: `{foo="a", bar="b"}`, + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + NonIndexedLabels: labels.Labels{ + {Name: "a", Value: "1"}, + {Name: "b", Value: "2"}, + }, }, }, Labels: `{test="test"}`, @@ -46,7 +50,10 @@ var pushTests = []struct { { "ts": "2019-09-13T18:32:23.380001319Z", "line": "super line with labels", - "labels": "{foo=\"a\", bar=\"b\"}" + "labels": { + "a": "1", + "b": "2" + } } ] } diff --git a/pkg/util/unmarshal/unmarshal_test.go b/pkg/util/unmarshal/unmarshal_test.go index 86a4654f109e..4b1b67ead71b 100644 --- a/pkg/util/unmarshal/unmarshal_test.go +++ b/pkg/util/unmarshal/unmarshal_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/prometheus/prometheus/model/labels" "github.com/stretchr/testify/require" "github.com/grafana/loki/pkg/loghttp" @@ -50,9 +51,12 @@ var pushTests = []struct { { Entries: []logproto.Entry{ { - Timestamp: time.Unix(0, 123456789012345), - Line: "super line", - NonIndexedLabels: `{a="1", b="2"}`, + Timestamp: time.Unix(0, 123456789012345), + Line: "super line", + NonIndexedLabels: labels.Labels{ + {Name: "a", Value: "1"}, + {Name: "b", Value: "2"}, + }, }, }, Labels: `{test="test"}`, diff --git a/vendor/github.com/grafana/loki/pkg/push/push.pb.go b/vendor/github.com/grafana/loki/pkg/push/push.pb.go index 79849186a8ef..6fae3c1e7f73 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.pb.go +++ b/vendor/github.com/grafana/loki/pkg/push/push.pb.go @@ -164,16 +164,67 @@ func (m *StreamAdapter) GetHash() uint64 { return 0 } +type LabelPairAdapter struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *LabelPairAdapter) Reset() { *m = LabelPairAdapter{} } +func (*LabelPairAdapter) ProtoMessage() {} +func (*LabelPairAdapter) Descriptor() ([]byte, []int) { + return fileDescriptor_35ec442956852c9e, []int{3} +} +func (m *LabelPairAdapter) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *LabelPairAdapter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_LabelPairAdapter.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *LabelPairAdapter) XXX_Merge(src proto.Message) { + xxx_messageInfo_LabelPairAdapter.Merge(m, src) +} +func (m *LabelPairAdapter) XXX_Size() int { + return m.Size() +} +func (m *LabelPairAdapter) XXX_DiscardUnknown() { + xxx_messageInfo_LabelPairAdapter.DiscardUnknown(m) +} + +var xxx_messageInfo_LabelPairAdapter proto.InternalMessageInfo + +func (m *LabelPairAdapter) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *LabelPairAdapter) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + type EntryAdapter struct { - Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` - Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` - NonIndexedLabels string `protobuf:"bytes,3,opt,name=nonIndexedLabels,proto3" json:"nonIndexedLabels,omitempty"` + Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` + NonIndexedLabels []LabelPairAdapter `protobuf:"bytes,3,rep,name=nonIndexedLabels,proto3" json:"nonIndexedLabels,omitempty"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } func (*EntryAdapter) ProtoMessage() {} func (*EntryAdapter) Descriptor() ([]byte, []int) { - return fileDescriptor_35ec442956852c9e, []int{3} + return fileDescriptor_35ec442956852c9e, []int{4} } func (m *EntryAdapter) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -216,53 +267,57 @@ func (m *EntryAdapter) GetLine() string { return "" } -func (m *EntryAdapter) GetNonIndexedLabels() string { +func (m *EntryAdapter) GetNonIndexedLabels() []LabelPairAdapter { if m != nil { return m.NonIndexedLabels } - return "" + return nil } func init() { proto.RegisterType((*PushRequest)(nil), "logproto.PushRequest") proto.RegisterType((*PushResponse)(nil), "logproto.PushResponse") proto.RegisterType((*StreamAdapter)(nil), "logproto.StreamAdapter") + proto.RegisterType((*LabelPairAdapter)(nil), "logproto.LabelPairAdapter") proto.RegisterType((*EntryAdapter)(nil), "logproto.EntryAdapter") } func init() { proto.RegisterFile("pkg/push/push.proto", fileDescriptor_35ec442956852c9e) } var fileDescriptor_35ec442956852c9e = []byte{ - // 460 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x52, 0xcf, 0x6e, 0xd3, 0x30, - 0x1c, 0x8e, 0xdb, 0xd2, 0x6d, 0xee, 0x18, 0xc8, 0xb0, 0x51, 0x22, 0x64, 0x57, 0x39, 0xf5, 0x00, - 0x89, 0x54, 0x0e, 0x9c, 0x1b, 0x09, 0x69, 0x20, 0x0e, 0x28, 0x20, 0x90, 0xb8, 0xa5, 0xd4, 0x73, - 0xa2, 0x25, 0x76, 0x88, 0x1d, 0x89, 0xdd, 0x78, 0x84, 0xf1, 0x16, 0x3c, 0x07, 0xa7, 0x1d, 0x7b, - 0x9c, 0x38, 0x04, 0x9a, 0x5e, 0x50, 0x4e, 0x7b, 0x04, 0x14, 0x27, 0xa6, 0x63, 0x5c, 0x9c, 0xcf, - 0xbf, 0x7f, 0xdf, 0x97, 0xef, 0x67, 0x78, 0x2f, 0x3b, 0x65, 0x5e, 0x56, 0xc8, 0x48, 0x1f, 0x6e, - 0x96, 0x0b, 0x25, 0xd0, 0x6e, 0x22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1, 0x6b, 0x2c, 0x74, - 0xdf, 0x9a, 0x0a, 0xff, 0xa0, 0x23, 0xed, 0x29, 0x79, 0xfe, 0x93, 0x80, 0x60, 0xdb, 0x8c, 0x1e, - 0xc1, 0x41, 0x12, 0x73, 0x3a, 0xee, 0xe9, 0x5f, 0xdb, 0xad, 0x4b, 0xa2, 0xef, 0x81, 0x3e, 0xd1, - 0x4b, 0x78, 0x97, 0x0b, 0xfe, 0x82, 0x2f, 0xe9, 0x67, 0xba, 0x7c, 0xd5, 0x9a, 0xd0, 0xd7, 0x95, - 0xb8, 0x2e, 0x89, 0x7d, 0x33, 0xf7, 0x58, 0xa4, 0xb1, 0xa2, 0x69, 0xa6, 0xce, 0x82, 0xff, 0xfa, - 0x66, 0x73, 0x38, 0x6c, 0x8c, 0xa6, 0x39, 0x7a, 0x06, 0x07, 0x0d, 0x42, 0x87, 0x5b, 0x8f, 0xae, - 0xed, 0xd6, 0x3e, 0xba, 0x19, 0xee, 0x36, 0x63, 0xf9, 0xef, 0x56, 0x6b, 0x6c, 0x5d, 0xae, 0xb1, - 0x75, 0xb5, 0xc6, 0xe0, 0x4b, 0x85, 0xc1, 0xb7, 0x0a, 0x83, 0x8b, 0x0a, 0x83, 0x55, 0x85, 0xc1, - 0xaf, 0x0a, 0x83, 0xdf, 0x15, 0xb6, 0xae, 0x2a, 0x0c, 0xce, 0x37, 0xd8, 0x5a, 0x6d, 0xb0, 0x75, - 0xb9, 0xc1, 0xd6, 0x87, 0x09, 0x8b, 0x55, 0x54, 0x2c, 0xdc, 0x8f, 0x22, 0xf5, 0x58, 0x1e, 0x9e, - 0x84, 0x3c, 0xf4, 0x12, 0x71, 0x1a, 0x7b, 0xe6, 0xa1, 0x2e, 0x86, 0x9a, 0xed, 0xe9, 0x9f, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x4e, 0xea, 0x30, 0x31, 0xbb, 0x02, 0x00, 0x00, + // 498 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 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 0xf5, 0x74, 0x36, 0x5f, 0xcc, 0xb5, 0x1a, 0x39, 0x63, 0xb3, 0xf6, 0x09, 0x8f, 0x43, 0xc9, + 0xe2, 0x54, 0x5e, 0x7a, 0xff, 0xf5, 0x1d, 0x4f, 0xa0, 0x57, 0xad, 0x91, 0x65, 0xf8, 0x39, 0xe8, + 0x15, 0xc2, 0x47, 0x6b, 0x8d, 0x3b, 0x5f, 0x8e, 0x71, 0xbc, 0x49, 0x37, 0x7b, 0xd7, 0xdc, 0xb7, + 0xf3, 0x05, 0xd1, 0x6e, 0x16, 0x44, 0xbb, 0x5d, 0x10, 0xf4, 0xb5, 0x24, 0xe8, 0x7b, 0x49, 0xd0, + 0x75, 0x49, 0xd0, 0xbc, 0x24, 0xe8, 0x57, 0x49, 0xd0, 0xef, 0x92, 0x68, 0xb7, 0x25, 0x41, 0x57, + 0x4b, 0xa2, 0xcd, 0x97, 0x44, 0xbb, 0x59, 0x12, 0xed, 0xfd, 0xd0, 0x0f, 0x65, 0x90, 0x4f, 0xed, + 0x0f, 0x3c, 0x76, 0xfc, 0x8c, 0x9e, 0xd3, 0x84, 0x3a, 0x11, 0xbf, 0x08, 0x9d, 0xf6, 0x37, 0x98, + 0xf6, 0x94, 0xda, 0xb3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x9b, 0x6f, 0x19, 0xc8, 0x19, 0x03, + 0x00, 0x00, } func (this *PushRequest) Equal(that interface{}) bool { @@ -350,6 +405,33 @@ func (this *StreamAdapter) Equal(that interface{}) bool { } return true } +func (this *LabelPairAdapter) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*LabelPairAdapter) + if !ok { + that2, ok := that.(LabelPairAdapter) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Name != that1.Name { + return false + } + if this.Value != that1.Value { + return false + } + return true +} func (this *EntryAdapter) Equal(that interface{}) bool { if that == nil { return this == nil @@ -375,9 +457,14 @@ func (this *EntryAdapter) Equal(that interface{}) bool { if this.Line != that1.Line { return false } - if this.NonIndexedLabels != that1.NonIndexedLabels { + if len(this.NonIndexedLabels) != len(that1.NonIndexedLabels) { return false } + for i := range this.NonIndexedLabels { + if !this.NonIndexedLabels[i].Equal(&that1.NonIndexedLabels[i]) { + return false + } + } return true } func (this *PushRequest) GoString() string { @@ -417,6 +504,17 @@ func (this *StreamAdapter) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *LabelPairAdapter) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 6) + s = append(s, "&push.LabelPairAdapter{") + s = append(s, "Name: "+fmt.Sprintf("%#v", this.Name)+",\n") + s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *EntryAdapter) GoString() string { if this == nil { return "nil" @@ -425,7 +523,13 @@ func (this *EntryAdapter) GoString() string { s = append(s, "&push.EntryAdapter{") s = append(s, "Timestamp: "+fmt.Sprintf("%#v", this.Timestamp)+",\n") s = append(s, "Line: "+fmt.Sprintf("%#v", this.Line)+",\n") - s = append(s, "NonIndexedLabels: "+fmt.Sprintf("%#v", this.NonIndexedLabels)+",\n") + if this.NonIndexedLabels != nil { + vs := make([]*LabelPairAdapter, len(this.NonIndexedLabels)) + for i := range vs { + vs[i] = &this.NonIndexedLabels[i] + } + s = append(s, "NonIndexedLabels: "+fmt.Sprintf("%#v", vs)+",\n") + } s = append(s, "}") return strings.Join(s, "") } @@ -627,6 +731,43 @@ func (m *StreamAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *LabelPairAdapter) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *LabelPairAdapter) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LabelPairAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintPush(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintPush(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *EntryAdapter) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -648,11 +789,18 @@ func (m *EntryAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.NonIndexedLabels) > 0 { - i -= len(m.NonIndexedLabels) - copy(dAtA[i:], m.NonIndexedLabels) - i = encodeVarintPush(dAtA, i, uint64(len(m.NonIndexedLabels))) - i-- - dAtA[i] = 0x1a + for iNdEx := len(m.NonIndexedLabels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.NonIndexedLabels[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPush(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } if len(m.Line) > 0 { i -= len(m.Line) @@ -729,6 +877,23 @@ func (m *StreamAdapter) Size() (n int) { return n } +func (m *LabelPairAdapter) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } + l = len(m.Value) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } + return n +} + func (m *EntryAdapter) Size() (n int) { if m == nil { return 0 @@ -741,9 +906,11 @@ func (m *EntryAdapter) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.NonIndexedLabels) - if l > 0 { - n += 1 + l + sovPush(uint64(l)) + if len(m.NonIndexedLabels) > 0 { + for _, e := range m.NonIndexedLabels { + l = e.Size() + n += 1 + l + sovPush(uint64(l)) + } } return n } @@ -790,14 +957,30 @@ func (this *StreamAdapter) String() string { }, "") return s } +func (this *LabelPairAdapter) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&LabelPairAdapter{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `Value:` + fmt.Sprintf("%v", this.Value) + `,`, + `}`, + }, "") + return s +} func (this *EntryAdapter) String() string { if this == nil { return "nil" } + repeatedStringForNonIndexedLabels := "[]LabelPairAdapter{" + for _, f := range this.NonIndexedLabels { + repeatedStringForNonIndexedLabels += strings.Replace(strings.Replace(f.String(), "LabelPairAdapter", "LabelPairAdapter", 1), `&`, ``, 1) + "," + } + repeatedStringForNonIndexedLabels += "}" s := strings.Join([]string{`&EntryAdapter{`, `Timestamp:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Timestamp), "Timestamp", "types.Timestamp", 1), `&`, ``, 1) + `,`, `Line:` + fmt.Sprintf("%v", this.Line) + `,`, - `NonIndexedLabels:` + fmt.Sprintf("%v", this.NonIndexedLabels) + `,`, + `NonIndexedLabels:` + repeatedStringForNonIndexedLabels + `,`, `}`, }, "") return s @@ -1088,6 +1271,123 @@ func (m *StreamAdapter) Unmarshal(dAtA []byte) error { } return nil } +func (m *LabelPairAdapter) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: LabelPairAdapter: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LabelPairAdapter: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + 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 ErrInvalidLengthPush + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPush + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + 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 ErrInvalidLengthPush + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPush + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Value = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPush(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPush + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPush + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *EntryAdapter) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1186,7 +1486,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPush @@ -1196,23 +1496,25 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthPush } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthPush } if postIndex > l { return io.ErrUnexpectedEOF } - m.NonIndexedLabels = string(dAtA[iNdEx:postIndex]) + m.NonIndexedLabels = append(m.NonIndexedLabels, LabelPairAdapter{}) + if err := m.NonIndexedLabels[len(m.NonIndexedLabels)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/vendor/github.com/grafana/loki/pkg/push/push.proto b/vendor/github.com/grafana/loki/pkg/push/push.proto index 49be9a257726..1e0a3649bdb8 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.proto +++ b/vendor/github.com/grafana/loki/pkg/push/push.proto @@ -30,6 +30,11 @@ message StreamAdapter { uint64 hash = 3 [(gogoproto.jsontag) = "-"]; } +message LabelPairAdapter { + string name = 1; + string value = 2; +} + message EntryAdapter { google.protobuf.Timestamp timestamp = 1 [ (gogoproto.stdtime) = true, @@ -37,5 +42,8 @@ message EntryAdapter { (gogoproto.jsontag) = "ts" ]; string line = 2 [(gogoproto.jsontag) = "line"]; - string nonIndexedLabels = 3 [(gogoproto.jsontag) = "nonIndexedLabels,omitempty"]; + repeated LabelPairAdapter nonIndexedLabels = 3 [ + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "nonIndexedLabels,omitempty" + ]; } diff --git a/vendor/github.com/grafana/loki/pkg/push/types.go b/vendor/github.com/grafana/loki/pkg/push/types.go index 5c687d09738e..836609aa4eef 100644 --- a/vendor/github.com/grafana/loki/pkg/push/types.go +++ b/vendor/github.com/grafana/loki/pkg/push/types.go @@ -4,6 +4,8 @@ import ( "fmt" "io" "time" + + "github.com/prometheus/prometheus/model/labels" ) // Stream contains a unique labels set as a string and a set of entries for it. @@ -17,9 +19,48 @@ type Stream struct { // Entry is a log entry with a timestamp. type Entry struct { - Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` - Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` - NonIndexedLabels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` + Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` + NonIndexedLabels labels.Labels `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` +} + +type LabelAdapter labels.Label + +func (m *LabelAdapter) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *LabelAdapter) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *LabelAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintPush(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0x12 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintPush(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil } func (m *Stream) Marshal() (dAtA []byte, err error) { @@ -92,11 +133,18 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.NonIndexedLabels) > 0 { - i -= len(m.NonIndexedLabels) - copy(dAtA[i:], m.NonIndexedLabels) - i = encodeVarintPush(dAtA, i, uint64(len(m.NonIndexedLabels))) - i-- - dAtA[i] = 0x1a + for iNdEx := len(m.NonIndexedLabels) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := (*LabelAdapter)(&m.NonIndexedLabels[iNdEx]).MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPush(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } if len(m.Line) > 0 { i -= len(m.Line) @@ -353,6 +401,126 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPush + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPush + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NonIndexedLabels = append(m.NonIndexedLabels, labels.Label{}) + if err := (*LabelAdapter)(&m.NonIndexedLabels[len(m.NonIndexedLabels)-1]).Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPush(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthPush + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthPush + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *LabelAdapter) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: LabelPairAdapter: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: LabelPairAdapter: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPush + } + 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 ErrInvalidLengthPush + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPush + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { @@ -379,7 +547,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.NonIndexedLabels = string(dAtA[iNdEx:postIndex]) + m.Value = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -440,7 +608,26 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.NonIndexedLabels) + if len(m.NonIndexedLabels) > 0 { + for _, e := range m.NonIndexedLabels { + l = (*LabelAdapter)(&e).Size() + n += 1 + l + sovPush(uint64(l)) + } + } + return n +} + +func (m *LabelAdapter) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } + l = len(m.Value) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -505,7 +692,37 @@ func (m *Entry) Equal(that interface{}) bool { if m.Line != that1.Line { return false } - if m.NonIndexedLabels != that1.NonIndexedLabels { + for i := range m.NonIndexedLabels { + if !(*LabelAdapter)(&m.NonIndexedLabels[i]).Equal(&that1.NonIndexedLabels[i]) { + return false + } + } + return true +} + +func (m *LabelAdapter) Equal(that interface{}) bool { + if that == nil { + return m == nil + } + + that1, ok := that.(*LabelPairAdapter) + if !ok { + that2, ok := that.(LabelPairAdapter) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return m == nil + } else if m == nil { + return false + } + if m.Name != that1.Name { + return false + } + if m.Value != that1.Value { return false } return true