From b7995562324e0a0a39f31be812347d4bb67c0f17 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 13 Jun 2023 09:47:37 +0200 Subject: [PATCH 01/36] Add metadata to push payload --- pkg/push/push.pb.go | 119 +++++++++++++++++++++++++++++++---------- pkg/push/push.proto | 4 ++ pkg/push/types.go | 65 +++++++++++++++++++--- pkg/push/types_test.go | 16 +++--- 4 files changed, 159 insertions(+), 45 deletions(-) diff --git a/pkg/push/push.pb.go b/pkg/push/push.pb.go index dd007f3bf53fb..b96f8002d3a8c 100644 --- a/pkg/push/push.pb.go +++ b/pkg/push/push.pb.go @@ -167,6 +167,11 @@ func (m *StreamAdapter) GetHash() uint64 { 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"` + // TODO: maybe we can use the labels.Labels type here? + // + // So we can avoid the conversion to and from string. + // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. + MetadataLabels string `protobuf:"bytes,3,opt,name=metadataLabels,proto3" json:"metadataLabels"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } @@ -215,6 +220,13 @@ func (m *EntryAdapter) GetLine() string { return "" } +func (m *EntryAdapter) GetMetadataLabels() string { + if m != nil { + return m.MetadataLabels + } + return "" +} + func init() { proto.RegisterType((*PushRequest)(nil), "logproto.PushRequest") proto.RegisterType((*PushResponse)(nil), "logproto.PushResponse") @@ -225,34 +237,35 @@ func init() { func init() { proto.RegisterFile("pkg/push/push.proto", fileDescriptor_35ec442956852c9e) } var fileDescriptor_35ec442956852c9e = []byte{ - // 422 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0x41, 0x6f, 0xd3, 0x30, - 0x18, 0xb5, 0xbb, 0xd2, 0x6d, 0xee, 0x18, 0x92, 0x61, 0xa3, 0x44, 0xc8, 0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0x32, 0xf3, 0x45, 0xc9, 0x2e, 0x59, 0xce, 0xfc, 0x54, 0x5e, - 0x25, 0xbe, 0x7d, 0x5b, 0xd1, 0xc4, 0xa8, 0x3d, 0xff, 0x13, 0x00, 0x00, 0xff, 0xff, 0x5c, 0x30, - 0xfc, 0xe9, 0x6e, 0x02, 0x00, 0x00, + // 448 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0xbf, 0x8e, 0xd3, 0x30, + 0x1c, 0x8e, 0xdb, 0xd2, 0xbb, 0x73, 0x8f, 0x22, 0x19, 0xee, 0x28, 0x15, 0xb2, 0xab, 0x4c, 0x5d, + 0x48, 0xa4, 0x32, 0x20, 0xb1, 0x35, 0x12, 0xd2, 0x0d, 0x0c, 0xc8, 0x20, 0x90, 0xd8, 0x5c, 0xce, + 0xe7, 0x44, 0x97, 0xc4, 0x21, 0x76, 0x06, 0x36, 0x1e, 0xe1, 0x78, 0x0b, 0x66, 0x9e, 0xe2, 0xc6, + 0x8e, 0x27, 0x86, 0x40, 0xd3, 0x05, 0x65, 0xba, 0x47, 0x40, 0x71, 0x62, 0x7a, 0x74, 0x71, 0xbe, + 0xdf, 0x1f, 0xff, 0xbe, 0x2f, 0xdf, 0xcf, 0xf0, 0x61, 0x76, 0x29, 0xfc, 0xac, 0x50, 0xa1, 0x39, + 0xbc, 0x2c, 0x97, 0x5a, 0xa2, 0xc3, 0x58, 0x0a, 0x83, 0xa6, 0x8f, 0x84, 0x14, 0xd2, 0x40, 0xbf, + 0x41, 0x6d, 0x7d, 0x4a, 0x84, 0x94, 0x22, 0xe6, 0xbe, 0x89, 0x56, 0xc5, 0x85, 0xaf, 0xa3, 0x84, + 0x2b, 0xcd, 0x92, 0xac, 0x6d, 0x70, 0x3f, 0xc0, 0xd1, 0x9b, 0x42, 0x85, 0x94, 0x7f, 0x2e, 0xb8, + 0xd2, 0xe8, 0x0c, 0x1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 0xd0, 0x37, 0x7d, 0xa8, 0x2e, + 0xc9, 0x5e, 0x85, 0xee, 0xc5, 0x8b, 0x25, 0x1c, 0x36, 0xc6, 0xf2, 0x1c, 0xbd, 0x80, 0x83, 0x06, + 0xa1, 0x93, 0x9d, 0x27, 0x77, 0x76, 0x39, 0x3d, 0xdd, 0x4f, 0x77, 0x9b, 0x70, 0x82, 0xf7, 0xeb, + 0x0d, 0x76, 0x6e, 0x36, 0xd8, 0xb9, 0xdd, 0x60, 0xf0, 0xb5, 0xc2, 0xe0, 0x7b, 0x85, 0xc1, 0x75, + 0x85, 0xc1, 0xba, 0xc2, 0xe0, 0x77, 0x85, 0xc1, 0x9f, 0x0a, 0x3b, 0xb7, 0x15, 0x06, 0x57, 0x5b, + 0xec, 0xac, 0xb7, 0xd8, 0xb9, 0xd9, 0x62, 0xe7, 0xe3, 0x4c, 0x44, 0x3a, 0x2c, 0x56, 0xde, 0x27, + 0x99, 0xf8, 0x22, 0x67, 0x17, 0x2c, 0x65, 0x7e, 0x2c, 0x2f, 0x23, 0xdf, 0x3e, 0xcc, 0xd5, 0xd0, + 0xb0, 0x3d, 0xff, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x13, 0xd9, 0x4f, 0xab, 0x02, 0x00, 0x00, } func (this *PushRequest) Equal(that interface{}) bool { @@ -365,6 +378,9 @@ func (this *EntryAdapter) Equal(that interface{}) bool { if this.Line != that1.Line { return false } + if this.MetadataLabels != that1.MetadataLabels { + return false + } return true } func (this *PushRequest) GoString() string { @@ -408,10 +424,11 @@ func (this *EntryAdapter) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) 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, "MetadataLabels: "+fmt.Sprintf("%#v", this.MetadataLabels)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -633,6 +650,13 @@ func (m *EntryAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.MetadataLabels) > 0 { + i -= len(m.MetadataLabels) + copy(dAtA[i:], m.MetadataLabels) + i = encodeVarintPush(dAtA, i, uint64(len(m.MetadataLabels))) + i-- + dAtA[i] = 0x1a + } if len(m.Line) > 0 { i -= len(m.Line) copy(dAtA[i:], m.Line) @@ -720,6 +744,10 @@ func (m *EntryAdapter) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } + l = len(m.MetadataLabels) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } return n } @@ -772,6 +800,7 @@ func (this *EntryAdapter) String() string { 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) + `,`, + `MetadataLabels:` + fmt.Sprintf("%v", this.MetadataLabels) + `,`, `}`, }, "") return s @@ -1156,6 +1185,38 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { } m.Line = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MetadataLabels", 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.MetadataLabels = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipPush(dAtA[iNdEx:]) diff --git a/pkg/push/push.proto b/pkg/push/push.proto index 39f9318df91f4..d0f50ede8d11e 100644 --- a/pkg/push/push.proto +++ b/pkg/push/push.proto @@ -37,4 +37,8 @@ message EntryAdapter { (gogoproto.jsontag) = "ts" ]; string line = 2 [(gogoproto.jsontag) = "line"]; + // TODO: maybe we can use the labels.Labels type here? + // So we can avoid the conversion to and from string. + // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. + string metadataLabels = 3 [(gogoproto.jsontag) = "metadataLabels"]; } diff --git a/pkg/push/types.go b/pkg/push/types.go index c6fd14a5fbe24..a4d40d58ea583 100644 --- a/pkg/push/types.go +++ b/pkg/push/types.go @@ -4,6 +4,8 @@ import ( "fmt" "io" "time" + + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" ) // Stream contains a unique labels set as a string and a set of entries for it. @@ -17,8 +19,9 @@ 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"` + Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` + MetadataLabels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"metadataLabels"` } func (m *Stream) Marshal() (dAtA []byte, err error) { @@ -90,6 +93,13 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.MetadataLabels) > 0 { + i -= len(m.MetadataLabels) + copy(dAtA[i:], m.MetadataLabels) + i = encodeVarintPush(dAtA, i, uint64(len(m.MetadataLabels))) + i-- + dAtA[i] = 0x1a + } if len(m.Line) > 0 { i -= len(m.Line) copy(dAtA[i:], m.Line) @@ -97,12 +107,12 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - n7, err7 := StdTimeMarshalTo(m.Timestamp, dAtA[i-SizeOfStdTime(m.Timestamp):]) - if err7 != nil { - return 0, err7 + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp):]) + if err1 != nil { + return 0, err1 } - i -= n7 - i = encodeVarintPush(dAtA, i, uint64(n7)) + i -= n1 + i = encodeVarintPush(dAtA, i, uint64(n1)) i-- dAtA[i] = 0xa return len(dAtA) - i, nil @@ -305,7 +315,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -341,6 +351,38 @@ func (m *Entry) Unmarshal(dAtA []byte) error { } m.Line = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MetadataLabels", 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.MetadataLabels = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipPush(dAtA[iNdEx:]) @@ -400,6 +442,10 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } + l = len(m.MetadataLabels) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } return n } @@ -461,5 +507,8 @@ func (m *Entry) Equal(that interface{}) bool { if m.Line != that1.Line { return false } + if m.MetadataLabels != that1.MetadataLabels { + return false + } return true } diff --git a/pkg/push/types_test.go b/pkg/push/types_test.go index 98f905b6c968d..28c787c72c485 100644 --- a/pkg/push/types_test.go +++ b/pkg/push/types_test.go @@ -14,20 +14,20 @@ var ( Labels: `{job="foobar", cluster="foo-central1", namespace="bar", container_name="buzz"}`, Hash: 1234*10 ^ 9, Entries: []Entry{ - {now, line}, - {now.Add(1 * time.Second), line}, - {now.Add(2 * time.Second), line}, - {now.Add(3 * time.Second), line}, + {now, line, ""}, + {now.Add(1 * time.Second), line, ""}, + {now.Add(2 * time.Second), line, ""}, + {now.Add(3 * time.Second), line, ""}, }, } streamAdapter = StreamAdapter{ Labels: `{job="foobar", cluster="foo-central1", namespace="bar", container_name="buzz"}`, Hash: 1234*10 ^ 9, Entries: []EntryAdapter{ - {now, line}, - {now.Add(1 * time.Second), line}, - {now.Add(2 * time.Second), line}, - {now.Add(3 * time.Second), line}, + {now, line, ""}, + {now.Add(1 * time.Second), line, ""}, + {now.Add(2 * time.Second), line, ""}, + {now.Add(3 * time.Second), line, ""}, }, } ) From b0810c8c98c0f963ac97ca1851e895b7248815b3 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 13 Jun 2023 09:52:06 +0200 Subject: [PATCH 02/36] Add metadata to tests --- pkg/push/types_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/push/types_test.go b/pkg/push/types_test.go index 28c787c72c485..45fbf6aa22386 100644 --- a/pkg/push/types_test.go +++ b/pkg/push/types_test.go @@ -15,9 +15,9 @@ var ( Hash: 1234*10 ^ 9, Entries: []Entry{ {now, line, ""}, - {now.Add(1 * time.Second), line, ""}, + {now.Add(1 * time.Second), line, `{traceID="1234"`}, {now.Add(2 * time.Second), line, ""}, - {now.Add(3 * time.Second), line, ""}, + {now.Add(3 * time.Second), line, `{user="abc"`}, }, } streamAdapter = StreamAdapter{ @@ -25,9 +25,9 @@ var ( Hash: 1234*10 ^ 9, Entries: []EntryAdapter{ {now, line, ""}, - {now.Add(1 * time.Second), line, ""}, + {now.Add(1 * time.Second), line, `{traceID="1234"`}, {now.Add(2 * time.Second), line, ""}, - {now.Add(3 * time.Second), line, ""}, + {now.Add(3 * time.Second), line, `{user="abc"`}, }, } ) From b7ae1313ccf30db8c86fab4b770b397a81a74787 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 13 Jun 2023 10:41:33 +0200 Subject: [PATCH 03/36] update vendor push pkg --- .../grafana/loki/pkg/push/push.pb.go | 119 +++++++++++++----- .../grafana/loki/pkg/push/push.proto | 4 + .../github.com/grafana/loki/pkg/push/types.go | 65 ++++++++-- 3 files changed, 151 insertions(+), 37 deletions(-) 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 dd007f3bf53fb..b96f8002d3a8c 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.pb.go +++ b/vendor/github.com/grafana/loki/pkg/push/push.pb.go @@ -167,6 +167,11 @@ func (m *StreamAdapter) GetHash() uint64 { 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"` + // TODO: maybe we can use the labels.Labels type here? + // + // So we can avoid the conversion to and from string. + // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. + MetadataLabels string `protobuf:"bytes,3,opt,name=metadataLabels,proto3" json:"metadataLabels"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } @@ -215,6 +220,13 @@ func (m *EntryAdapter) GetLine() string { return "" } +func (m *EntryAdapter) GetMetadataLabels() string { + if m != nil { + return m.MetadataLabels + } + return "" +} + func init() { proto.RegisterType((*PushRequest)(nil), "logproto.PushRequest") proto.RegisterType((*PushResponse)(nil), "logproto.PushResponse") @@ -225,34 +237,35 @@ func init() { func init() { proto.RegisterFile("pkg/push/push.proto", fileDescriptor_35ec442956852c9e) } var fileDescriptor_35ec442956852c9e = []byte{ - // 422 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0x41, 0x6f, 0xd3, 0x30, - 0x18, 0xb5, 0xbb, 0xd2, 0x6d, 0xee, 0x18, 0x92, 0x61, 0xa3, 0x44, 0xc8, 0xae, 0x72, 0xea, 0x85, - 0x44, 0x2a, 0x07, 0xce, 0x8d, 0x84, 0xb4, 0x23, 0x0a, 0x08, 0x24, 0x6e, 0x0e, 0x78, 0x4e, 0xb4, - 0x24, 0x0e, 0xb1, 0x83, 0xc4, 0x8d, 0x9f, 0x30, 0xfe, 0x05, 0x3f, 0x65, 0xc7, 0x1e, 0x27, 0x0e, - 0x81, 0xa6, 0x17, 0x94, 0xd3, 0x7e, 0x02, 0x8a, 0x13, 0xd3, 0xc2, 0xc5, 0x79, 0x7e, 0xfe, 0xfc, - 0xbd, 0xf7, 0xbd, 0x18, 0x3d, 0x2c, 0xae, 0x84, 0x5f, 0x54, 0x2a, 0x36, 0x8b, 0x57, 0x94, 0x52, - 0x4b, 0x7c, 0x94, 0x4a, 0x61, 0x90, 0xf3, 0x48, 0x48, 0x21, 0x0d, 0xf4, 0x3b, 0xd4, 0x9f, 0x3b, - 0x54, 0x48, 0x29, 0x52, 0xee, 0x9b, 0x5d, 0x54, 0x5d, 0xfa, 0x3a, 0xc9, 0xb8, 0xd2, 0x2c, 0x2b, - 0xfa, 0x02, 0xf7, 0x1d, 0x9a, 0xbe, 0xaa, 0x54, 0x1c, 0xf2, 0x4f, 0x15, 0x57, 0x1a, 0x5f, 0xa0, - 0x43, 0xa5, 0x4b, 0xce, 0x32, 0x35, 0x83, 0xf3, 0x83, 0xc5, 0x74, 0xf9, 0xd8, 0xb3, 0x0a, 0xde, - 0x6b, 0x73, 0xb0, 0xfa, 0xc8, 0x0a, 0xcd, 0xcb, 0xe0, 0xec, 0x47, 0x4d,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d, 0x08, 0xfc, 0xde, 0x10, 0x78, 0xd3, 0x10, 0xb8, 0x6e, 0x08, 0xfc, 0xd5, 0x10, 0xf8, 0xbb, - 0x21, 0xe0, 0xae, 0x21, 0xf0, 0x7a, 0x4b, 0xc0, 0x7a, 0x4b, 0xc0, 0xed, 0x96, 0x80, 0xf7, 0x73, - 0x91, 0xe8, 0xb8, 0x8a, 0xbc, 0x0f, 0x32, 0xf3, 0x45, 0xc9, 0x2e, 0x59, 0xce, 0xfc, 0x54, 0x5e, - 0x25, 0xbe, 0x7d, 0x5b, 0xd1, 0xc4, 0xa8, 0x3d, 0xff, 0x13, 0x00, 0x00, 0xff, 0xff, 0x5c, 0x30, - 0xfc, 0xe9, 0x6e, 0x02, 0x00, 0x00, + // 448 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0xbf, 0x8e, 0xd3, 0x30, + 0x1c, 0x8e, 0xdb, 0xd2, 0xbb, 0x73, 0x8f, 0x22, 0x19, 0xee, 0x28, 0x15, 0xb2, 0xab, 0x4c, 0x5d, + 0x48, 0xa4, 0x32, 0x20, 0xb1, 0x35, 0x12, 0xd2, 0x0d, 0x0c, 0xc8, 0x20, 0x90, 0xd8, 0x5c, 0xce, + 0xe7, 0x44, 0x97, 0xc4, 0x21, 0x76, 0x06, 0x36, 0x1e, 0xe1, 0x78, 0x0b, 0x66, 0x9e, 0xe2, 0xc6, + 0x8e, 0x27, 0x86, 0x40, 0xd3, 0x05, 0x65, 0xba, 0x47, 0x40, 0x71, 0x62, 0x7a, 0x74, 0x71, 0xbe, + 0xdf, 0x1f, 0xff, 0xbe, 0x2f, 0xdf, 0xcf, 0xf0, 0x61, 0x76, 0x29, 0xfc, 0xac, 0x50, 0xa1, 0x39, + 0xbc, 0x2c, 0x97, 0x5a, 0xa2, 0xc3, 0x58, 0x0a, 0x83, 0xa6, 0x8f, 0x84, 0x14, 0xd2, 0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18, 0x77, 0xa4, 0x3d, 0xad, 0xae, 0x7e, 0x11, 0x40, 0x77, 0x97, 0xd1, + 0x53, 0x38, 0x88, 0xa3, 0x94, 0x4f, 0x7a, 0xe6, 0xd7, 0x0e, 0xeb, 0x92, 0x98, 0x98, 0x9a, 0x13, + 0xbd, 0x84, 0xe3, 0x84, 0x6b, 0x76, 0xce, 0x34, 0x7b, 0xdd, 0x5a, 0xd0, 0x37, 0x7d, 0xa8, 0x2e, + 0xc9, 0x5e, 0x85, 0xee, 0xc5, 0x8b, 0x25, 0x1c, 0x36, 0xc6, 0xf2, 0x1c, 0xbd, 0x80, 0x83, 0x06, + 0xa1, 0x93, 0x9d, 0x27, 0x77, 0x76, 0x39, 0x3d, 0xdd, 0x4f, 0x77, 0x9b, 0x70, 0x82, 0xf7, 0xeb, + 0x0d, 0x76, 0x6e, 0x36, 0xd8, 0xb9, 0xdd, 0x60, 0xf0, 0xb5, 0xc2, 0xe0, 0x7b, 0x85, 0xc1, 0x75, + 0x85, 0xc1, 0xba, 0xc2, 0xe0, 0x77, 0x85, 0xc1, 0x9f, 0x0a, 0x3b, 0xb7, 0x15, 0x06, 0x57, 0x5b, + 0xec, 0xac, 0xb7, 0xd8, 0xb9, 0xd9, 0x62, 0xe7, 0xe3, 0x4c, 0x44, 0x3a, 0x2c, 0x56, 0xde, 0x27, + 0x99, 0xf8, 0x22, 0x67, 0x17, 0x2c, 0x65, 0x7e, 0x2c, 0x2f, 0x23, 0xdf, 0x3e, 0xcc, 0xd5, 0xd0, + 0xb0, 0x3d, 0xff, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x13, 0xd9, 0x4f, 0xab, 0x02, 0x00, 0x00, } func (this *PushRequest) Equal(that interface{}) bool { @@ -365,6 +378,9 @@ func (this *EntryAdapter) Equal(that interface{}) bool { if this.Line != that1.Line { return false } + if this.MetadataLabels != that1.MetadataLabels { + return false + } return true } func (this *PushRequest) GoString() string { @@ -408,10 +424,11 @@ func (this *EntryAdapter) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) 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, "MetadataLabels: "+fmt.Sprintf("%#v", this.MetadataLabels)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -633,6 +650,13 @@ func (m *EntryAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.MetadataLabels) > 0 { + i -= len(m.MetadataLabels) + copy(dAtA[i:], m.MetadataLabels) + i = encodeVarintPush(dAtA, i, uint64(len(m.MetadataLabels))) + i-- + dAtA[i] = 0x1a + } if len(m.Line) > 0 { i -= len(m.Line) copy(dAtA[i:], m.Line) @@ -720,6 +744,10 @@ func (m *EntryAdapter) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } + l = len(m.MetadataLabels) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } return n } @@ -772,6 +800,7 @@ func (this *EntryAdapter) String() string { 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) + `,`, + `MetadataLabels:` + fmt.Sprintf("%v", this.MetadataLabels) + `,`, `}`, }, "") return s @@ -1156,6 +1185,38 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { } m.Line = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MetadataLabels", 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.MetadataLabels = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipPush(dAtA[iNdEx:]) diff --git a/vendor/github.com/grafana/loki/pkg/push/push.proto b/vendor/github.com/grafana/loki/pkg/push/push.proto index 39f9318df91f4..d0f50ede8d11e 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.proto +++ b/vendor/github.com/grafana/loki/pkg/push/push.proto @@ -37,4 +37,8 @@ message EntryAdapter { (gogoproto.jsontag) = "ts" ]; string line = 2 [(gogoproto.jsontag) = "line"]; + // TODO: maybe we can use the labels.Labels type here? + // So we can avoid the conversion to and from string. + // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. + string metadataLabels = 3 [(gogoproto.jsontag) = "metadataLabels"]; } diff --git a/vendor/github.com/grafana/loki/pkg/push/types.go b/vendor/github.com/grafana/loki/pkg/push/types.go index c6fd14a5fbe24..a4d40d58ea583 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_gogo_protobuf_types "github.com/gogo/protobuf/types" ) // Stream contains a unique labels set as a string and a set of entries for it. @@ -17,8 +19,9 @@ 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"` + Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` + MetadataLabels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"metadataLabels"` } func (m *Stream) Marshal() (dAtA []byte, err error) { @@ -90,6 +93,13 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.MetadataLabels) > 0 { + i -= len(m.MetadataLabels) + copy(dAtA[i:], m.MetadataLabels) + i = encodeVarintPush(dAtA, i, uint64(len(m.MetadataLabels))) + i-- + dAtA[i] = 0x1a + } if len(m.Line) > 0 { i -= len(m.Line) copy(dAtA[i:], m.Line) @@ -97,12 +107,12 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - n7, err7 := StdTimeMarshalTo(m.Timestamp, dAtA[i-SizeOfStdTime(m.Timestamp):]) - if err7 != nil { - return 0, err7 + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp):]) + if err1 != nil { + return 0, err1 } - i -= n7 - i = encodeVarintPush(dAtA, i, uint64(n7)) + i -= n1 + i = encodeVarintPush(dAtA, i, uint64(n1)) i-- dAtA[i] = 0xa return len(dAtA) - i, nil @@ -305,7 +315,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -341,6 +351,38 @@ func (m *Entry) Unmarshal(dAtA []byte) error { } m.Line = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MetadataLabels", 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.MetadataLabels = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipPush(dAtA[iNdEx:]) @@ -400,6 +442,10 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } + l = len(m.MetadataLabels) + if l > 0 { + n += 1 + l + sovPush(uint64(l)) + } return n } @@ -461,5 +507,8 @@ func (m *Entry) Equal(that interface{}) bool { if m.Line != that1.Line { return false } + if m.MetadataLabels != that1.MetadataLabels { + return false + } return true } From 9bec73ab7eff3c3451493dd5b41880381c9781fd Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 13 Jun 2023 10:53:17 +0200 Subject: [PATCH 04/36] WIP fix tests --- integration/client/client.go | 16 +++++++++++++--- integration/loki_micro_services_delete_test.go | 6 +++++- integration/loki_micro_services_test.go | 10 +++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/integration/client/client.go b/integration/client/client.go index 43f9cc724ee54..c37b5fdd483db 100644 --- a/integration/client/client.go +++ b/integration/client/client.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "github.com/prometheus/prometheus/model/labels" "github.com/weaveworks/common/user" ) @@ -86,13 +87,21 @@ func New(instanceID, token, baseURL string, opts ...Option) *Client { // PushLogLine creates a new logline with the current time as timestamp func (c *Client) PushLogLine(line string, extraLabels ...map[string]string) error { - return c.pushLogLine(line, c.Now, extraLabels...) + return c.pushLogLine(line, c.Now, nil, extraLabels...) +} + +func (c *Client) PushLogLineWithMetadata(line string, metadata map[string]string, extraLabels ...map[string]string) error { + return c.PushLogLineWithTimestampAndMetadata(line, c.Now, metadata, extraLabels...) } // PushLogLineWithTimestamp creates a new logline at the given timestamp // The timestamp has to be a Unix timestamp (epoch seconds) func (c *Client) PushLogLineWithTimestamp(line string, timestamp time.Time, extraLabelList ...map[string]string) error { - return c.pushLogLine(line, timestamp, extraLabelList...) + return c.pushLogLine(line, timestamp, nil, extraLabelList...) +} + +func (c *Client) PushLogLineWithTimestampAndMetadata(line string, timestamp time.Time, metadata map[string]string, extraLabelList ...map[string]string) error { + return c.pushLogLine(line, timestamp, labels.FromMap(metadata), extraLabelList...) } func formatTS(ts time.Time) string { @@ -105,7 +114,7 @@ type stream struct { } // pushLogLine creates a new logline -func (c *Client) pushLogLine(line string, timestamp time.Time, extraLabelList ...map[string]string) error { +func (c *Client) pushLogLine(line string, timestamp time.Time, metadata labels.Labels, extraLabelList ...map[string]string) error { apiEndpoint := fmt.Sprintf("%s/loki/api/v1/push", c.baseURL) s := stream{ @@ -116,6 +125,7 @@ func (c *Client) pushLogLine(line string, timestamp time.Time, extraLabelList .. { formatTS(timestamp), line, + metadata.String(), }, }, } diff --git a/integration/loki_micro_services_delete_test.go b/integration/loki_micro_services_delete_test.go index c8505b907fc43..01ece64300051 100644 --- a/integration/loki_micro_services_delete_test.go +++ b/integration/loki_micro_services_delete_test.go @@ -7,12 +7,12 @@ import ( "testing" "time" + "github.com/prometheus/prometheus/model/labels" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/grafana/loki/integration/client" "github.com/grafana/loki/integration/cluster" - "github.com/grafana/loki/pkg/storage" ) @@ -100,18 +100,22 @@ func TestMicroServicesDeleteRequest(t *testing.T) { { strconv.FormatInt(now.Add(-48*time.Hour).UnixNano(), 10), "lineA", + labels.Labels{}.String(), }, { strconv.FormatInt(now.Add(-48*time.Hour).UnixNano(), 10), "lineB", + labels.Labels{}.String(), }, { strconv.FormatInt(now.Add(-time.Minute).UnixNano(), 10), "lineC", + labels.Labels{}.String(), }, { strconv.FormatInt(now.Add(-time.Minute).UnixNano(), 10), "lineD", + labels.Labels{}.String(), }, }, }) diff --git a/integration/loki_micro_services_test.go b/integration/loki_micro_services_test.go index 7b2106b5fdf92..890e6c338577f 100644 --- a/integration/loki_micro_services_test.go +++ b/integration/loki_micro_services_test.go @@ -207,13 +207,13 @@ func TestMicroServicesMultipleBucketSingleProvider(t *testing.T) { cliQueryFrontend.Now = now t.Run("ingest-logs", func(t *testing.T) { - // ingest logs to the previous period - require.NoError(t, cliDistributor.PushLogLineWithTimestamp("lineA", time.Now().Add(-48*time.Hour), map[string]string{"job": "fake"})) - require.NoError(t, cliDistributor.PushLogLineWithTimestamp("lineB", time.Now().Add(-36*time.Hour), map[string]string{"job": "fake"})) + require.NoError(t, cliDistributor.PushLogLineWithTimestampAndMetadata("lineA", time.Now().Add(-48*time.Hour), map[string]string{"traceID": "123"}, map[string]string{"job": "fake"})) + require.NoError(t, cliDistributor.PushLogLineWithTimestampAndMetadata("lineB", time.Now().Add(-36*time.Hour), map[string]string{"traceID": "456"}, map[string]string{"job": "fake"})) // ingest logs to the current period - require.NoError(t, cliDistributor.PushLogLine("lineC", map[string]string{"job": "fake"})) - require.NoError(t, cliDistributor.PushLogLine("lineD", map[string]string{"job": "fake"})) + require.NoError(t, cliDistributor.PushLogLineWithMetadata("lineC", map[string]string{"traceID": "789"}, map[string]string{"job": "fake"})) + require.NoError(t, cliDistributor.PushLogLineWithMetadata("lineD", map[string]string{"traceID": "123"}, map[string]string{"job": "fake"})) + }) t.Run("query-lookback-default", func(t *testing.T) { From d876c21b8aaf1154e1b55c50f7fec25a046d8f2c Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 13 Jun 2023 11:40:40 +0200 Subject: [PATCH 05/36] Fix more tests --- .../loki_micro_services_delete_test.go | 9 +++--- pkg/loghttp/entry.go | 29 +++++++++++++++---- pkg/logql/log/fmt_test.go | 6 ++-- pkg/querier/queryrange/codec_test.go | 8 ++--- pkg/util/marshal/legacy/marshal_test.go | 6 ++-- pkg/util/marshal/marshal_test.go | 6 ++-- pkg/util/marshal/query.go | 2 ++ 7 files changed, 44 insertions(+), 22 deletions(-) diff --git a/integration/loki_micro_services_delete_test.go b/integration/loki_micro_services_delete_test.go index 01ece64300051..78d1b44b87742 100644 --- a/integration/loki_micro_services_delete_test.go +++ b/integration/loki_micro_services_delete_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - "github.com/prometheus/prometheus/model/labels" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -100,22 +99,22 @@ func TestMicroServicesDeleteRequest(t *testing.T) { { strconv.FormatInt(now.Add(-48*time.Hour).UnixNano(), 10), "lineA", - labels.Labels{}.String(), + "", }, { strconv.FormatInt(now.Add(-48*time.Hour).UnixNano(), 10), "lineB", - labels.Labels{}.String(), + "", }, { strconv.FormatInt(now.Add(-time.Minute).UnixNano(), 10), "lineC", - labels.Labels{}.String(), + "", }, { strconv.FormatInt(now.Add(-time.Minute).UnixNano(), 10), "lineD", - labels.Labels{}.String(), + "", }, }, }) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index 7d7a7dced33cd..089e7e4bce421 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -16,8 +16,9 @@ func init() { // Entry represents a log entry. It includes a log message and the time it occurred at. type Entry struct { - Timestamp time.Time - Line string + Timestamp time.Time + Line string + MetadataLabels string } func (e *Entry) UnmarshalJSON(data []byte) error { @@ -46,6 +47,13 @@ func (e *Entry) UnmarshalJSON(data []byte) error { return } e.Line = v + case 2: // metadataLabels + il, err := jsonparser.ParseString(value) + if err != nil { + parseError = err + return + } + e.MetadataLabels = il } i++ }) @@ -67,6 +75,7 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { i := 0 var ts time.Time var line string + var metadataLabels string ok := iter.ReadArrayCB(func(iter *jsoniter.Iterator) bool { var ok bool switch i { @@ -81,6 +90,13 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { return false } return true + case 2: + metadataLabels = iter.ReadString() + i++ + if iter.Error != nil { + return false + } + return true default: iter.ReportError("error reading entry", "array must contains 2 values") return false @@ -88,8 +104,9 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { }) if ok { *((*[]Entry)(ptr)) = append(*((*[]Entry)(ptr)), Entry{ - Timestamp: ts, - Line: line, + Timestamp: ts, + Line: line, + MetadataLabels: metadataLabels, }) return true } @@ -113,7 +130,7 @@ func readTimestamp(iter *jsoniter.Iterator) (time.Time, bool) { type EntryEncoder struct{} -func (EntryEncoder) IsEmpty(_ unsafe.Pointer) bool { +func (EntryEncoder) IsEmpty(ptr unsafe.Pointer) bool { // we don't omit-empty with log entries. return false } @@ -126,6 +143,8 @@ func (EntryEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { stream.WriteRaw(`"`) stream.WriteMore() stream.WriteStringWithHTMLEscaped(e.Line) + stream.WriteMore() + stream.WriteString(e.MetadataLabels) stream.WriteArrayEnd() } diff --git a/pkg/logql/log/fmt_test.go b/pkg/logql/log/fmt_test.go index ff4b845286700..4d6606a457064 100644 --- a/pkg/logql/log/fmt_test.go +++ b/pkg/logql/log/fmt_test.go @@ -676,10 +676,10 @@ func Test_labelsFormatter_Format(t *testing.T) { { "unixToTime milliseconds", mustNewLabelsFormatter([]LabelFmt{NewTemplateLabelFmt("foo", `{{ .bar | unixToTime | date "2006-01-02" }}`)}), - labels.Labels{{Name: "foo", Value: ""}, {Name: "bar", Value: "1257894000000"}}, + labels.Labels{{Name: "foo", Value: ""}, {Name: "bar", Value: "1686641739000"}}, labels.Labels{ - {Name: "bar", Value: "1257894000000"}, - {Name: "foo", Value: "2009-11-10"}, + {Name: "bar", Value: "1686641739000"}, + {Name: "foo", Value: "2023-06-13"}, }, }, { diff --git a/pkg/querier/queryrange/codec_test.go b/pkg/querier/queryrange/codec_test.go index 988500968dea9..bafd827a30266 100644 --- a/pkg/querier/queryrange/codec_test.go +++ b/pkg/querier/queryrange/codec_test.go @@ -1021,7 +1021,7 @@ func (badResponse) GetHeaders() []*queryrangebase.PrometheusResponseHeader { ret type badReader struct{} -func (badReader) Read(_ []byte) (n int, err error) { +func (badReader) Read(p []byte) (n int, err error) { return 0, errors.New("") } @@ -1187,7 +1187,7 @@ var ( "test": "test" }, "values":[ - [ "123456789012345", "super line" ] + [ "123456789012345", "super line", "" ] ] }, { @@ -1195,14 +1195,14 @@ var ( "test": "test2" }, "values":[ - [ "123456789012346", "super line2" ] + [ "123456789012346", "super line2", "" ] ] } ] } }` streamsStringLegacy = `{ - ` + statsResultString + `"streams":[{"labels":"{test=\"test\"}","entries":[{"ts":"1970-01-02T10:17:36.789012345Z","line":"super line"}]},{"labels":"{test=\"test2\"}","entries":[{"ts":"1970-01-02T10:17:36.789012346Z","line":"super line2"}]}]}` + ` + statsResultString + `"streams":[{"labels":"{test=\"test\"}","entries":[{"ts":"1970-01-02T10:17:36.789012345Z","line":"super line","metadataLabels":""}]},{"labels":"{test=\"test2\"}","entries":[{"ts":"1970-01-02T10:17:36.789012346Z","line":"super line2","metadataLabels":""}]}]}` logStreams = []logproto.Stream{ { Labels: `{test="test"}`, diff --git a/pkg/util/marshal/legacy/marshal_test.go b/pkg/util/marshal/legacy/marshal_test.go index 3f0529b1fcd0a..e0edaa3ed22cb 100644 --- a/pkg/util/marshal/legacy/marshal_test.go +++ b/pkg/util/marshal/legacy/marshal_test.go @@ -38,7 +38,8 @@ var queryTests = []struct { "entries":[ { "ts": "2019-09-13T18:32:22.380001319Z", - "line": "super line" + "line": "super line", + "metadataLabels": "" } ] } @@ -182,7 +183,8 @@ var tailTests = []struct { "entries": [ { "ts": "2019-09-13T18:32:22.380001319Z", - "line": "super line" + "line": "super line", + "metadataLabels": "" } ] } diff --git a/pkg/util/marshal/marshal_test.go b/pkg/util/marshal/marshal_test.go index 6bc130a6786d8..ecd03e920710f 100644 --- a/pkg/util/marshal/marshal_test.go +++ b/pkg/util/marshal/marshal_test.go @@ -48,7 +48,7 @@ var queryTests = []struct { "test": "test" }, "values":[ - [ "123456789012345", "super line" ] + [ "123456789012345", "super line", "" ] ] } ], @@ -506,7 +506,7 @@ var tailTests = []struct { "test": "test" }, "values":[ - [ "123456789012345", "super line" ] + [ "123456789012345", "super line", "" ] ] } ], @@ -828,7 +828,7 @@ func Test_WriteTailResponseJSON(t *testing.T) { }, }, WebsocketWriterFunc(func(i int, b []byte) error { - require.Equal(t, `{"streams":[{"stream":{"app":"foo"},"values":[["1","foobar"]]}],"dropped_entries":[{"timestamp":"2","labels":{"app":"dropped"}}]}`, string(b)) + require.Equal(t, `{"streams":[{"stream":{"app":"foo"},"values":[["1","foobar",""]]}],"dropped_entries":[{"timestamp":"2","labels":{"app":"dropped"}}]}`, string(b)) return nil }), ), diff --git a/pkg/util/marshal/query.go b/pkg/util/marshal/query.go index 07ce73816bf0d..410af30b2def4 100644 --- a/pkg/util/marshal/query.go +++ b/pkg/util/marshal/query.go @@ -315,6 +315,8 @@ func encodeStream(stream logproto.Stream, s *jsoniter.Stream) error { s.WriteRaw(`"`) s.WriteMore() s.WriteStringWithHTMLEscaped(e.Line) + s.WriteMore() + s.WriteString(e.MetadataLabels) s.WriteArrayEnd() s.Flush() From 9c6fdef3e2541849d41ea35e70db619b974c1686 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 13 Jun 2023 11:49:54 +0200 Subject: [PATCH 06/36] Revent some unwanted changes --- pkg/loghttp/entry.go | 2 +- pkg/push/types.go | 6 ++---- pkg/querier/queryrange/codec_test.go | 2 +- vendor/github.com/grafana/loki/pkg/push/types.go | 6 ++---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index 089e7e4bce421..c3b335e362c48 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -130,7 +130,7 @@ func readTimestamp(iter *jsoniter.Iterator) (time.Time, bool) { type EntryEncoder struct{} -func (EntryEncoder) IsEmpty(ptr unsafe.Pointer) bool { +func (EntryEncoder) IsEmpty(_ unsafe.Pointer) bool { // we don't omit-empty with log entries. return false } diff --git a/pkg/push/types.go b/pkg/push/types.go index a4d40d58ea583..3abdc25021590 100644 --- a/pkg/push/types.go +++ b/pkg/push/types.go @@ -4,8 +4,6 @@ import ( "fmt" "io" "time" - - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" ) // Stream contains a unique labels set as a string and a set of entries for it. @@ -107,7 +105,7 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp):]) + n1, err1 := StdTimeMarshalTo(m.Timestamp, dAtA[i-SizeOfStdTime(m.Timestamp):]) if err1 != nil { return 0, err1 } @@ -315,7 +313,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + if err := StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/pkg/querier/queryrange/codec_test.go b/pkg/querier/queryrange/codec_test.go index bafd827a30266..1325804d1d629 100644 --- a/pkg/querier/queryrange/codec_test.go +++ b/pkg/querier/queryrange/codec_test.go @@ -1021,7 +1021,7 @@ func (badResponse) GetHeaders() []*queryrangebase.PrometheusResponseHeader { ret type badReader struct{} -func (badReader) Read(p []byte) (n int, err error) { +func (badReader) Read(_ []byte) (n int, err error) { return 0, errors.New("") } diff --git a/vendor/github.com/grafana/loki/pkg/push/types.go b/vendor/github.com/grafana/loki/pkg/push/types.go index a4d40d58ea583..3abdc25021590 100644 --- a/vendor/github.com/grafana/loki/pkg/push/types.go +++ b/vendor/github.com/grafana/loki/pkg/push/types.go @@ -4,8 +4,6 @@ import ( "fmt" "io" "time" - - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" ) // Stream contains a unique labels set as a string and a set of entries for it. @@ -107,7 +105,7 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp):]) + n1, err1 := StdTimeMarshalTo(m.Timestamp, dAtA[i-SizeOfStdTime(m.Timestamp):]) if err1 != nil { return 0, err1 } @@ -315,7 +313,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { + if err := StdTimeUnmarshal(&m.Timestamp, dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex From b4ed160468f49a0f796629a0d84b902bdc33765a Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 13 Jun 2023 11:52:22 +0200 Subject: [PATCH 07/36] Remove more unwanted changes --- pkg/push/types.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/push/types.go b/pkg/push/types.go index 3abdc25021590..bd27ef2c05f0a 100644 --- a/pkg/push/types.go +++ b/pkg/push/types.go @@ -105,12 +105,12 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - n1, err1 := StdTimeMarshalTo(m.Timestamp, dAtA[i-SizeOfStdTime(m.Timestamp):]) - if err1 != nil { - return 0, err1 + n7, err7 := StdTimeMarshalTo(m.Timestamp, dAtA[i-SizeOfStdTime(m.Timestamp):]) + if err7 != nil { + return 0, err7 } - i -= n1 - i = encodeVarintPush(dAtA, i, uint64(n1)) + i -= n7 + i = encodeVarintPush(dAtA, i, uint64(n7)) i-- dAtA[i] = 0xa return len(dAtA) - i, nil From 8c6f22e56344305948b6a5fd2feceb739bf862f6 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 13 Jun 2023 12:18:51 +0200 Subject: [PATCH 08/36] Update vendor files --- vendor/github.com/grafana/loki/pkg/push/types.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vendor/github.com/grafana/loki/pkg/push/types.go b/vendor/github.com/grafana/loki/pkg/push/types.go index 3abdc25021590..bd27ef2c05f0a 100644 --- a/vendor/github.com/grafana/loki/pkg/push/types.go +++ b/vendor/github.com/grafana/loki/pkg/push/types.go @@ -105,12 +105,12 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - n1, err1 := StdTimeMarshalTo(m.Timestamp, dAtA[i-SizeOfStdTime(m.Timestamp):]) - if err1 != nil { - return 0, err1 + n7, err7 := StdTimeMarshalTo(m.Timestamp, dAtA[i-SizeOfStdTime(m.Timestamp):]) + if err7 != nil { + return 0, err7 } - i -= n1 - i = encodeVarintPush(dAtA, i, uint64(n1)) + i -= n7 + i = encodeVarintPush(dAtA, i, uint64(n7)) i-- dAtA[i] = 0xa return len(dAtA) - i, nil From c854d06be9e43e2fd00faf9a98fb04ea16be0b9a Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Fri, 16 Jun 2023 11:33:46 +0530 Subject: [PATCH 09/36] use json format for metadata labels in v1 push api --- integration/client/client.go | 7 +++++- pkg/util/unmarshal/unmarshal.go | 42 ++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/integration/client/client.go b/integration/client/client.go index c37b5fdd483db..9a9ee99451fca 100644 --- a/integration/client/client.go +++ b/integration/client/client.go @@ -117,6 +117,11 @@ type stream struct { func (c *Client) pushLogLine(line string, timestamp time.Time, metadata labels.Labels, extraLabelList ...map[string]string) error { apiEndpoint := fmt.Sprintf("%s/loki/api/v1/push", c.baseURL) + metadataJson, err := metadata.MarshalJSON() + if err != nil { + return err + } + s := stream{ Stream: map[string]string{ "job": "varlog", @@ -125,7 +130,7 @@ func (c *Client) pushLogLine(line string, timestamp time.Time, metadata labels.L { formatTS(timestamp), line, - metadata.String(), + string(metadataJson), }, }, } diff --git a/pkg/util/unmarshal/unmarshal.go b/pkg/util/unmarshal/unmarshal.go index a8c462ac497f1..bb39ea42ef5ce 100644 --- a/pkg/util/unmarshal/unmarshal.go +++ b/pkg/util/unmarshal/unmarshal.go @@ -4,10 +4,10 @@ import ( "io" "unsafe" - jsoniter "github.com/json-iterator/go" - "github.com/grafana/loki/pkg/loghttp" "github.com/grafana/loki/pkg/logproto" + "github.com/grafana/loki/pkg/util" + jsoniter "github.com/json-iterator/go" ) // DecodePushRequest directly decodes json to a logproto.PushRequest @@ -17,30 +17,56 @@ func DecodePushRequest(b io.Reader, r *logproto.PushRequest) error { if err := jsoniter.NewDecoder(b).Decode(&request); err != nil { return err } - *r = NewPushRequest(request) + + req, err := NewPushRequest(request) + if err != nil { + return err + } + *r = *req return nil } // NewPushRequest constructs a logproto.PushRequest from a PushRequest -func NewPushRequest(r loghttp.PushRequest) logproto.PushRequest { +func NewPushRequest(r loghttp.PushRequest) (*logproto.PushRequest, error) { ret := logproto.PushRequest{ Streams: make([]logproto.Stream, len(r.Streams)), } for i, s := range r.Streams { - ret.Streams[i] = NewStream(s) + stream, err := NewStream(s) + if err != nil { + return nil, err + } + + ret.Streams[i] = *stream } - return ret + return &ret, nil } // NewStream constructs a logproto.Stream from a Stream -func NewStream(s *loghttp.Stream) logproto.Stream { - return logproto.Stream{ +func NewStream(s *loghttp.Stream) (*logproto.Stream, error) { + stream := logproto.Stream{ Entries: *(*[]logproto.Entry)(unsafe.Pointer(&s.Entries)), Labels: s.Labels.String(), } + + for i, entry := range stream.Entries { + if entry.MetadataLabels == "" { + continue + } + // labels in v1 HTTP push endpoint are in json format({"foo":"bar"}) while for proto it is key=value format({foo="bar"}) + // So here we need to convert metadata labels from json to proto format. + // ToDo(Sandeep): Find a way to either not do the conversion or efficiently do it since + // metadata labels can be attached to each log line. + metadataLabels := loghttp.LabelSet{} + if err := metadataLabels.UnmarshalJSON(util.YoloBuf(entry.MetadataLabels)); err != nil { + return nil, err + } + stream.Entries[i].MetadataLabels = metadataLabels.String() + } + return &stream, nil } // WebsocketReader knows how to read message to a websocket connection. From 95ba8a2ca4ea19287f00a93bd18461a9fce0a0c9 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Fri, 16 Jun 2023 13:15:09 +0530 Subject: [PATCH 10/36] rename metadataLabels to labels --- pkg/loghttp/entry.go | 22 ++--- pkg/push/push.pb.go | 84 +++++++++---------- pkg/push/push.proto | 2 +- pkg/push/types.go | 22 ++--- pkg/querier/queryrange/codec_test.go | 2 +- pkg/util/marshal/legacy/marshal_test.go | 6 +- pkg/util/marshal/query.go | 2 +- pkg/util/unmarshal/unmarshal.go | 16 ++-- .../grafana/loki/pkg/push/push.pb.go | 84 +++++++++---------- .../grafana/loki/pkg/push/push.proto | 2 +- .../github.com/grafana/loki/pkg/push/types.go | 22 ++--- 11 files changed, 134 insertions(+), 130 deletions(-) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index c3b335e362c48..afcda0262cb99 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -16,9 +16,9 @@ func init() { // Entry represents a log entry. It includes a log message and the time it occurred at. type Entry struct { - Timestamp time.Time - Line string - MetadataLabels string + Timestamp time.Time + Line string + Labels string } func (e *Entry) UnmarshalJSON(data []byte) error { @@ -47,13 +47,13 @@ func (e *Entry) UnmarshalJSON(data []byte) error { return } e.Line = v - case 2: // metadataLabels + case 2: // labels il, err := jsonparser.ParseString(value) if err != nil { parseError = err return } - e.MetadataLabels = il + e.Labels = il } i++ }) @@ -75,7 +75,7 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { i := 0 var ts time.Time var line string - var metadataLabels string + var labels string ok := iter.ReadArrayCB(func(iter *jsoniter.Iterator) bool { var ok bool switch i { @@ -91,7 +91,7 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { } return true case 2: - metadataLabels = iter.ReadString() + labels = iter.ReadString() i++ if iter.Error != nil { return false @@ -104,9 +104,9 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { }) if ok { *((*[]Entry)(ptr)) = append(*((*[]Entry)(ptr)), Entry{ - Timestamp: ts, - Line: line, - MetadataLabels: metadataLabels, + Timestamp: ts, + Line: line, + Labels: labels, }) return true } @@ -144,7 +144,7 @@ func (EntryEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { stream.WriteMore() stream.WriteStringWithHTMLEscaped(e.Line) stream.WriteMore() - stream.WriteString(e.MetadataLabels) + stream.WriteString(e.Labels) stream.WriteArrayEnd() } diff --git a/pkg/push/push.pb.go b/pkg/push/push.pb.go index b96f8002d3a8c..8f241eb44497d 100644 --- a/pkg/push/push.pb.go +++ b/pkg/push/push.pb.go @@ -171,7 +171,7 @@ type EntryAdapter struct { // // So we can avoid the conversion to and from string. // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. - MetadataLabels string `protobuf:"bytes,3,opt,name=metadataLabels,proto3" json:"metadataLabels"` + Labels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } @@ -220,9 +220,9 @@ func (m *EntryAdapter) GetLine() string { return "" } -func (m *EntryAdapter) GetMetadataLabels() string { +func (m *EntryAdapter) GetLabels() string { if m != nil { - return m.MetadataLabels + return m.Labels } return "" } @@ -237,35 +237,35 @@ func init() { func init() { proto.RegisterFile("pkg/push/push.proto", fileDescriptor_35ec442956852c9e) } var fileDescriptor_35ec442956852c9e = []byte{ - // 448 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0xbf, 0x8e, 0xd3, 0x30, - 0x1c, 0x8e, 0xdb, 0xd2, 0xbb, 0x73, 0x8f, 0x22, 0x19, 0xee, 0x28, 0x15, 0xb2, 0xab, 0x4c, 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15, 0x06, 0x57, 0x5b, - 0xec, 0xac, 0xb7, 0xd8, 0xb9, 0xd9, 0x62, 0xe7, 0xe3, 0x4c, 0x44, 0x3a, 0x2c, 0x56, 0xde, 0x27, - 0x99, 0xf8, 0x22, 0x67, 0x17, 0x2c, 0x65, 0x7e, 0x2c, 0x2f, 0x23, 0xdf, 0x3e, 0xcc, 0xd5, 0xd0, - 0xb0, 0x3d, 0xff, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x13, 0xd9, 0x4f, 0xab, 0x02, 0x00, 0x00, + // 446 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0x41, 0x6f, 0xd3, 0x30, + 0x18, 0xb5, 0xdb, 0xd2, 0x6d, 0xee, 0x18, 0xc8, 0x6c, 0xa3, 0x54, 0xc8, 0xae, 0x72, 0xea, 0x61, + 0x24, 0x52, 0x39, 0x70, 0x6e, 0x24, 0xa4, 0x1d, 0x51, 0x40, 0x20, 0x71, 0x73, 0xc1, 0x73, 0xa2, + 0x25, 0x71, 0x88, 0x9d, 0xc3, 0x6e, 0xfc, 0x84, 0xf1, 0x1f, 0x38, 0xf0, 0x53, 0x76, 0xec, 0x71, + 0xe2, 0x10, 0x68, 0x7a, 0x41, 0x39, 0xed, 0x27, 0xa0, 0x38, 0xf1, 0x5a, 0xb8, 0x38, 0xcf, 0xef, + 0xfb, 0xfc, 0xbd, 0xe7, 0x17, 0xa3, 0x27, 0xd9, 0xa5, 0xf0, 0xb2, 0x42, 0x85, 0x66, 0x71, 0xb3, + 0x5c, 0x6a, 0x89, 0xf7, 0x63, 0x29, 0x0c, 0x9a, 0x1c, 0x0b, 0x29, 0xa4, 0x81, 0x5e, 0x83, 0xda, + 0xfa, 0x84, 0x0a, 0x29, 0x45, 0xcc, 0x3d, 0xb3, 0x5b, 0x16, 0x17, 0x9e, 0x8e, 0x12, 0xae, 0x34, + 0x4b, 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 0xb6, 0x5f, 0x97, 0xd4, 0xec, 0x03, 0xb3, 0xe2, 0xb3, + 0xfb, 0xab, 0xf7, 0x4d, 0xfd, 0xb8, 0x2e, 0xe9, 0xe3, 0x96, 0x39, 0x93, 0x49, 0xa4, 0x79, 0x92, + 0xe9, 0x2b, 0x1b, 0xc2, 0x7c, 0x81, 0x86, 0x4d, 0x94, 0x3c, 0xc7, 0xaf, 0xd0, 0xa0, 0x41, 0xf8, + 0x64, 0x9b, 0xc2, 0xce, 0xdf, 0x9b, 0x9c, 0xfe, 0x4f, 0x77, 0xd9, 0x03, 0xff, 0xfd, 0x6a, 0x4d, + 0xc0, 0xed, 0x9a, 0x80, 0xbb, 0x35, 0x81, 0x5f, 0x2b, 0x02, 0x7f, 0x54, 0x04, 0xde, 0x54, 0x04, + 0xae, 0x2a, 0x02, 0x7f, 0x57, 0x04, 0xfe, 0xa9, 0x08, 0xb8, 0xab, 0x08, 0xbc, 0xde, 0x10, 0xb0, + 0xda, 0x10, 0x70, 0xbb, 0x21, 0xe0, 0xe3, 0x54, 0x44, 0x3a, 0x2c, 0x96, 0xee, 0x27, 0x99, 0x78, + 0x22, 0x67, 0x17, 0x2c, 0x65, 0x5e, 0x2c, 0x2f, 0x23, 0xcf, 0x3e, 0xc5, 0xe5, 0xd0, 0xa8, 0xbd, + 0xfc, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x95, 0x50, 0x89, 0x19, 0x9d, 0x02, 0x00, 0x00, } func (this *PushRequest) Equal(that interface{}) bool { @@ -378,7 +378,7 @@ func (this *EntryAdapter) Equal(that interface{}) bool { if this.Line != that1.Line { return false } - if this.MetadataLabels != that1.MetadataLabels { + if this.Labels != that1.Labels { return false } return true @@ -428,7 +428,7 @@ 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, "MetadataLabels: "+fmt.Sprintf("%#v", this.MetadataLabels)+",\n") + s = append(s, "Labels: "+fmt.Sprintf("%#v", this.Labels)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -650,10 +650,10 @@ func (m *EntryAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MetadataLabels) > 0 { - i -= len(m.MetadataLabels) - copy(dAtA[i:], m.MetadataLabels) - i = encodeVarintPush(dAtA, i, uint64(len(m.MetadataLabels))) + if len(m.Labels) > 0 { + i -= len(m.Labels) + copy(dAtA[i:], m.Labels) + i = encodeVarintPush(dAtA, i, uint64(len(m.Labels))) i-- dAtA[i] = 0x1a } @@ -744,7 +744,7 @@ func (m *EntryAdapter) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.MetadataLabels) + l = len(m.Labels) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -800,7 +800,7 @@ func (this *EntryAdapter) String() string { 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) + `,`, - `MetadataLabels:` + fmt.Sprintf("%v", this.MetadataLabels) + `,`, + `Labels:` + fmt.Sprintf("%v", this.Labels) + `,`, `}`, }, "") return s @@ -1187,7 +1187,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MetadataLabels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1215,7 +1215,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MetadataLabels = string(dAtA[iNdEx:postIndex]) + m.Labels = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/pkg/push/push.proto b/pkg/push/push.proto index d0f50ede8d11e..93c13f72ce67b 100644 --- a/pkg/push/push.proto +++ b/pkg/push/push.proto @@ -40,5 +40,5 @@ message EntryAdapter { // TODO: maybe we can use the labels.Labels type here? // So we can avoid the conversion to and from string. // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. - string metadataLabels = 3 [(gogoproto.jsontag) = "metadataLabels"]; + string labels = 3 [(gogoproto.jsontag) = "labels,omitempty"]; } diff --git a/pkg/push/types.go b/pkg/push/types.go index bd27ef2c05f0a..6c7668db02e5a 100644 --- a/pkg/push/types.go +++ b/pkg/push/types.go @@ -17,9 +17,9 @@ 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"` - MetadataLabels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"metadataLabels"` + Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` + Labels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` } func (m *Stream) Marshal() (dAtA []byte, err error) { @@ -91,10 +91,10 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MetadataLabels) > 0 { - i -= len(m.MetadataLabels) - copy(dAtA[i:], m.MetadataLabels) - i = encodeVarintPush(dAtA, i, uint64(len(m.MetadataLabels))) + if len(m.Labels) > 0 { + i -= len(m.Labels) + copy(dAtA[i:], m.Labels) + i = encodeVarintPush(dAtA, i, uint64(len(m.Labels))) i-- dAtA[i] = 0x1a } @@ -351,7 +351,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MetadataLabels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -379,7 +379,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MetadataLabels = string(dAtA[iNdEx:postIndex]) + m.Labels = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -440,7 +440,7 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.MetadataLabels) + l = len(m.Labels) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -505,7 +505,7 @@ func (m *Entry) Equal(that interface{}) bool { if m.Line != that1.Line { return false } - if m.MetadataLabels != that1.MetadataLabels { + if m.Labels != that1.Labels { return false } return true diff --git a/pkg/querier/queryrange/codec_test.go b/pkg/querier/queryrange/codec_test.go index 1325804d1d629..f6bf7f92db610 100644 --- a/pkg/querier/queryrange/codec_test.go +++ b/pkg/querier/queryrange/codec_test.go @@ -1202,7 +1202,7 @@ var ( } }` streamsStringLegacy = `{ - ` + statsResultString + `"streams":[{"labels":"{test=\"test\"}","entries":[{"ts":"1970-01-02T10:17:36.789012345Z","line":"super line","metadataLabels":""}]},{"labels":"{test=\"test2\"}","entries":[{"ts":"1970-01-02T10:17:36.789012346Z","line":"super line2","metadataLabels":""}]}]}` + ` + statsResultString + `"streams":[{"labels":"{test=\"test\"}","entries":[{"ts":"1970-01-02T10:17:36.789012345Z","line":"super line"}]},{"labels":"{test=\"test2\"}","entries":[{"ts":"1970-01-02T10:17:36.789012346Z","line":"super line2"}]}]}` logStreams = []logproto.Stream{ { Labels: `{test="test"}`, diff --git a/pkg/util/marshal/legacy/marshal_test.go b/pkg/util/marshal/legacy/marshal_test.go index e0edaa3ed22cb..3f0529b1fcd0a 100644 --- a/pkg/util/marshal/legacy/marshal_test.go +++ b/pkg/util/marshal/legacy/marshal_test.go @@ -38,8 +38,7 @@ var queryTests = []struct { "entries":[ { "ts": "2019-09-13T18:32:22.380001319Z", - "line": "super line", - "metadataLabels": "" + "line": "super line" } ] } @@ -183,8 +182,7 @@ var tailTests = []struct { "entries": [ { "ts": "2019-09-13T18:32:22.380001319Z", - "line": "super line", - "metadataLabels": "" + "line": "super line" } ] } diff --git a/pkg/util/marshal/query.go b/pkg/util/marshal/query.go index 410af30b2def4..bcc4f500b75c1 100644 --- a/pkg/util/marshal/query.go +++ b/pkg/util/marshal/query.go @@ -316,7 +316,7 @@ func encodeStream(stream logproto.Stream, s *jsoniter.Stream) error { s.WriteMore() s.WriteStringWithHTMLEscaped(e.Line) s.WriteMore() - s.WriteString(e.MetadataLabels) + s.WriteString(e.Labels) s.WriteArrayEnd() s.Flush() diff --git a/pkg/util/unmarshal/unmarshal.go b/pkg/util/unmarshal/unmarshal.go index bb39ea42ef5ce..93962135807e9 100644 --- a/pkg/util/unmarshal/unmarshal.go +++ b/pkg/util/unmarshal/unmarshal.go @@ -2,11 +2,11 @@ package unmarshal import ( "io" + "reflect" "unsafe" "github.com/grafana/loki/pkg/loghttp" "github.com/grafana/loki/pkg/logproto" - "github.com/grafana/loki/pkg/util" jsoniter "github.com/json-iterator/go" ) @@ -53,18 +53,18 @@ func NewStream(s *loghttp.Stream) (*logproto.Stream, error) { } for i, entry := range stream.Entries { - if entry.MetadataLabels == "" { + if entry.Labels == "" { continue } // labels in v1 HTTP push endpoint are in json format({"foo":"bar"}) while for proto it is key=value format({foo="bar"}) // So here we need to convert metadata labels from json to proto format. // ToDo(Sandeep): Find a way to either not do the conversion or efficiently do it since // metadata labels can be attached to each log line. - metadataLabels := loghttp.LabelSet{} - if err := metadataLabels.UnmarshalJSON(util.YoloBuf(entry.MetadataLabels)); err != nil { + labels := loghttp.LabelSet{} + if err := labels.UnmarshalJSON(yoloBytes(entry.Labels)); err != nil { return nil, err } - stream.Entries[i].MetadataLabels = metadataLabels.String() + stream.Entries[i].Labels = labels.String() } return &stream, nil } @@ -82,3 +82,9 @@ func ReadTailResponseJSON(r *loghttp.TailResponse, reader WebsocketReader) error } return jsoniter.Unmarshal(data, r) } + +func yoloBytes(s string) (b []byte) { + *(*string)(unsafe.Pointer(&b)) = s + (*reflect.SliceHeader)(unsafe.Pointer(&b)).Cap = len(s) + return +} 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 b96f8002d3a8c..8f241eb44497d 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.pb.go +++ b/vendor/github.com/grafana/loki/pkg/push/push.pb.go @@ -171,7 +171,7 @@ type EntryAdapter struct { // // So we can avoid the conversion to and from string. // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. - MetadataLabels string `protobuf:"bytes,3,opt,name=metadataLabels,proto3" json:"metadataLabels"` + Labels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } @@ -220,9 +220,9 @@ func (m *EntryAdapter) GetLine() string { return "" } -func (m *EntryAdapter) GetMetadataLabels() string { +func (m *EntryAdapter) GetLabels() string { if m != nil { - return m.MetadataLabels + return m.Labels } return "" } @@ -237,35 +237,35 @@ func init() { func init() { proto.RegisterFile("pkg/push/push.proto", fileDescriptor_35ec442956852c9e) } var fileDescriptor_35ec442956852c9e = []byte{ - // 448 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0xbf, 0x8e, 0xd3, 0x30, - 0x1c, 0x8e, 0xdb, 0xd2, 0xbb, 0x73, 0x8f, 0x22, 0x19, 0xee, 0x28, 0x15, 0xb2, 0xab, 0x4c, 0x5d, - 0x48, 0xa4, 0x32, 0x20, 0xb1, 0x35, 0x12, 0xd2, 0x0d, 0x0c, 0xc8, 0x20, 0x90, 0xd8, 0x5c, 0xce, - 0xe7, 0x44, 0x97, 0xc4, 0x21, 0x76, 0x06, 0x36, 0x1e, 0xe1, 0x78, 0x0b, 0x66, 0x9e,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xdf, 0x3e, 0xcc, 0xd5, 0xd0, - 0xb0, 0x3d, 0xff, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x13, 0xd9, 0x4f, 0xab, 0x02, 0x00, 0x00, + // 446 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0x41, 0x6f, 0xd3, 0x30, + 0x18, 0xb5, 0xdb, 0xd2, 0x6d, 0xee, 0x18, 0xc8, 0x6c, 0xa3, 0x54, 0xc8, 0xae, 0x72, 0xea, 0x61, + 0x24, 0x52, 0x39, 0x70, 0x6e, 0x24, 0xa4, 0x1d, 0x51, 0x40, 0x20, 0x71, 0x73, 0xc1, 0x73, 0xa2, + 0x25, 0x71, 0x88, 0x9d, 0xc3, 0x6e, 0xfc, 0x84, 0xf1, 0x1f, 0x38, 0xf0, 0x53, 0x76, 0xec, 0x71, + 0xe2, 0x10, 0x68, 0x7a, 0x41, 0x39, 0xed, 0x27, 0xa0, 0x38, 0xf1, 0x5a, 0xb8, 0x38, 0xcf, 0xef, + 0xfb, 0xfc, 0xbd, 0xe7, 0x17, 0xa3, 0x27, 0xd9, 0xa5, 0xf0, 0xb2, 0x42, 0x85, 0x66, 0x71, 0xb3, + 0x5c, 0x6a, 0x89, 0xf7, 0x63, 0x29, 0x0c, 0x9a, 0x1c, 0x0b, 0x29, 0xa4, 0x81, 0x5e, 0x83, 0xda, + 0xfa, 0x84, 0x0a, 0x29, 0x45, 0xcc, 0x3d, 0xb3, 0x5b, 0x16, 0x17, 0x9e, 0x8e, 0x12, 0xae, 0x34, + 0x4b, 0xb2, 0xb6, 0xc1, 0xf9, 0x80, 0x46, 0x6f, 0x0a, 0x15, 0x06, 0xfc, 0x4b, 0xc1, 0x95, 0xc6, + 0xe7, 0x68, 0x4f, 0xe9, 0x9c, 0xb3, 0x44, 0x8d, 0xe1, 0xb4, 0x3f, 0x1b, 0xcd, 0x9f, 0xba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, 0x81, 0x86, 0x4d, 0x94, 0x3c, 0xc7, 0xaf, 0xd0, 0xa0, 0x41, 0xf8, + 0x64, 0x9b, 0xc2, 0xce, 0xdf, 0x9b, 0x9c, 0xfe, 0x4f, 0x77, 0xd9, 0x03, 0xff, 0xfd, 0x6a, 0x4d, + 0xc0, 0xed, 0x9a, 0x80, 0xbb, 0x35, 0x81, 0x5f, 0x2b, 0x02, 0x7f, 0x54, 0x04, 0xde, 0x54, 0x04, + 0xae, 0x2a, 0x02, 0x7f, 0x57, 0x04, 0xfe, 0xa9, 0x08, 0xb8, 0xab, 0x08, 0xbc, 0xde, 0x10, 0xb0, + 0xda, 0x10, 0x70, 0xbb, 0x21, 0xe0, 0xe3, 0x54, 0x44, 0x3a, 0x2c, 0x96, 0xee, 0x27, 0x99, 0x78, + 0x22, 0x67, 0x17, 0x2c, 0x65, 0x5e, 0x2c, 0x2f, 0x23, 0xcf, 0x3e, 0xc5, 0xe5, 0xd0, 0xa8, 0xbd, + 0xfc, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x95, 0x50, 0x89, 0x19, 0x9d, 0x02, 0x00, 0x00, } func (this *PushRequest) Equal(that interface{}) bool { @@ -378,7 +378,7 @@ func (this *EntryAdapter) Equal(that interface{}) bool { if this.Line != that1.Line { return false } - if this.MetadataLabels != that1.MetadataLabels { + if this.Labels != that1.Labels { return false } return true @@ -428,7 +428,7 @@ 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, "MetadataLabels: "+fmt.Sprintf("%#v", this.MetadataLabels)+",\n") + s = append(s, "Labels: "+fmt.Sprintf("%#v", this.Labels)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -650,10 +650,10 @@ func (m *EntryAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MetadataLabels) > 0 { - i -= len(m.MetadataLabels) - copy(dAtA[i:], m.MetadataLabels) - i = encodeVarintPush(dAtA, i, uint64(len(m.MetadataLabels))) + if len(m.Labels) > 0 { + i -= len(m.Labels) + copy(dAtA[i:], m.Labels) + i = encodeVarintPush(dAtA, i, uint64(len(m.Labels))) i-- dAtA[i] = 0x1a } @@ -744,7 +744,7 @@ func (m *EntryAdapter) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.MetadataLabels) + l = len(m.Labels) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -800,7 +800,7 @@ func (this *EntryAdapter) String() string { 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) + `,`, - `MetadataLabels:` + fmt.Sprintf("%v", this.MetadataLabels) + `,`, + `Labels:` + fmt.Sprintf("%v", this.Labels) + `,`, `}`, }, "") return s @@ -1187,7 +1187,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MetadataLabels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1215,7 +1215,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MetadataLabels = string(dAtA[iNdEx:postIndex]) + m.Labels = string(dAtA[iNdEx:postIndex]) 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 d0f50ede8d11e..93c13f72ce67b 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.proto +++ b/vendor/github.com/grafana/loki/pkg/push/push.proto @@ -40,5 +40,5 @@ message EntryAdapter { // TODO: maybe we can use the labels.Labels type here? // So we can avoid the conversion to and from string. // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. - string metadataLabels = 3 [(gogoproto.jsontag) = "metadataLabels"]; + string labels = 3 [(gogoproto.jsontag) = "labels,omitempty"]; } diff --git a/vendor/github.com/grafana/loki/pkg/push/types.go b/vendor/github.com/grafana/loki/pkg/push/types.go index bd27ef2c05f0a..6c7668db02e5a 100644 --- a/vendor/github.com/grafana/loki/pkg/push/types.go +++ b/vendor/github.com/grafana/loki/pkg/push/types.go @@ -17,9 +17,9 @@ 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"` - MetadataLabels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"metadataLabels"` + Timestamp time.Time `protobuf:"bytes,1,opt,name=timestamp,proto3,stdtime" json:"ts"` + Line string `protobuf:"bytes,2,opt,name=line,proto3" json:"line"` + Labels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` } func (m *Stream) Marshal() (dAtA []byte, err error) { @@ -91,10 +91,10 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.MetadataLabels) > 0 { - i -= len(m.MetadataLabels) - copy(dAtA[i:], m.MetadataLabels) - i = encodeVarintPush(dAtA, i, uint64(len(m.MetadataLabels))) + if len(m.Labels) > 0 { + i -= len(m.Labels) + copy(dAtA[i:], m.Labels) + i = encodeVarintPush(dAtA, i, uint64(len(m.Labels))) i-- dAtA[i] = 0x1a } @@ -351,7 +351,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MetadataLabels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -379,7 +379,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.MetadataLabels = string(dAtA[iNdEx:postIndex]) + m.Labels = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -440,7 +440,7 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.MetadataLabels) + l = len(m.Labels) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -505,7 +505,7 @@ func (m *Entry) Equal(that interface{}) bool { if m.Line != that1.Line { return false } - if m.MetadataLabels != that1.MetadataLabels { + if m.Labels != that1.Labels { return false } return true From ea8f3f62bb5a0f69db800418dae46de9a6f8d6d3 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Fri, 16 Jun 2023 13:31:00 +0530 Subject: [PATCH 11/36] lint and some test fixes --- integration/client/client.go | 22 +++++++++++----------- pkg/push/types_test.go | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/integration/client/client.go b/integration/client/client.go index 9a9ee99451fca..558c5d6c47077 100644 --- a/integration/client/client.go +++ b/integration/client/client.go @@ -86,22 +86,22 @@ func New(instanceID, token, baseURL string, opts ...Option) *Client { } // PushLogLine creates a new logline with the current time as timestamp -func (c *Client) PushLogLine(line string, extraLabels ...map[string]string) error { - return c.pushLogLine(line, c.Now, nil, extraLabels...) +func (c *Client) PushLogLine(line string, logLabels ...map[string]string) error { + return c.pushLogLine(line, c.Now, nil, logLabels...) } -func (c *Client) PushLogLineWithMetadata(line string, metadata map[string]string, extraLabels ...map[string]string) error { - return c.PushLogLineWithTimestampAndMetadata(line, c.Now, metadata, extraLabels...) +func (c *Client) PushLogLineWithMetadata(line string, logLabels map[string]string, extraLabels ...map[string]string) error { + return c.PushLogLineWithTimestampAndMetadata(line, c.Now, logLabels, extraLabels...) } // PushLogLineWithTimestamp creates a new logline at the given timestamp // The timestamp has to be a Unix timestamp (epoch seconds) -func (c *Client) PushLogLineWithTimestamp(line string, timestamp time.Time, extraLabelList ...map[string]string) error { - return c.pushLogLine(line, timestamp, nil, extraLabelList...) +func (c *Client) PushLogLineWithTimestamp(line string, timestamp time.Time, logLabels ...map[string]string) error { + return c.pushLogLine(line, timestamp, nil, logLabels...) } -func (c *Client) PushLogLineWithTimestampAndMetadata(line string, timestamp time.Time, metadata map[string]string, extraLabelList ...map[string]string) error { - return c.pushLogLine(line, timestamp, labels.FromMap(metadata), extraLabelList...) +func (c *Client) PushLogLineWithTimestampAndMetadata(line string, timestamp time.Time, logLabels map[string]string, extraLabelList ...map[string]string) error { + return c.pushLogLine(line, timestamp, labels.FromMap(logLabels), extraLabelList...) } func formatTS(ts time.Time) string { @@ -114,10 +114,10 @@ type stream struct { } // pushLogLine creates a new logline -func (c *Client) pushLogLine(line string, timestamp time.Time, metadata labels.Labels, extraLabelList ...map[string]string) error { +func (c *Client) pushLogLine(line string, timestamp time.Time, logLabels labels.Labels, extraLabelList ...map[string]string) error { apiEndpoint := fmt.Sprintf("%s/loki/api/v1/push", c.baseURL) - metadataJson, err := metadata.MarshalJSON() + logLabelsJSON, err := logLabels.MarshalJSON() if err != nil { return err } @@ -130,7 +130,7 @@ func (c *Client) pushLogLine(line string, timestamp time.Time, metadata labels.L { formatTS(timestamp), line, - string(metadataJson), + string(logLabelsJSON), }, }, } diff --git a/pkg/push/types_test.go b/pkg/push/types_test.go index 45fbf6aa22386..736af9d01dde9 100644 --- a/pkg/push/types_test.go +++ b/pkg/push/types_test.go @@ -15,9 +15,9 @@ var ( Hash: 1234*10 ^ 9, Entries: []Entry{ {now, line, ""}, - {now.Add(1 * time.Second), line, `{traceID="1234"`}, + {now.Add(1 * time.Second), line, `{traceID="1234"}`}, {now.Add(2 * time.Second), line, ""}, - {now.Add(3 * time.Second), line, `{user="abc"`}, + {now.Add(3 * time.Second), line, `{user="abc"}`}, }, } streamAdapter = StreamAdapter{ @@ -25,9 +25,9 @@ var ( Hash: 1234*10 ^ 9, Entries: []EntryAdapter{ {now, line, ""}, - {now.Add(1 * time.Second), line, `{traceID="1234"`}, + {now.Add(1 * time.Second), line, `{traceID="1234"}`}, {now.Add(2 * time.Second), line, ""}, - {now.Add(3 * time.Second), line, `{user="abc"`}, + {now.Add(3 * time.Second), line, `{user="abc"}`}, }, } ) From 73cf5dc75628acee8818e648c62422e168380b10 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Fri, 16 Jun 2023 13:38:13 +0530 Subject: [PATCH 12/36] lint --- pkg/util/unmarshal/unmarshal.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/util/unmarshal/unmarshal.go b/pkg/util/unmarshal/unmarshal.go index 93962135807e9..6dfc23a3ecc65 100644 --- a/pkg/util/unmarshal/unmarshal.go +++ b/pkg/util/unmarshal/unmarshal.go @@ -5,9 +5,10 @@ import ( "reflect" "unsafe" + jsoniter "github.com/json-iterator/go" + "github.com/grafana/loki/pkg/loghttp" "github.com/grafana/loki/pkg/logproto" - jsoniter "github.com/json-iterator/go" ) // DecodePushRequest directly decodes json to a logproto.PushRequest From 7b77c69639f9dd1f4f189f3e1c0f0c6e7f6fb0da Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Fri, 16 Jun 2023 14:00:52 +0530 Subject: [PATCH 13/36] lint lint lin... --- pkg/util/unmarshal/unmarshal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/unmarshal/unmarshal.go b/pkg/util/unmarshal/unmarshal.go index 6dfc23a3ecc65..3250b5a06c2e4 100644 --- a/pkg/util/unmarshal/unmarshal.go +++ b/pkg/util/unmarshal/unmarshal.go @@ -6,7 +6,7 @@ import ( "unsafe" jsoniter "github.com/json-iterator/go" - + "github.com/grafana/loki/pkg/loghttp" "github.com/grafana/loki/pkg/logproto" ) From 44b0932247909e5d196087b88ec15ae00ad7254d Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Mon, 19 Jun 2023 14:43:09 +0530 Subject: [PATCH 14/36] use map object instead of string representation for log labels in json push request --- integration/client/client.go | 11 +-- pkg/loghttp/query.go | 121 ++++++++++++++++++++++++++- pkg/util/unmarshal/unmarshal.go | 55 +----------- pkg/util/unmarshal/unmarshal_test.go | 26 ++++++ 4 files changed, 150 insertions(+), 63 deletions(-) diff --git a/integration/client/client.go b/integration/client/client.go index 558c5d6c47077..114c99f27929f 100644 --- a/integration/client/client.go +++ b/integration/client/client.go @@ -110,27 +110,22 @@ func formatTS(ts time.Time) string { type stream struct { Stream map[string]string `json:"stream"` - Values [][]string `json:"values"` + Values [][]any `json:"values"` } // pushLogLine creates a new logline func (c *Client) pushLogLine(line string, timestamp time.Time, logLabels labels.Labels, extraLabelList ...map[string]string) error { apiEndpoint := fmt.Sprintf("%s/loki/api/v1/push", c.baseURL) - logLabelsJSON, err := logLabels.MarshalJSON() - if err != nil { - return err - } - s := stream{ Stream: map[string]string{ "job": "varlog", }, - Values: [][]string{ + Values: [][]any{ { formatTS(timestamp), line, - string(logLabelsJSON), + logLabels, }, }, } diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index af8ebbe9689fc..ddc66193138f4 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -55,9 +55,122 @@ func (q *QueryResponse) UnmarshalJSON(data []byte) error { }) } -// PushRequest models a log stream push +// PushRequest models a log stream push but is unmarshalled to proto push format. type PushRequest struct { - Streams []*Stream `json:"streams"` + Streams []LogProtoStream `json:"streams"` +} + +// LogProtoStream helps with unmarshalling of each log stream for push request. +// This might look un-necessary but without it the CPU usage in benchmarks was increasing by ~25% :shrug: +type LogProtoStream struct { + logproto.Stream +} + +func (s *LogProtoStream) UnmarshalJSON(data []byte) error { + err := jsonparser.ObjectEach(data, func(key, val []byte, ty jsonparser.ValueType, _ int) error { + switch string(key) { + case "stream": + labels := make(LabelSet) + err := jsonparser.ObjectEach(val, func(key, val []byte, _ jsonparser.ValueType, _ int) error { + labels[yoloString(key)] = yoloString(val) + return nil + }) + if err != nil { + return err + } + s.Labels = labels.String() + case "values": + if ty == jsonparser.Null { + return nil + } + entries, err := unmarshalHTTPToLogProtoEntries(val) + if err != nil { + return err + } + s.Entries = entries + } + return nil + }) + return err +} + +func unmarshalHTTPToLogProtoEntries(data []byte) ([]logproto.Entry, error) { + var ( + entries []logproto.Entry + parseError error + ) + _, err := jsonparser.ArrayEach(data, func(value []byte, ty jsonparser.ValueType, _ int, err error) { + if err != nil || parseError != nil { + return + } + if ty == jsonparser.Null { + return + } + e, err := unmarshalHTTPToLogProtoEntry(value) + if err != nil { + parseError = err + return + } + entries = append(entries, e) + }) + if parseError != nil { + return nil, parseError + } + if err != nil { + return nil, parseError + } + + return entries, nil +} + +func unmarshalHTTPToLogProtoEntry(data []byte) (logproto.Entry, error) { + var ( + i int + parseError error + e logproto.Entry + ) + _, err := jsonparser.ArrayEach(data, func(value []byte, t jsonparser.ValueType, _ int, _ error) { + // assert that both items in array are of type string + if (i == 0 || i == 1) && t != jsonparser.String { + parseError = jsonparser.MalformedStringError + return + } else if i == 2 && t != jsonparser.Object { + parseError = jsonparser.MalformedObjectError + return + } + switch i { + case 0: // timestamp + ts, err := jsonparser.ParseInt(value) + if err != nil { + parseError = err + return + } + e.Timestamp = time.Unix(0, ts) + case 1: // value + v, err := jsonparser.ParseString(value) + if err != nil { + parseError = err + return + } + e.Line = v + case 2: // labels + labels := make(LabelSet) + err := jsonparser.ObjectEach(value, func(key, val []byte, _ jsonparser.ValueType, _ int) error { + labels[yoloString(key)] = yoloString(val) + return nil + }) + if err != nil { + parseError = err + return + } + e.Labels = labels.String() + } + i++ + }) + if parseError != nil { + return e, parseError + } + return e, err } // ResultType holds the type of the result @@ -377,3 +490,7 @@ func labelVolumeLimit(r *http.Request) error { return nil } + +func yoloString(buf []byte) string { + return *((*string)(unsafe.Pointer(&buf))) +} diff --git a/pkg/util/unmarshal/unmarshal.go b/pkg/util/unmarshal/unmarshal.go index 3250b5a06c2e4..51e7d1108d9d9 100644 --- a/pkg/util/unmarshal/unmarshal.go +++ b/pkg/util/unmarshal/unmarshal.go @@ -2,7 +2,6 @@ package unmarshal import ( "io" - "reflect" "unsafe" jsoniter "github.com/json-iterator/go" @@ -19,57 +18,13 @@ func DecodePushRequest(b io.Reader, r *logproto.PushRequest) error { return err } - req, err := NewPushRequest(request) - if err != nil { - return err + *r = logproto.PushRequest{ + Streams: *(*[]logproto.Stream)(unsafe.Pointer(&request.Streams)), } - *r = *req return nil } -// NewPushRequest constructs a logproto.PushRequest from a PushRequest -func NewPushRequest(r loghttp.PushRequest) (*logproto.PushRequest, error) { - ret := logproto.PushRequest{ - Streams: make([]logproto.Stream, len(r.Streams)), - } - - for i, s := range r.Streams { - stream, err := NewStream(s) - if err != nil { - return nil, err - } - - ret.Streams[i] = *stream - } - - return &ret, nil -} - -// NewStream constructs a logproto.Stream from a Stream -func NewStream(s *loghttp.Stream) (*logproto.Stream, error) { - stream := logproto.Stream{ - Entries: *(*[]logproto.Entry)(unsafe.Pointer(&s.Entries)), - Labels: s.Labels.String(), - } - - for i, entry := range stream.Entries { - if entry.Labels == "" { - continue - } - // labels in v1 HTTP push endpoint are in json format({"foo":"bar"}) while for proto it is key=value format({foo="bar"}) - // So here we need to convert metadata labels from json to proto format. - // ToDo(Sandeep): Find a way to either not do the conversion or efficiently do it since - // metadata labels can be attached to each log line. - labels := loghttp.LabelSet{} - if err := labels.UnmarshalJSON(yoloBytes(entry.Labels)); err != nil { - return nil, err - } - stream.Entries[i].Labels = labels.String() - } - return &stream, nil -} - // WebsocketReader knows how to read message to a websocket connection. type WebsocketReader interface { ReadMessage() (int, []byte, error) @@ -83,9 +38,3 @@ func ReadTailResponseJSON(r *loghttp.TailResponse, reader WebsocketReader) error } return jsoniter.Unmarshal(data, r) } - -func yoloBytes(s string) (b []byte) { - *(*string)(unsafe.Pointer(&b)) = s - (*reflect.SliceHeader)(unsafe.Pointer(&b)).Cap = len(s) - return -} diff --git a/pkg/util/unmarshal/unmarshal_test.go b/pkg/util/unmarshal/unmarshal_test.go index 51e515e0d1df0..da8f8640f4d46 100644 --- a/pkg/util/unmarshal/unmarshal_test.go +++ b/pkg/util/unmarshal/unmarshal_test.go @@ -45,6 +45,32 @@ var pushTests = []struct { ] }`, }, + { + []logproto.Stream{ + { + Entries: []logproto.Entry{ + { + Timestamp: time.Unix(0, 123456789012345), + Line: "super line", + Labels: `{foo="bar"}`, + }, + }, + Labels: `{test="test"}`, + }, + }, + `{ + "streams": [ + { + "stream": { + "test": "test" + }, + "values":[ + [ "123456789012345", "super line", {"foo":"bar"} ] + ] + } + ] + }`, + }, } func Test_DecodePushRequest(t *testing.T) { From 617e8641e9bfe8a94f9acb71abecd93902ccfc4b Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Mon, 19 Jun 2023 16:49:37 +0530 Subject: [PATCH 15/36] revert some accidental chagnes --- integration/client/client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration/client/client.go b/integration/client/client.go index 114c99f27929f..5a3ba3ce961f9 100644 --- a/integration/client/client.go +++ b/integration/client/client.go @@ -86,8 +86,8 @@ func New(instanceID, token, baseURL string, opts ...Option) *Client { } // PushLogLine creates a new logline with the current time as timestamp -func (c *Client) PushLogLine(line string, logLabels ...map[string]string) error { - return c.pushLogLine(line, c.Now, nil, logLabels...) +func (c *Client) PushLogLine(line string, extraLabels ...map[string]string) error { + return c.pushLogLine(line, c.Now, nil, extraLabels...) } func (c *Client) PushLogLineWithMetadata(line string, logLabels map[string]string, extraLabels ...map[string]string) error { @@ -96,8 +96,8 @@ func (c *Client) PushLogLineWithMetadata(line string, logLabels map[string]strin // PushLogLineWithTimestamp creates a new logline at the given timestamp // The timestamp has to be a Unix timestamp (epoch seconds) -func (c *Client) PushLogLineWithTimestamp(line string, timestamp time.Time, logLabels ...map[string]string) error { - return c.pushLogLine(line, timestamp, nil, logLabels...) +func (c *Client) PushLogLineWithTimestamp(line string, timestamp time.Time, extraLabels ...map[string]string) error { + return c.pushLogLine(line, timestamp, nil, extraLabels...) } func (c *Client) PushLogLineWithTimestampAndMetadata(line string, timestamp time.Time, logLabels map[string]string, extraLabelList ...map[string]string) error { From f43dfab7febf8784e6624ea3459826ac0ec0309b Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 29 Jun 2023 10:43:23 +0200 Subject: [PATCH 16/36] Make labels in loghttp.Entry of type LabelSet --- .../loki_micro_services_delete_test.go | 4 -- pkg/loghttp/entry.go | 65 +++++++++++++++---- pkg/loghttp/query.go | 5 +- pkg/querier/queryrange/codec_test.go | 4 +- pkg/util/marshal/marshal_test.go | 6 +- pkg/util/marshal/query.go | 26 ++++++-- 6 files changed, 83 insertions(+), 27 deletions(-) diff --git a/integration/loki_micro_services_delete_test.go b/integration/loki_micro_services_delete_test.go index 78d1b44b87742..1ba0e3e2c20c1 100644 --- a/integration/loki_micro_services_delete_test.go +++ b/integration/loki_micro_services_delete_test.go @@ -99,22 +99,18 @@ func TestMicroServicesDeleteRequest(t *testing.T) { { strconv.FormatInt(now.Add(-48*time.Hour).UnixNano(), 10), "lineA", - "", }, { strconv.FormatInt(now.Add(-48*time.Hour).UnixNano(), 10), "lineB", - "", }, { strconv.FormatInt(now.Add(-time.Minute).UnixNano(), 10), "lineC", - "", }, { strconv.FormatInt(now.Add(-time.Minute).UnixNano(), 10), "lineD", - "", }, }, }) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index afcda0262cb99..43b268b06446e 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -8,6 +8,8 @@ import ( "github.com/buger/jsonparser" jsoniter "github.com/json-iterator/go" "github.com/modern-go/reflect2" + + "github.com/grafana/loki/pkg/logproto" ) func init() { @@ -18,7 +20,21 @@ func init() { type Entry struct { Timestamp time.Time Line string - Labels string + Labels LabelSet +} + +func (e Entry) ToProto() logproto.Entry { + // If there are no labels, we return empty string instead of '{}'. + var labels string + if len(e.Labels) > 0 { + labels = e.Labels.String() + } + + return logproto.Entry{ + Timestamp: e.Timestamp, + Line: e.Line, + Labels: labels, + } } func (e *Entry) UnmarshalJSON(data []byte) error { @@ -28,12 +44,12 @@ func (e *Entry) UnmarshalJSON(data []byte) error { ) _, err := jsonparser.ArrayEach(data, func(value []byte, t jsonparser.ValueType, _ int, _ error) { // assert that both items in array are of type string - if t != jsonparser.String { - parseError = jsonparser.MalformedStringError - return - } switch i { case 0: // timestamp + if t != jsonparser.String { + parseError = jsonparser.MalformedStringError + return + } ts, err := jsonparser.ParseInt(value) if err != nil { parseError = err @@ -41,6 +57,10 @@ func (e *Entry) UnmarshalJSON(data []byte) error { } e.Timestamp = time.Unix(0, ts) case 1: // value + if t != jsonparser.String { + parseError = jsonparser.MalformedStringError + return + } v, err := jsonparser.ParseString(value) if err != nil { parseError = err @@ -48,12 +68,21 @@ func (e *Entry) UnmarshalJSON(data []byte) error { } e.Line = v case 2: // labels - il, err := jsonparser.ParseString(value) - if err != nil { + if t != jsonparser.Object { + parseError = jsonparser.MalformedObjectError + return + } + e.Labels = make(LabelSet) + if err := jsonparser.ObjectEach(value, func(key []byte, value []byte, dataType jsonparser.ValueType, _ int) error { + if dataType != jsonparser.String { + return jsonparser.MalformedStringError + } + e.Labels[yoloString(key)] = yoloString(value) + return nil + }); err != nil { parseError = err return } - e.Labels = il } i++ }) @@ -75,7 +104,7 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { i := 0 var ts time.Time var line string - var labels string + var labels LabelSet ok := iter.ReadArrayCB(func(iter *jsoniter.Iterator) bool { var ok bool switch i { @@ -91,7 +120,12 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { } return true case 2: - labels = iter.ReadString() + labels = make(LabelSet) + iter.ReadMapCB(func(iter *jsoniter.Iterator, labelName string) bool { + labelValue := iter.ReadString() + labels[labelName] = labelValue + return true + }) i++ if iter.Error != nil { return false @@ -143,8 +177,15 @@ func (EntryEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { stream.WriteRaw(`"`) stream.WriteMore() stream.WriteStringWithHTMLEscaped(e.Line) - stream.WriteMore() - stream.WriteString(e.Labels) + if len(e.Labels) > 0 { + stream.WriteMore() + stream.WriteObjectStart() + for lName, lValue := range e.Labels { + stream.WriteObjectField(lName) + stream.WriteString(lValue) + } + stream.WriteObjectEnd() + } stream.WriteArrayEnd() } diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index ddc66193138f4..e1bb65b0cf6da 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -233,7 +233,10 @@ func (s Streams) ToProto() []logproto.Stream { } result := make([]logproto.Stream, 0, len(s)) for _, s := range s { - entries := *(*[]logproto.Entry)(unsafe.Pointer(&s.Entries)) + entries := make([]logproto.Entry, len(s.Entries), len(s.Entries)) + for i, e := range s.Entries { + entries[i] = e.ToProto() + } result = append(result, logproto.Stream{Labels: s.Labels.String(), Entries: entries}) } return result diff --git a/pkg/querier/queryrange/codec_test.go b/pkg/querier/queryrange/codec_test.go index a1a284c78db98..532219baa7edb 100644 --- a/pkg/querier/queryrange/codec_test.go +++ b/pkg/querier/queryrange/codec_test.go @@ -1187,7 +1187,7 @@ var ( "test": "test" }, "values":[ - [ "123456789012345", "super line", "" ] + [ "123456789012345", "super line"] ] }, { @@ -1195,7 +1195,7 @@ var ( "test": "test2" }, "values":[ - [ "123456789012346", "super line2", "" ] + [ "123456789012346", "super line2"] ] } ] diff --git a/pkg/util/marshal/marshal_test.go b/pkg/util/marshal/marshal_test.go index ecd03e920710f..6025abd4528d8 100644 --- a/pkg/util/marshal/marshal_test.go +++ b/pkg/util/marshal/marshal_test.go @@ -48,7 +48,7 @@ var queryTests = []struct { "test": "test" }, "values":[ - [ "123456789012345", "super line", "" ] + [ "123456789012345", "super line"] ] } ], @@ -506,7 +506,7 @@ var tailTests = []struct { "test": "test" }, "values":[ - [ "123456789012345", "super line", "" ] + [ "123456789012345", "super line"] ] } ], @@ -828,7 +828,7 @@ func Test_WriteTailResponseJSON(t *testing.T) { }, }, WebsocketWriterFunc(func(i int, b []byte) error { - require.Equal(t, `{"streams":[{"stream":{"app":"foo"},"values":[["1","foobar",""]]}],"dropped_entries":[{"timestamp":"2","labels":{"app":"dropped"}}]}`, string(b)) + require.Equal(t, `{"streams":[{"stream":{"app":"foo"},"values":[["1","foobar"]]}],"dropped_entries":[{"timestamp":"2","labels":{"app":"dropped"}}]}`, string(b)) return nil }), ), diff --git a/pkg/util/marshal/query.go b/pkg/util/marshal/query.go index bcc4f500b75c1..5a322027bd05f 100644 --- a/pkg/util/marshal/query.go +++ b/pkg/util/marshal/query.go @@ -13,6 +13,7 @@ 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" ) @@ -96,18 +97,31 @@ func NewStream(s logproto.Stream) (loghttp.Stream, error) { } for i, e := range s.Entries { - ret.Entries[i] = NewEntry(e) + ret.Entries[i], err = NewEntry(e) + if err != nil { + return loghttp.Stream{}, err + } } return ret, nil } // NewEntry constructs an Entry from a logproto.Entry -func NewEntry(e logproto.Entry) loghttp.Entry { +func NewEntry(e logproto.Entry) (loghttp.Entry, error) { + var labels loghttp.LabelSet + if e.Labels != "" { + lbls, err := syntax.ParseLabels(e.Labels) + if err != nil { + return loghttp.Entry{}, errors.Wrapf(err, "err while creating labelset for entry %s", e.Labels) + } + labels = lbls.Map() + } + return loghttp.Entry{ Timestamp: e.Timestamp, Line: e.Line, - } + Labels: labels, + }, nil } func NewScalar(s promql.Scalar) loghttp.Scalar { @@ -315,8 +329,10 @@ func encodeStream(stream logproto.Stream, s *jsoniter.Stream) error { s.WriteRaw(`"`) s.WriteMore() s.WriteStringWithHTMLEscaped(e.Line) - s.WriteMore() - s.WriteString(e.Labels) + if e.Labels != "" { + s.WriteMore() + s.WriteString(e.Labels) + } s.WriteArrayEnd() s.Flush() From 384d556c8ab30c0e58c4834c5090aafdf294995d Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 29 Jun 2023 11:09:53 +0200 Subject: [PATCH 17/36] Apply CR feedback --- pkg/loghttp/query.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index e1bb65b0cf6da..fae1707cad36a 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -71,7 +71,10 @@ func (s *LogProtoStream) UnmarshalJSON(data []byte) error { switch string(key) { case "stream": labels := make(LabelSet) - err := jsonparser.ObjectEach(val, func(key, val []byte, _ jsonparser.ValueType, _ int) error { + err := jsonparser.ObjectEach(val, func(key, val []byte, dataType jsonparser.ValueType, _ int) error { + if dataType != jsonparser.String { + return jsonparser.MalformedStringError + } labels[yoloString(key)] = yoloString(val) return nil }) @@ -99,7 +102,7 @@ func unmarshalHTTPToLogProtoEntries(data []byte) ([]logproto.Entry, error) { entries []logproto.Entry parseError error ) - _, err := jsonparser.ArrayEach(data, func(value []byte, ty jsonparser.ValueType, _ int, err error) { + if _, err := jsonparser.ArrayEach(data, func(value []byte, ty jsonparser.ValueType, _ int, err error) { if err != nil || parseError != nil { return } @@ -112,11 +115,11 @@ func unmarshalHTTPToLogProtoEntries(data []byte) ([]logproto.Entry, error) { return } entries = append(entries, e) - }) - if parseError != nil { - return nil, parseError + }); err != nil { + parseError = err } - if err != nil { + + if parseError != nil { return nil, parseError } @@ -155,7 +158,10 @@ func unmarshalHTTPToLogProtoEntry(data []byte) (logproto.Entry, error) { e.Line = v case 2: // labels labels := make(LabelSet) - err := jsonparser.ObjectEach(value, func(key, val []byte, _ jsonparser.ValueType, _ int) error { + err := jsonparser.ObjectEach(value, func(key, val []byte, dataType jsonparser.ValueType, _ int) error { + if dataType != jsonparser.String { + return jsonparser.MalformedStringError + } labels[yoloString(key)] = yoloString(val) return nil }) From 4088112f418372a5ae459084165a8c98f43a25e1 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 29 Jun 2023 11:16:59 +0200 Subject: [PATCH 18/36] Avoid allocations for empty labels --- integration/client/client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/integration/client/client.go b/integration/client/client.go index 5a3ba3ce961f9..823fbdf73a310 100644 --- a/integration/client/client.go +++ b/integration/client/client.go @@ -101,7 +101,14 @@ func (c *Client) PushLogLineWithTimestamp(line string, timestamp time.Time, extr } func (c *Client) PushLogLineWithTimestampAndMetadata(line string, timestamp time.Time, logLabels map[string]string, extraLabelList ...map[string]string) error { - return c.pushLogLine(line, timestamp, labels.FromMap(logLabels), extraLabelList...) + // If the logLabels map is empty, labels.FromMap will allocate some empty slices. + // Since this code is executed for every log line we receive, as an optimization + // to avoid those allocations we'll call labels.FromMap only if the map is not empty. + var lbls labels.Labels + if len(logLabels) > 0 { + lbls = labels.FromMap(logLabels) + } + return c.pushLogLine(line, timestamp, lbls, extraLabelList...) } func formatTS(ts time.Time) string { From 0b0af55dc0eacf86e583416e5e802d5b883d2f99 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 29 Jun 2023 12:05:56 +0200 Subject: [PATCH 19/36] Fix json encoding and add tests --- pkg/loghttp/entry.go | 5 +++++ pkg/loghttp/query_test.go | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index 43b268b06446e..cd2c784f4c32d 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -180,9 +180,14 @@ func (EntryEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { if len(e.Labels) > 0 { stream.WriteMore() stream.WriteObjectStart() + var idx int for lName, lValue := range e.Labels { + if idx > 0 { + stream.WriteMore() + } stream.WriteObjectField(lName) stream.WriteString(lValue) + idx++ } stream.WriteObjectEnd() } diff --git a/pkg/loghttp/query_test.go b/pkg/loghttp/query_test.go index eb841c16935d8..29ecd2047fa00 100644 --- a/pkg/loghttp/query_test.go +++ b/pkg/loghttp/query_test.go @@ -153,14 +153,14 @@ 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"}, + {Timestamp: time.Unix(0, 2), Line: "2", Labels: LabelSet{"foo": "bar"}}, }, }, { Labels: map[string]string{"foo": "bar", "lvl": "error"}, Entries: []Entry{ {Timestamp: time.Unix(0, 3), Line: "3"}, - {Timestamp: time.Unix(0, 4), Line: "4"}, + {Timestamp: time.Unix(0, 4), Line: "4", Labels: LabelSet{"foo": "bar"}}, }, }, }, @@ -169,14 +169,14 @@ 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"}, + {Timestamp: time.Unix(0, 2), Line: "2", Labels: LabelSet{"foo": "bar"}.String()}, }, }, { Labels: `{foo="bar", lvl="error"}`, Entries: []logproto.Entry{ {Timestamp: time.Unix(0, 3), Line: "3"}, - {Timestamp: time.Unix(0, 4), Line: "4"}, + {Timestamp: time.Unix(0, 4), Line: "4", Labels: LabelSet{"foo": "bar"}.String()}, }, }, }, @@ -210,7 +210,7 @@ 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"}, + {Timestamp: time.Unix(0, 2), Line: "2", Labels: LabelSet{"foo": "bar"}}, }, }, }, @@ -230,7 +230,7 @@ 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"}, + {Timestamp: time.Unix(0, 2), Line: "some log line 2", Labels: LabelSet{"foo": "bar"}}, }, }, Stream{ @@ -240,7 +240,7 @@ 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"}, + {Timestamp: time.Unix(0, 2), Line: "2", Labels: LabelSet{"foo": "bar"}}, }, }, }, From d4e311c4fabe2ad96fb10dbfc8f7ba7ac0cfadc8 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 29 Jun 2023 12:08:45 +0200 Subject: [PATCH 20/36] Change error message --- pkg/loghttp/entry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index cd2c784f4c32d..a4f085c14e24e 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -132,7 +132,7 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { } return true default: - iter.ReportError("error reading entry", "array must contains 2 values") + iter.ReportError("error reading entry", "array must have at least 2 and up to 3 values") return false } }) From 10d404e36264df337b9914f3e7c509e55068537f Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 29 Jun 2023 12:15:37 +0200 Subject: [PATCH 21/36] Add more labels to tests cases --- pkg/loghttp/query_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/loghttp/query_test.go b/pkg/loghttp/query_test.go index 29ecd2047fa00..d96d7a76367f4 100644 --- a/pkg/loghttp/query_test.go +++ b/pkg/loghttp/query_test.go @@ -153,14 +153,14 @@ 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", Labels: LabelSet{"foo": "bar"}}, + {Timestamp: time.Unix(0, 2), Line: "2", Labels: LabelSet{"foo": "a", "bar": "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", Labels: LabelSet{"foo": "bar"}}, + {Timestamp: time.Unix(0, 4), Line: "4", Labels: LabelSet{"foo": "a", "bar": "b"}}, }, }, }, @@ -169,14 +169,14 @@ 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", Labels: LabelSet{"foo": "bar"}.String()}, + {Timestamp: time.Unix(0, 2), Line: "2", Labels: LabelSet{"foo": "a", "bar": "b"}.String()}, }, }, { Labels: `{foo="bar", lvl="error"}`, Entries: []logproto.Entry{ {Timestamp: time.Unix(0, 3), Line: "3"}, - {Timestamp: time.Unix(0, 4), Line: "4", Labels: LabelSet{"foo": "bar"}.String()}, + {Timestamp: time.Unix(0, 4), Line: "4", Labels: LabelSet{"foo": "a", "bar": "b"}.String()}, }, }, }, @@ -210,7 +210,7 @@ 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", Labels: LabelSet{"foo": "bar"}}, + {Timestamp: time.Unix(0, 2), Line: "2", Labels: LabelSet{"foo": "a", "bar": "b"}}, }, }, }, @@ -230,7 +230,7 @@ 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", Labels: LabelSet{"foo": "bar"}}, + {Timestamp: time.Unix(0, 2), Line: "some log line 2", Labels: LabelSet{"foo": "a", "bar": "b"}}, }, }, Stream{ @@ -240,7 +240,7 @@ 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", Labels: LabelSet{"foo": "bar"}}, + {Timestamp: time.Unix(0, 2), Line: "2", Labels: LabelSet{"foo": "a", "bar": "b"}}, }, }, }, From fcd1e66bfab728b5a8ef58ebdd201c7a067a891c Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 29 Jun 2023 13:14:06 +0200 Subject: [PATCH 22/36] Fix encode and add more tests --- pkg/util/marshal/legacy/marshal_test.go | 20 ++++++++++++++++++++ pkg/util/marshal/marshal_test.go | 16 ++++++++++++++-- pkg/util/marshal/query.go | 16 +++++++++++++++- pkg/util/unmarshal/legacy/unmarshal_test.go | 10 ++++++++++ pkg/util/unmarshal/unmarshal_test.go | 4 ++-- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/pkg/util/marshal/legacy/marshal_test.go b/pkg/util/marshal/legacy/marshal_test.go index 3f0529b1fcd0a..1dd1d99337e45 100644 --- a/pkg/util/marshal/legacy/marshal_test.go +++ b/pkg/util/marshal/legacy/marshal_test.go @@ -27,6 +27,11 @@ var queryTests = []struct { Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:22.380001319Z"), Line: "super line", }, + { + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + Labels: `{foo="a", bar="b"}`, + }, }, Labels: `{test="test"}`, }, @@ -39,6 +44,11 @@ var queryTests = []struct { { "ts": "2019-09-13T18:32:22.380001319Z", "line": "super line" + }, + { + "ts": "2019-09-13T18:32:23.380001319Z", + "line": "super line with labels", + "labels": "{foo=\"a\", bar=\"b\"}" } ] } @@ -164,6 +174,11 @@ var tailTests = []struct { Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:22.380001319Z"), Line: "super line", }, + { + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + Labels: `{foo="a", bar="b"}`, + }, }, Labels: "{test=\"test\"}", }, @@ -183,6 +198,11 @@ var tailTests = []struct { { "ts": "2019-09-13T18:32:22.380001319Z", "line": "super line" + }, + { + "ts": "2019-09-13T18:32:23.380001319Z", + "line": "super line with labels", + "labels": "{foo=\"a\", bar=\"b\"}" } ] } diff --git a/pkg/util/marshal/marshal_test.go b/pkg/util/marshal/marshal_test.go index 6025abd4528d8..5787e3b4095f6 100644 --- a/pkg/util/marshal/marshal_test.go +++ b/pkg/util/marshal/marshal_test.go @@ -34,6 +34,11 @@ var queryTests = []struct { Timestamp: time.Unix(0, 123456789012345), Line: "super line", }, + { + Timestamp: time.Unix(0, 123456789012346), + Line: "super line with labels", + Labels: `{foo="a", bar="b"}`, + }, }, Labels: `{test="test"}`, }, @@ -48,7 +53,8 @@ var queryTests = []struct { "test": "test" }, "values":[ - [ "123456789012345", "super line"] + [ "123456789012345", "super line"], + [ "123456789012346", "super line with labels", { "foo": "a", "bar": "b" } ] ] } ], @@ -488,6 +494,11 @@ var tailTests = []struct { Timestamp: time.Unix(0, 123456789012345), Line: "super line", }, + { + Timestamp: time.Unix(0, 123456789012346), + Line: "super line with labels", + Labels: `{foo="a", bar="b"}`, + }, }, Labels: "{test=\"test\"}", }, @@ -506,7 +517,8 @@ var tailTests = []struct { "test": "test" }, "values":[ - [ "123456789012345", "super line"] + [ "123456789012345", "super line"], + [ "123456789012346", "super line with labels", { "foo": "a", "bar": "b" } ] ] } ], diff --git a/pkg/util/marshal/query.go b/pkg/util/marshal/query.go index 5a322027bd05f..41d618ccf0940 100644 --- a/pkg/util/marshal/query.go +++ b/pkg/util/marshal/query.go @@ -331,7 +331,21 @@ func encodeStream(stream logproto.Stream, s *jsoniter.Stream) error { s.WriteStringWithHTMLEscaped(e.Line) if e.Labels != "" { s.WriteMore() - s.WriteString(e.Labels) + s.WriteObjectStart() + labels, err = parser.ParseMetric(e.Labels) + if err != nil { + return err + } + + for i, l := range labels { + if i > 0 { + s.WriteMore() + } + + s.WriteObjectField(l.Name) + s.WriteString(l.Value) + } + s.WriteObjectEnd() } s.WriteArrayEnd() diff --git a/pkg/util/unmarshal/legacy/unmarshal_test.go b/pkg/util/unmarshal/legacy/unmarshal_test.go index e82682107e170..feacfdbe8b441 100644 --- a/pkg/util/unmarshal/legacy/unmarshal_test.go +++ b/pkg/util/unmarshal/legacy/unmarshal_test.go @@ -25,6 +25,11 @@ var pushTests = []struct { Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:22.380001319Z"), Line: "super line", }, + { + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + Labels: `{foo="a", bar="b"}`, + }, }, Labels: `{test="test"}`, }, @@ -37,6 +42,11 @@ var pushTests = []struct { { "ts": "2019-09-13T18:32:22.380001319Z", "line": "super line" + }, + { + "ts": "2019-09-13T18:32:23.380001319Z", + "line": "super line with labels", + "labels": "{foo=\"a\", bar=\"b\"}" } ] } diff --git a/pkg/util/unmarshal/unmarshal_test.go b/pkg/util/unmarshal/unmarshal_test.go index da8f8640f4d46..9fef987a8943d 100644 --- a/pkg/util/unmarshal/unmarshal_test.go +++ b/pkg/util/unmarshal/unmarshal_test.go @@ -52,7 +52,7 @@ var pushTests = []struct { { Timestamp: time.Unix(0, 123456789012345), Line: "super line", - Labels: `{foo="bar"}`, + Labels: `{a="1", b="2"}`, }, }, Labels: `{test="test"}`, @@ -65,7 +65,7 @@ var pushTests = []struct { "test": "test" }, "values":[ - [ "123456789012345", "super line", {"foo":"bar"} ] + [ "123456789012345", "super line", { "a": "1", "b": "2" } ] ] } ] From 64d3d6c2ec6d5ec9b6b9c2a450a2663da1d5cbce Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Fri, 30 Jun 2023 10:08:47 +0200 Subject: [PATCH 23/36] Do not use struct --- pkg/loghttp/query.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index fae1707cad36a..6b26dce17cf0a 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -62,9 +62,7 @@ type PushRequest struct { // LogProtoStream helps with unmarshalling of each log stream for push request. // This might look un-necessary but without it the CPU usage in benchmarks was increasing by ~25% :shrug: -type LogProtoStream struct { - logproto.Stream -} +type LogProtoStream logproto.Stream func (s *LogProtoStream) UnmarshalJSON(data []byte) error { err := jsonparser.ObjectEach(data, func(key, val []byte, ty jsonparser.ValueType, _ int) error { From 7f25bb8bd1fc32e317212e3c7f1b6a2900bd2d02 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Wed, 5 Jul 2023 16:40:47 +0530 Subject: [PATCH 24/36] remove a TODO --- pkg/push/push.pb.go | 6 +----- pkg/push/push.proto | 3 --- vendor/github.com/grafana/loki/pkg/push/push.pb.go | 6 +----- vendor/github.com/grafana/loki/pkg/push/push.proto | 3 --- 4 files changed, 2 insertions(+), 16 deletions(-) diff --git a/pkg/push/push.pb.go b/pkg/push/push.pb.go index 8f241eb44497d..4937ce2d4fd6f 100644 --- a/pkg/push/push.pb.go +++ b/pkg/push/push.pb.go @@ -167,11 +167,7 @@ func (m *StreamAdapter) GetHash() uint64 { 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"` - // TODO: maybe we can use the labels.Labels type here? - // - // So we can avoid the conversion to and from string. - // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. - Labels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` + Labels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } diff --git a/pkg/push/push.proto b/pkg/push/push.proto index 93c13f72ce67b..9e799b49c0704 100644 --- a/pkg/push/push.proto +++ b/pkg/push/push.proto @@ -37,8 +37,5 @@ message EntryAdapter { (gogoproto.jsontag) = "ts" ]; string line = 2 [(gogoproto.jsontag) = "line"]; - // TODO: maybe we can use the labels.Labels type here? - // So we can avoid the conversion to and from string. - // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. string labels = 3 [(gogoproto.jsontag) = "labels,omitempty"]; } 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 8f241eb44497d..4937ce2d4fd6f 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.pb.go +++ b/vendor/github.com/grafana/loki/pkg/push/push.pb.go @@ -167,11 +167,7 @@ func (m *StreamAdapter) GetHash() uint64 { 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"` - // TODO: maybe we can use the labels.Labels type here? - // - // So we can avoid the conversion to and from string. - // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. - Labels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` + Labels string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } diff --git a/vendor/github.com/grafana/loki/pkg/push/push.proto b/vendor/github.com/grafana/loki/pkg/push/push.proto index 93c13f72ce67b..9e799b49c0704 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.proto +++ b/vendor/github.com/grafana/loki/pkg/push/push.proto @@ -37,8 +37,5 @@ message EntryAdapter { (gogoproto.jsontag) = "ts" ]; string line = 2 [(gogoproto.jsontag) = "line"]; - // TODO: maybe we can use the labels.Labels type here? - // So we can avoid the conversion to and from string. - // Leaving it as string for now to be consistent with `labels` field in `StreamAdapter`. string labels = 3 [(gogoproto.jsontag) = "labels,omitempty"]; } From 752ae6bef324c93ca885f58303c0ba2f82aed78c Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Mon, 10 Jul 2023 12:06:08 +0200 Subject: [PATCH 25/36] rename to NonIndexedLabels --- pkg/loghttp/entry.go | 28 ++++++++++++++-------------- pkg/loghttp/query_test.go | 10 +++++----- pkg/push/types.go | 24 ++++++++++++------------ pkg/util/marshal/query.go | 6 +++--- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index a4f085c14e24e..2433dcf69d49e 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -18,22 +18,22 @@ func init() { // Entry represents a log entry. It includes a log message and the time it occurred at. type Entry struct { - Timestamp time.Time - Line string - Labels LabelSet + 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 labels string - if len(e.Labels) > 0 { - labels = e.Labels.String() + var nonIndexedLabels string + if len(e.NonIndexedLabels) > 0 { + nonIndexedLabels = e.NonIndexedLabels.String() } return logproto.Entry{ Timestamp: e.Timestamp, Line: e.Line, - Labels: labels, + Labels: nonIndexedLabels, } } @@ -72,12 +72,12 @@ func (e *Entry) UnmarshalJSON(data []byte) error { parseError = jsonparser.MalformedObjectError return } - e.Labels = make(LabelSet) + e.NonIndexedLabels = make(LabelSet) if err := jsonparser.ObjectEach(value, func(key []byte, value []byte, dataType jsonparser.ValueType, _ int) error { if dataType != jsonparser.String { return jsonparser.MalformedStringError } - e.Labels[yoloString(key)] = yoloString(value) + e.NonIndexedLabels[yoloString(key)] = yoloString(value) return nil }); err != nil { parseError = err @@ -138,9 +138,9 @@ func (sliceEntryDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { }) if ok { *((*[]Entry)(ptr)) = append(*((*[]Entry)(ptr)), Entry{ - Timestamp: ts, - Line: line, - Labels: labels, + Timestamp: ts, + Line: line, + NonIndexedLabels: labels, }) return true } @@ -177,11 +177,11 @@ func (EntryEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) { stream.WriteRaw(`"`) stream.WriteMore() stream.WriteStringWithHTMLEscaped(e.Line) - if len(e.Labels) > 0 { + if len(e.NonIndexedLabels) > 0 { stream.WriteMore() stream.WriteObjectStart() var idx int - for lName, lValue := range e.Labels { + for lName, lValue := range e.NonIndexedLabels { if idx > 0 { stream.WriteMore() } diff --git a/pkg/loghttp/query_test.go b/pkg/loghttp/query_test.go index d96d7a76367f4..ef7108efcc3d8 100644 --- a/pkg/loghttp/query_test.go +++ b/pkg/loghttp/query_test.go @@ -153,14 +153,14 @@ 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", Labels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "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", Labels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 4), Line: "4", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, }, }, }, @@ -210,7 +210,7 @@ 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", Labels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, }, }, }, @@ -230,7 +230,7 @@ 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", Labels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 2), Line: "some log line 2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, }, }, Stream{ @@ -240,7 +240,7 @@ 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", Labels: LabelSet{"foo": "a", "bar": "b"}}, + {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}}, }, }, }, diff --git a/pkg/push/types.go b/pkg/push/types.go index 6c7668db02e5a..5c687d09738e6 100644 --- a/pkg/push/types.go +++ b/pkg/push/types.go @@ -17,9 +17,9 @@ 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"` - Labels 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 string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` } func (m *Stream) Marshal() (dAtA []byte, err error) { @@ -91,10 +91,10 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Labels) > 0 { - i -= len(m.Labels) - copy(dAtA[i:], m.Labels) - i = encodeVarintPush(dAtA, i, uint64(len(m.Labels))) + 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 } @@ -147,7 +147,7 @@ func (m *Stream) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -351,7 +351,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -379,7 +379,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Labels = string(dAtA[iNdEx:postIndex]) + m.NonIndexedLabels = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -440,7 +440,7 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.Labels) + l = len(m.NonIndexedLabels) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -505,7 +505,7 @@ func (m *Entry) Equal(that interface{}) bool { if m.Line != that1.Line { return false } - if m.Labels != that1.Labels { + if m.NonIndexedLabels != that1.NonIndexedLabels { return false } return true diff --git a/pkg/util/marshal/query.go b/pkg/util/marshal/query.go index 41d618ccf0940..b0b30d388626e 100644 --- a/pkg/util/marshal/query.go +++ b/pkg/util/marshal/query.go @@ -118,9 +118,9 @@ func NewEntry(e logproto.Entry) (loghttp.Entry, error) { } return loghttp.Entry{ - Timestamp: e.Timestamp, - Line: e.Line, - Labels: labels, + Timestamp: e.Timestamp, + Line: e.Line, + NonIndexedLabels: labels, }, nil } From 4b671450eb55bb4c6888f2b29eb64d8d17324b32 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Mon, 10 Jul 2023 12:11:39 +0200 Subject: [PATCH 26/36] Add missing protos updates --- pkg/push/push.pb.go | 89 +++++++++++++++++++++++---------------------- pkg/push/push.proto | 2 +- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/pkg/push/push.pb.go b/pkg/push/push.pb.go index 4937ce2d4fd6f..79849186a8efc 100644 --- a/pkg/push/push.pb.go +++ b/pkg/push/push.pb.go @@ -165,9 +165,9 @@ func (m *StreamAdapter) GetHash() uint64 { } 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"` - Labels 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 string `protobuf:"bytes,3,opt,name=nonIndexedLabels,proto3" json:"nonIndexedLabels,omitempty"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } @@ -216,9 +216,9 @@ func (m *EntryAdapter) GetLine() string { return "" } -func (m *EntryAdapter) GetLabels() string { +func (m *EntryAdapter) GetNonIndexedLabels() string { if m != nil { - return m.Labels + return m.NonIndexedLabels } return "" } @@ -233,35 +233,36 @@ func init() { func init() { proto.RegisterFile("pkg/push/push.proto", fileDescriptor_35ec442956852c9e) } var fileDescriptor_35ec442956852c9e = []byte{ - // 446 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x52, 0x41, 0x6f, 0xd3, 0x30, - 0x18, 0xb5, 0xdb, 0xd2, 0x6d, 0xee, 0x18, 0xc8, 0x6c, 0xa3, 0x54, 0xc8, 0xae, 0x72, 0xea, 0x61, - 0x24, 0x52, 0x39, 0x70, 0x6e, 0x24, 0xa4, 0x1d, 0x51, 0x40, 0x20, 0x71, 0x73, 0xc1, 0x73, 0xa2, - 0x25, 0x71, 0x88, 0x9d, 0xc3, 0x6e, 0xfc, 0x84, 0xf1, 0x1f, 0x38, 0xf0, 0x53, 0x76, 0xec, 0x71, - 0xe2, 0x10, 0x68, 0x7a, 0x41, 0x39, 0xed, 0x27, 0xa0, 0x38, 0xf1, 0x5a, 0xb8, 0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 0x9d, 0x02, 0x00, 0x00, + // 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, 0xe2, 0xa9, 0x38, 0xa5, 0x52, + 0x85, 0x69, 0xd6, 0x16, 0x38, 0xef, 0xe1, 0xe8, 0x75, 0x21, 0xa3, 0x80, 0x7e, 0x2a, 0xa8, 0x54, + 0xe8, 0x18, 0xee, 0x48, 0x95, 0xd3, 0x30, 0x95, 0x63, 0x30, 0xe9, 0x4f, 0x47, 0xb3, 0x07, 0xae, + 0x61, 0x70, 0xdf, 0xe8, 0xc4, 0x7c, 0x19, 0x66, 0x8a, 0xe6, 0xfe, 0xe1, 0x8f, 0x92, 0x0c, 0xdb, + 0x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x39, 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, } func (this *PushRequest) Equal(that interface{}) bool { @@ -374,7 +375,7 @@ func (this *EntryAdapter) Equal(that interface{}) bool { if this.Line != that1.Line { return false } - if this.Labels != that1.Labels { + if this.NonIndexedLabels != that1.NonIndexedLabels { return false } return true @@ -424,7 +425,7 @@ 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, "Labels: "+fmt.Sprintf("%#v", this.Labels)+",\n") + s = append(s, "NonIndexedLabels: "+fmt.Sprintf("%#v", this.NonIndexedLabels)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -646,10 +647,10 @@ func (m *EntryAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Labels) > 0 { - i -= len(m.Labels) - copy(dAtA[i:], m.Labels) - i = encodeVarintPush(dAtA, i, uint64(len(m.Labels))) + 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 } @@ -740,7 +741,7 @@ func (m *EntryAdapter) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.Labels) + l = len(m.NonIndexedLabels) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -796,7 +797,7 @@ func (this *EntryAdapter) String() string { 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) + `,`, - `Labels:` + fmt.Sprintf("%v", this.Labels) + `,`, + `NonIndexedLabels:` + fmt.Sprintf("%v", this.NonIndexedLabels) + `,`, `}`, }, "") return s @@ -1183,7 +1184,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1211,7 +1212,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Labels = string(dAtA[iNdEx:postIndex]) + m.NonIndexedLabels = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex diff --git a/pkg/push/push.proto b/pkg/push/push.proto index 9e799b49c0704..49be9a2577267 100644 --- a/pkg/push/push.proto +++ b/pkg/push/push.proto @@ -37,5 +37,5 @@ message EntryAdapter { (gogoproto.jsontag) = "ts" ]; string line = 2 [(gogoproto.jsontag) = "line"]; - string labels = 3 [(gogoproto.jsontag) = "labels,omitempty"]; + string nonIndexedLabels = 3 [(gogoproto.jsontag) = "nonIndexedLabels,omitempty"]; } From aa58916e2594142429374688177ab4d739de2b63 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Mon, 10 Jul 2023 12:20:28 +0200 Subject: [PATCH 27/36] Update vendor --- .../grafana/loki/pkg/push/push.pb.go | 89 ++++++++++--------- .../grafana/loki/pkg/push/push.proto | 2 +- .../github.com/grafana/loki/pkg/push/types.go | 24 ++--- 3 files changed, 58 insertions(+), 57 deletions(-) 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 4937ce2d4fd6f..79849186a8efc 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.pb.go +++ b/vendor/github.com/grafana/loki/pkg/push/push.pb.go @@ -165,9 +165,9 @@ func (m *StreamAdapter) GetHash() uint64 { } 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"` - Labels 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 string `protobuf:"bytes,3,opt,name=nonIndexedLabels,proto3" json:"nonIndexedLabels,omitempty"` } func (m *EntryAdapter) Reset() { *m = EntryAdapter{} } @@ -216,9 +216,9 @@ func (m *EntryAdapter) GetLine() string { return "" } -func (m *EntryAdapter) GetLabels() string { +func (m *EntryAdapter) GetNonIndexedLabels() string { if m != nil { - return m.Labels + return m.NonIndexedLabels } return "" } @@ -233,35 +233,36 @@ func init() { func init() { proto.RegisterFile("pkg/push/push.proto", fileDescriptor_35ec442956852c9e) } var fileDescriptor_35ec442956852c9e = []byte{ - // 446 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0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d, - 0xc0, 0xed, 0x9a, 0x80, 0xbb, 0x35, 0x81, 0x5f, 0x2b, 0x02, 0x7f, 0x54, 0x04, 0xde, 0x54, 0x04, - 0xae, 0x2a, 0x02, 0x7f, 0x57, 0x04, 0xfe, 0xa9, 0x08, 0xb8, 0xab, 0x08, 0xbc, 0xde, 0x10, 0xb0, - 0xda, 0x10, 0x70, 0xbb, 0x21, 0xe0, 0xe3, 0x54, 0x44, 0x3a, 0x2c, 0x96, 0xee, 0x27, 0x99, 0x78, - 0x22, 0x67, 0x17, 0x2c, 0x65, 0x5e, 0x2c, 0x2f, 0x23, 0xcf, 0x3e, 0xc5, 0xe5, 0xd0, 0xa8, 0xbd, - 0xfc, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x95, 0x50, 0x89, 0x19, 0x9d, 0x02, 0x00, 0x00, + // 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, 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, 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, } func (this *PushRequest) Equal(that interface{}) bool { @@ -374,7 +375,7 @@ func (this *EntryAdapter) Equal(that interface{}) bool { if this.Line != that1.Line { return false } - if this.Labels != that1.Labels { + if this.NonIndexedLabels != that1.NonIndexedLabels { return false } return true @@ -424,7 +425,7 @@ 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, "Labels: "+fmt.Sprintf("%#v", this.Labels)+",\n") + s = append(s, "NonIndexedLabels: "+fmt.Sprintf("%#v", this.NonIndexedLabels)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -646,10 +647,10 @@ func (m *EntryAdapter) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Labels) > 0 { - i -= len(m.Labels) - copy(dAtA[i:], m.Labels) - i = encodeVarintPush(dAtA, i, uint64(len(m.Labels))) + 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 } @@ -740,7 +741,7 @@ func (m *EntryAdapter) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.Labels) + l = len(m.NonIndexedLabels) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -796,7 +797,7 @@ func (this *EntryAdapter) String() string { 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) + `,`, - `Labels:` + fmt.Sprintf("%v", this.Labels) + `,`, + `NonIndexedLabels:` + fmt.Sprintf("%v", this.NonIndexedLabels) + `,`, `}`, }, "") return s @@ -1183,7 +1184,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1211,7 +1212,7 @@ func (m *EntryAdapter) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Labels = string(dAtA[iNdEx:postIndex]) + m.NonIndexedLabels = string(dAtA[iNdEx:postIndex]) 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 9e799b49c0704..49be9a2577267 100644 --- a/vendor/github.com/grafana/loki/pkg/push/push.proto +++ b/vendor/github.com/grafana/loki/pkg/push/push.proto @@ -37,5 +37,5 @@ message EntryAdapter { (gogoproto.jsontag) = "ts" ]; string line = 2 [(gogoproto.jsontag) = "line"]; - string labels = 3 [(gogoproto.jsontag) = "labels,omitempty"]; + string nonIndexedLabels = 3 [(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 6c7668db02e5a..5c687d09738e6 100644 --- a/vendor/github.com/grafana/loki/pkg/push/types.go +++ b/vendor/github.com/grafana/loki/pkg/push/types.go @@ -17,9 +17,9 @@ 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"` - Labels 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 string `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` } func (m *Stream) Marshal() (dAtA []byte, err error) { @@ -91,10 +91,10 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Labels) > 0 { - i -= len(m.Labels) - copy(dAtA[i:], m.Labels) - i = encodeVarintPush(dAtA, i, uint64(len(m.Labels))) + 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 } @@ -147,7 +147,7 @@ func (m *Stream) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -351,7 +351,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Labels", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NonIndexedLabels", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -379,7 +379,7 @@ func (m *Entry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Labels = string(dAtA[iNdEx:postIndex]) + m.NonIndexedLabels = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -440,7 +440,7 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovPush(uint64(l)) } - l = len(m.Labels) + l = len(m.NonIndexedLabels) if l > 0 { n += 1 + l + sovPush(uint64(l)) } @@ -505,7 +505,7 @@ func (m *Entry) Equal(that interface{}) bool { if m.Line != that1.Line { return false } - if m.Labels != that1.Labels { + if m.NonIndexedLabels != that1.NonIndexedLabels { return false } return true From 4c60a9ed50ad28712d25361853b6234580a4541b Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Mon, 10 Jul 2023 12:39:51 +0200 Subject: [PATCH 28/36] Update after mod vendor --- pkg/loghttp/entry.go | 6 +++--- pkg/loghttp/query.go | 8 ++++---- pkg/loghttp/query_test.go | 4 ++-- pkg/util/marshal/legacy/marshal_test.go | 12 ++++++------ pkg/util/marshal/marshal_test.go | 12 ++++++------ pkg/util/marshal/query.go | 10 +++++----- pkg/util/unmarshal/legacy/unmarshal_test.go | 6 +++--- pkg/util/unmarshal/unmarshal_test.go | 6 +++--- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index 2433dcf69d49e..28d92b6b4dcf6 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -31,9 +31,9 @@ func (e Entry) ToProto() logproto.Entry { } return logproto.Entry{ - Timestamp: e.Timestamp, - Line: e.Line, - Labels: nonIndexedLabels, + Timestamp: e.Timestamp, + Line: e.Line, + NonIndexedLabels: nonIndexedLabels, } } diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index 4599978448de9..6f905029ab66e 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -155,20 +155,20 @@ func unmarshalHTTPToLogProtoEntry(data []byte) (logproto.Entry, error) { return } e.Line = v - case 2: // labels - labels := make(LabelSet) + case 2: // nonIndexedLabels + nonIndexedLabels := make(LabelSet) err := jsonparser.ObjectEach(value, func(key, val []byte, dataType jsonparser.ValueType, _ int) error { if dataType != jsonparser.String { return jsonparser.MalformedStringError } - labels[yoloString(key)] = yoloString(val) + nonIndexedLabels[yoloString(key)] = yoloString(val) return nil }) if err != nil { parseError = err return } - e.Labels = labels.String() + e.NonIndexedLabels = nonIndexedLabels.String() } i++ }) diff --git a/pkg/loghttp/query_test.go b/pkg/loghttp/query_test.go index ef7108efcc3d8..5bd2e2cce69b0 100644 --- a/pkg/loghttp/query_test.go +++ b/pkg/loghttp/query_test.go @@ -169,14 +169,14 @@ 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", Labels: LabelSet{"foo": "a", "bar": "b"}.String()}, + {Timestamp: time.Unix(0, 2), Line: "2", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}.String()}, }, }, { Labels: `{foo="bar", lvl="error"}`, Entries: []logproto.Entry{ {Timestamp: time.Unix(0, 3), Line: "3"}, - {Timestamp: time.Unix(0, 4), Line: "4", Labels: LabelSet{"foo": "a", "bar": "b"}.String()}, + {Timestamp: time.Unix(0, 4), Line: "4", NonIndexedLabels: LabelSet{"foo": "a", "bar": "b"}.String()}, }, }, }, diff --git a/pkg/util/marshal/legacy/marshal_test.go b/pkg/util/marshal/legacy/marshal_test.go index 1dd1d99337e45..eca3f6eab98c5 100644 --- a/pkg/util/marshal/legacy/marshal_test.go +++ b/pkg/util/marshal/legacy/marshal_test.go @@ -28,9 +28,9 @@ var queryTests = []struct { Line: "super line", }, { - Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), - Line: "super line with labels", - Labels: `{foo="a", bar="b"}`, + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + NonIndexedLabels: `{foo="a", bar="b"}`, }, }, Labels: `{test="test"}`, @@ -175,9 +175,9 @@ var tailTests = []struct { Line: "super line", }, { - Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), - Line: "super line with labels", - Labels: `{foo="a", bar="b"}`, + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + NonIndexedLabels: `{foo="a", bar="b"}`, }, }, Labels: "{test=\"test\"}", diff --git a/pkg/util/marshal/marshal_test.go b/pkg/util/marshal/marshal_test.go index 5787e3b4095f6..dae110927cbe4 100644 --- a/pkg/util/marshal/marshal_test.go +++ b/pkg/util/marshal/marshal_test.go @@ -35,9 +35,9 @@ var queryTests = []struct { Line: "super line", }, { - Timestamp: time.Unix(0, 123456789012346), - Line: "super line with labels", - Labels: `{foo="a", bar="b"}`, + Timestamp: time.Unix(0, 123456789012346), + Line: "super line with labels", + NonIndexedLabels: `{foo="a", bar="b"}`, }, }, Labels: `{test="test"}`, @@ -495,9 +495,9 @@ var tailTests = []struct { Line: "super line", }, { - Timestamp: time.Unix(0, 123456789012346), - Line: "super line with labels", - Labels: `{foo="a", bar="b"}`, + Timestamp: time.Unix(0, 123456789012346), + Line: "super line with labels", + NonIndexedLabels: `{foo="a", bar="b"}`, }, }, Labels: "{test=\"test\"}", diff --git a/pkg/util/marshal/query.go b/pkg/util/marshal/query.go index b0b30d388626e..a39d409588356 100644 --- a/pkg/util/marshal/query.go +++ b/pkg/util/marshal/query.go @@ -109,10 +109,10 @@ func NewStream(s logproto.Stream) (loghttp.Stream, error) { // NewEntry constructs an Entry from a logproto.Entry func NewEntry(e logproto.Entry) (loghttp.Entry, error) { var labels loghttp.LabelSet - if e.Labels != "" { - lbls, err := syntax.ParseLabels(e.Labels) + 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.Labels) + return loghttp.Entry{}, errors.Wrapf(err, "err while creating labelset for entry %s", e.NonIndexedLabels) } labels = lbls.Map() } @@ -329,10 +329,10 @@ func encodeStream(stream logproto.Stream, s *jsoniter.Stream) error { s.WriteRaw(`"`) s.WriteMore() s.WriteStringWithHTMLEscaped(e.Line) - if e.Labels != "" { + if e.NonIndexedLabels != "" { s.WriteMore() s.WriteObjectStart() - labels, err = parser.ParseMetric(e.Labels) + labels, err = parser.ParseMetric(e.NonIndexedLabels) if err != nil { return err } diff --git a/pkg/util/unmarshal/legacy/unmarshal_test.go b/pkg/util/unmarshal/legacy/unmarshal_test.go index feacfdbe8b441..691ac140786cd 100644 --- a/pkg/util/unmarshal/legacy/unmarshal_test.go +++ b/pkg/util/unmarshal/legacy/unmarshal_test.go @@ -26,9 +26,9 @@ var pushTests = []struct { Line: "super line", }, { - Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), - Line: "super line with labels", - Labels: `{foo="a", bar="b"}`, + Timestamp: mustParse(time.RFC3339Nano, "2019-09-13T18:32:23.380001319Z"), + Line: "super line with labels", + NonIndexedLabels: `{foo="a", bar="b"}`, }, }, Labels: `{test="test"}`, diff --git a/pkg/util/unmarshal/unmarshal_test.go b/pkg/util/unmarshal/unmarshal_test.go index 9fef987a8943d..86a4654f109ed 100644 --- a/pkg/util/unmarshal/unmarshal_test.go +++ b/pkg/util/unmarshal/unmarshal_test.go @@ -50,9 +50,9 @@ var pushTests = []struct { { Entries: []logproto.Entry{ { - Timestamp: time.Unix(0, 123456789012345), - Line: "super line", - Labels: `{a="1", b="2"}`, + Timestamp: time.Unix(0, 123456789012345), + Line: "super line", + NonIndexedLabels: `{a="1", b="2"}`, }, }, Labels: `{test="test"}`, From 40287588c7fb79c93e45d17e6ca4dedb69119d52 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 11 Jul 2023 14:09:11 +0200 Subject: [PATCH 29/36] 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 28d92b6b4dcf6..c76e26856c720 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 6f905029ab66e..566b2d68de9f3 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 5bd2e2cce69b0..fb0ab15604bbd 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 e99a33d3e7ada..d83e55f7a04cc 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 79849186a8efc..6fae3c1e7f735 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, 0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 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, 0xb6, 0x04, 0x0b, 0xad, 0x23, 0x9f, 0x72, + 0x00, 0x5b, 0x0a, 0x07, 0x2e, 0x5c, 0x62, 0x09, 0xa9, 0x48, 0x3d, 0x54, 0x06, 0x81, 0xc4, 0x6d, + 0x43, 0xb6, 0xb6, 0xa9, 0xed, 0x35, 0xde, 0x35, 0xa2, 0x37, 0x3e, 0xa1, 0xfc, 0x05, 0x9f, 0xd2, + 0x63, 0x8e, 0x15, 0x07, 0x43, 0x9c, 0x0b, 0xca, 0xa9, 0x9f, 0x80, 0xbc, 0xb6, 0x49, 0x09, 0x97, + 0xf5, 0x9b, 0xb7, 0x33, 0xf3, 0x9e, 0x67, 0x6c, 0x78, 0x90, 0x5e, 0xf8, 0x4e, 0x9a, 0x8b, 0x40, + 0x1d, 0x76, 0x9a, 0x71, 0xc9, 0xf1, 0x4e, 0xc4, 0x7d, 0x85, 0x8c, 0x43, 0x9f, 0xfb, 0x5c, 0x41, + 0xa7, 0x42, 0xf5, 0xbd, 0x61, 0xfa, 0x9c, 0xfb, 0x11, 0x73, 0x54, 0x34, 0xcd, 0xcf, 0x1d, 0x19, + 0xc6, 0x4c, 0x48, 0x1a, 0xa7, 0x75, 0x82, 0xf5, 0x0e, 0xfa, 0x67, 0xb9, 0x08, 0x3c, 0xf6, 0x29, + 0x67, 0x42, 0xe2, 0x13, 0xd8, 0x16, 0x32, 0x63, 0x34, 0x16, 0x03, 0x34, 0xec, 0x8e, 0xfa, 0xe3, + 0x87, 0x76, 0xab, 0x60, 0xbf, 0x56, 0x17, 0x93, 0x19, 0x4d, 0x25, 0xcb, 0xdc, 0xa3, 0x1f, 0x85, + 0xd9, 0xab, 0xa9, 0x55, 0x61, 0xb6, 0x55, 0x5e, 0x0b, 0xac, 0x7d, 0xd8, 0xab, 0x1b, 0x8b, 0x94, + 0x27, 0x82, 0x59, 0xdf, 0x10, 0xdc, 0xfb, 0xa7, 0x03, 0xb6, 0xa0, 0x17, 0xd1, 0x29, 0x8b, 0x2a, + 0x29, 0x34, 0xda, 0x75, 0x61, 0x55, 0x98, 0x0d, 0xe3, 0x35, 0x4f, 0x3c, 0x81, 0x6d, 0x96, 0xc8, + 0x2c, 0x64, 0x62, 0xd0, 0x51, 0x7e, 0x8e, 0xd7, 0x7e, 0x5e, 0x26, 0x32, 0xbb, 0x6c, 0xed, 0xdc, + 0xbf, 0x2e, 0x4c, 0xad, 0x32, 0xd2, 0xa4, 0x7b, 0x2d, 0xc0, 0x8f, 0x40, 0x0f, 0xa8, 0x08, 0x06, + 0xdd, 0x21, 0x1a, 0xe9, 0xee, 0xd6, 0xaa, 0x30, 0xd1, 0x53, 0x4f, 0x51, 0xd6, 0x0b, 0x38, 0x38, + 0xad, 0x74, 0xce, 0x68, 0x98, 0xb5, 0xae, 0x30, 0xe8, 0x09, 0x8d, 0x59, 0xed, 0xc9, 0x53, 0x18, + 0x1f, 0xc2, 0xd6, 0x67, 0x1a, 0xe5, 0x6c, 0xd0, 0x51, 0x64, 0x1d, 0x58, 0x25, 0x82, 0xbd, 0xbb, + 0x1e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x00, 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 49be9a2577267..1e0a3649bdb82 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 5c687d09738e6..836609aa4eef3 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 eca3f6eab98c5..0ae8bf60f2903 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 dae110927cbe4..40be7a7c472fe 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 a39d409588356..8930b879c6f20 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 691ac140786cd..5492b22fa683f 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 86a4654f109ed..4b1b67ead71b9 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 79849186a8efc..6fae3c1e7f735 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,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x6b, 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, 0xb6, 0x04, 0x0b, 0xad, 0x23, 0x9f, 0x72, + 0x00, 0x5b, 0x0a, 0x07, 0x2e, 0x5c, 0x62, 0x09, 0xa9, 0x48, 0x3d, 0x54, 0x06, 0x81, 0xc4, 0x6d, + 0x43, 0xb6, 0xb6, 0xa9, 0xed, 0x35, 0xde, 0x35, 0xa2, 0x37, 0x3e, 0xa1, 0xfc, 0x05, 0x9f, 0xd2, + 0x63, 0x8e, 0x15, 0x07, 0x43, 0x9c, 0x0b, 0xca, 0xa9, 0x9f, 0x80, 0xbc, 0xb6, 0x49, 0x09, 0x97, + 0xf5, 0x9b, 0xb7, 0x33, 0xf3, 0x9e, 0x67, 0x6c, 0x78, 0x90, 0x5e, 0xf8, 0x4e, 0x9a, 0x8b, 0x40, + 0x1d, 0x76, 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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 49be9a2577267..1e0a3649bdb82 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 5c687d09738e6..836609aa4eef3 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 From 8c76150ff80b3512088488076c1b5487bb1e6b81 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 11 Jul 2023 14:23:18 +0200 Subject: [PATCH 30/36] Fix format --- pkg/loghttp/query.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index 566b2d68de9f3..4d05a2bac76f3 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -7,15 +7,14 @@ import ( "time" "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" "github.com/prometheus/common/model" + "github.com/prometheus/prometheus/model/labels" "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/logqlmodel/stats" + "github.com/grafana/loki/pkg/storage/stores/index/seriesvolume" ) var ( From fb505b457b377974b7de551f7144781d4e7ef7ef Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Wed, 12 Jul 2023 11:32:24 +0200 Subject: [PATCH 31/36] Move LabelsAdapter to push pkg --- pkg/logproto/alias.go | 1 + pkg/logproto/timeseries.go | 201 ------------------ pkg/push/types.go | 48 ++--- .../github.com/grafana/loki/pkg/push/types.go | 48 ++--- 4 files changed, 43 insertions(+), 255 deletions(-) diff --git a/pkg/logproto/alias.go b/pkg/logproto/alias.go index 27b984bc31300..ab378fcbd0e81 100644 --- a/pkg/logproto/alias.go +++ b/pkg/logproto/alias.go @@ -10,6 +10,7 @@ import ( type Entry = push.Entry type Stream = push.Stream +type LabelAdapter = push.LabelAdapter type PushRequest = push.PushRequest type PushResponse = push.PushResponse type PusherClient = push.PusherClient diff --git a/pkg/logproto/timeseries.go b/pkg/logproto/timeseries.go index 2bf4ae15ae7a0..377b82bb81b29 100644 --- a/pkg/logproto/timeseries.go +++ b/pkg/logproto/timeseries.go @@ -2,13 +2,7 @@ package logproto import ( "flag" - "fmt" - "io" - "strings" "sync" - "unsafe" - - "github.com/prometheus/prometheus/model/labels" ) var ( @@ -70,201 +64,6 @@ func (p *PreallocTimeseries) Unmarshal(dAtA []byte) error { return p.TimeSeries.Unmarshal(dAtA) } -// LabelAdapter is a labels.Label that can be marshalled to/from protos. -type LabelAdapter labels.Label - -// Marshal implements proto.Marshaller. -func (bs *LabelAdapter) Marshal() ([]byte, error) { - size := bs.Size() - buf := make([]byte, size) - n, err := bs.MarshalToSizedBuffer(buf[:size]) - if err != nil { - return nil, err - } - return buf[:n], err -} - -func (bs *LabelAdapter) MarshalTo(dAtA []byte) (int, error) { - size := bs.Size() - return bs.MarshalToSizedBuffer(dAtA[:size]) -} - -// MarshalTo implements proto.Marshaller. -func (bs *LabelAdapter) MarshalToSizedBuffer(buf []byte) (n int, err error) { - ls := (*labels.Label)(bs) - i := len(buf) - if len(ls.Value) > 0 { - i -= len(ls.Value) - copy(buf[i:], ls.Value) - i = encodeVarintMetrics(buf, i, uint64(len(ls.Value))) - i-- - buf[i] = 0x12 - } - if len(ls.Name) > 0 { - i -= len(ls.Name) - copy(buf[i:], ls.Name) - i = encodeVarintMetrics(buf, i, uint64(len(ls.Name))) - i-- - buf[i] = 0xa - } - return len(buf) - i, nil -} - -// Unmarshal a LabelAdapter, implements proto.Unmarshaller. -// NB this is a copy of the autogenerated code to unmarshal a LabelPair, -// with the byte copying replaced with a yoloString. -func (bs *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 ErrIntOverflowMetrics - } - 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: LabelPair: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: LabelPair: 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 byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMetrics - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthMetrics - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthMetrics - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - bs.Name = yoloString(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMetrics - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthMetrics - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthMetrics - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - bs.Value = yoloString(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipMetrics(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthMetrics - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMetrics - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} - -func yoloString(buf []byte) string { - return *((*string)(unsafe.Pointer(&buf))) -} - -// Size implements proto.Sizer. -func (bs *LabelAdapter) Size() (n int) { - ls := (*labels.Label)(bs) - if bs == nil { - return 0 - } - var l int - _ = l - l = len(ls.Name) - if l > 0 { - n += 1 + l + sovMetrics(uint64(l)) - } - l = len(ls.Value) - if l > 0 { - n += 1 + l + sovMetrics(uint64(l)) - } - return n -} - -// Equal implements proto.Equaler. -func (bs *LabelAdapter) Equal(other LabelAdapter) bool { - return bs.Name == other.Name && bs.Value == other.Value -} - -// Compare implements proto.Comparer. -func (bs *LabelAdapter) Compare(other LabelAdapter) int { - if c := strings.Compare(bs.Name, other.Name); c != 0 { - return c - } - return strings.Compare(bs.Value, other.Value) -} - // PreallocTimeseriesSliceFromPool retrieves a slice of PreallocTimeseries from a sync.Pool. // ReuseSlice should be called once done. func PreallocTimeseriesSliceFromPool() []PreallocTimeseries { diff --git a/pkg/push/types.go b/pkg/push/types.go index 836609aa4eef3..dde8ff1ef1c64 100644 --- a/pkg/push/types.go +++ b/pkg/push/types.go @@ -3,7 +3,9 @@ package push import ( "fmt" "io" + "strings" "time" + "unsafe" "github.com/prometheus/prometheus/model/labels" ) @@ -456,6 +458,9 @@ func (m *Entry) Unmarshal(dAtA []byte) error { return nil } +// Unmarshal a LabelAdapter, implements proto.Unmarshaller. +// NB this is a copy of the autogenerated code to unmarshal a LabelPair, +// with the byte copying replaced with a yoloString. func (m *LabelAdapter) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -515,7 +520,7 @@ func (m *LabelAdapter) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Name = string(dAtA[iNdEx:postIndex]) + m.Name = yoloString(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { @@ -547,7 +552,7 @@ func (m *LabelAdapter) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Value = string(dAtA[iNdEx:postIndex]) + m.Value = yoloString(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -574,6 +579,10 @@ func (m *LabelAdapter) Unmarshal(dAtA []byte) error { return nil } +func yoloString(buf []byte) string { + return *((*string)(unsafe.Pointer(&buf))) +} + func (m *Stream) Size() (n int) { if m == nil { return 0 @@ -693,37 +702,22 @@ func (m *Entry) Equal(that interface{}) bool { return false } for i := range m.NonIndexedLabels { - if !(*LabelAdapter)(&m.NonIndexedLabels[i]).Equal(&that1.NonIndexedLabels[i]) { + if !(*LabelAdapter)(&m.NonIndexedLabels[i]).Equal(LabelAdapter(that1.NonIndexedLabels[i])) { return false } } return true } -func (m *LabelAdapter) Equal(that interface{}) bool { - if that == nil { - return m == nil - } +// Equal implements proto.Equaler. +func (m *LabelAdapter) Equal(other LabelAdapter) bool { + return m.Name == other.Name && m.Value == other.Value +} - 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 +// Compare implements proto.Comparer. +func (m *LabelAdapter) Compare(other LabelAdapter) int { + if c := strings.Compare(m.Name, other.Name); c != 0 { + return c } - if m.Name != that1.Name { - return false - } - if m.Value != that1.Value { - return false - } - return true + return strings.Compare(m.Value, other.Value) } diff --git a/vendor/github.com/grafana/loki/pkg/push/types.go b/vendor/github.com/grafana/loki/pkg/push/types.go index 836609aa4eef3..dde8ff1ef1c64 100644 --- a/vendor/github.com/grafana/loki/pkg/push/types.go +++ b/vendor/github.com/grafana/loki/pkg/push/types.go @@ -3,7 +3,9 @@ package push import ( "fmt" "io" + "strings" "time" + "unsafe" "github.com/prometheus/prometheus/model/labels" ) @@ -456,6 +458,9 @@ func (m *Entry) Unmarshal(dAtA []byte) error { return nil } +// Unmarshal a LabelAdapter, implements proto.Unmarshaller. +// NB this is a copy of the autogenerated code to unmarshal a LabelPair, +// with the byte copying replaced with a yoloString. func (m *LabelAdapter) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -515,7 +520,7 @@ func (m *LabelAdapter) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Name = string(dAtA[iNdEx:postIndex]) + m.Name = yoloString(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { @@ -547,7 +552,7 @@ func (m *LabelAdapter) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Value = string(dAtA[iNdEx:postIndex]) + m.Value = yoloString(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -574,6 +579,10 @@ func (m *LabelAdapter) Unmarshal(dAtA []byte) error { return nil } +func yoloString(buf []byte) string { + return *((*string)(unsafe.Pointer(&buf))) +} + func (m *Stream) Size() (n int) { if m == nil { return 0 @@ -693,37 +702,22 @@ func (m *Entry) Equal(that interface{}) bool { return false } for i := range m.NonIndexedLabels { - if !(*LabelAdapter)(&m.NonIndexedLabels[i]).Equal(&that1.NonIndexedLabels[i]) { + if !(*LabelAdapter)(&m.NonIndexedLabels[i]).Equal(LabelAdapter(that1.NonIndexedLabels[i])) { return false } } return true } -func (m *LabelAdapter) Equal(that interface{}) bool { - if that == nil { - return m == nil - } +// Equal implements proto.Equaler. +func (m *LabelAdapter) Equal(other LabelAdapter) bool { + return m.Name == other.Name && m.Value == other.Value +} - 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 +// Compare implements proto.Comparer. +func (m *LabelAdapter) Compare(other LabelAdapter) int { + if c := strings.Compare(m.Name, other.Name); c != 0 { + return c } - if m.Name != that1.Name { - return false - } - if m.Value != that1.Value { - return false - } - return true + return strings.Compare(m.Value, other.Value) } From ccaf1922751f82c414f58a96960a970605a9bcc9 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Wed, 12 Jul 2023 11:58:58 +0200 Subject: [PATCH 32/36] Use same prometheus version in push pkg --- pkg/push/go.mod | 24 ++++++++++++++---------- pkg/push/go.sum | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/pkg/push/go.mod b/pkg/push/go.mod index d83e55f7a04cc..cf928c3a58cac 100644 --- a/pkg/push/go.mod +++ b/pkg/push/go.mod @@ -4,21 +4,25 @@ 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 + github.com/prometheus/prometheus v0.43.1-0.20230419161410-69155c6ba1e9 + github.com/stretchr/testify v1.8.2 + google.golang.org/grpc v1.53.0 ) require ( + github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang/protobuf v1.5.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect + github.com/kr/pretty v0.2.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect - google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect - google.golang.org/protobuf v1.28.1 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + github.com/prometheus/common v0.42.0 // indirect + golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect + golang.org/x/net v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect + google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect + google.golang.org/protobuf v1.29.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/pkg/push/go.sum b/pkg/push/go.sum index c13553cd3727e..06bf170f66191 100644 --- a/pkg/push/go.sum +++ b/pkg/push/go.sum @@ -1,3 +1,5 @@ +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -5,10 +7,12 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd h1:PpuIBO5P3e9hpqBD0O/HjhShYuM6XE0i/lbE6J94kww= +github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= @@ -19,38 +23,44 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= +github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= +github.com/prometheus/prometheus v0.43.1-0.20230419161410-69155c6ba1e9 h1:GrpznPCSJgx8mGGj5qfKoHiou/dVx7uMce9/9rSdiuY= +github.com/prometheus/prometheus v0.43.1-0.20230419161410-69155c6ba1e9/go.mod h1:L8xLODXgpZM57D1MA7SPgsDecKj6ez4AF7mMczR1bis= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20230307190834-24139beb5833 h1:SChBja7BCQewoTAU7IgvucQKMIXrEpFxNMs0spT3/5s= +golang.org/x/exp v0.0.0-20230307190834-24139beb5833/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -59,17 +69,17 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 h1:a2S6M0+660BgMNl++4JPlcAO/CjkqYItDEZwkoDQK7c= -google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= -google.golang.org/grpc v1.52.0 h1:kd48UiU7EHsV4rnLyOJRuP/Il/UHE7gdDAQ+SZI7nZk= -google.golang.org/grpc v1.52.0/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY= +google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 h1:DdoeryqhaXp1LtT/emMP1BRJPHHKFi5akj/nbx/zNTA= +google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s= +google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= +google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.29.1 h1:7QBf+IK2gx70Ap/hDsOmam3GE0v9HicjfEdAxE62UoM= +google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From eaf235c0cc4a53e3ad301598a6ad4d45579c3565 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Wed, 12 Jul 2023 13:10:27 +0200 Subject: [PATCH 33/36] Update vendor/github.com/grafana/loki/pkg/push/types.go Co-authored-by: Sandeep Sukhani --- vendor/github.com/grafana/loki/pkg/push/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/github.com/grafana/loki/pkg/push/types.go b/vendor/github.com/grafana/loki/pkg/push/types.go index dde8ff1ef1c64..80adf2563c582 100644 --- a/vendor/github.com/grafana/loki/pkg/push/types.go +++ b/vendor/github.com/grafana/loki/pkg/push/types.go @@ -23,7 +23,7 @@ type Stream struct { 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 labels.Labels `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` + NonIndexedLabels labels.Labels `protobuf:"bytes,3,opt,name=nonIndexedLabels,proto3" json:"nonIndexedLabels,omitempty"` } type LabelAdapter labels.Label From 7438809390c221a17870b93e94c1fff5d6ba54a4 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Wed, 12 Jul 2023 14:05:04 +0200 Subject: [PATCH 34/36] Fix tests --- pkg/push/types.go | 2 +- pkg/util/marshal/legacy/marshal_test.go | 4 ++-- pkg/util/unmarshal/legacy/unmarshal_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/push/types.go b/pkg/push/types.go index dde8ff1ef1c64..80adf2563c582 100644 --- a/pkg/push/types.go +++ b/pkg/push/types.go @@ -23,7 +23,7 @@ type Stream struct { 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 labels.Labels `protobuf:"bytes,3,opt,name=labels,proto3" json:"labels,omitempty"` + NonIndexedLabels labels.Labels `protobuf:"bytes,3,opt,name=nonIndexedLabels,proto3" json:"nonIndexedLabels,omitempty"` } type LabelAdapter labels.Label diff --git a/pkg/util/marshal/legacy/marshal_test.go b/pkg/util/marshal/legacy/marshal_test.go index 0ae8bf60f2903..b3a141a09e6df 100644 --- a/pkg/util/marshal/legacy/marshal_test.go +++ b/pkg/util/marshal/legacy/marshal_test.go @@ -52,7 +52,7 @@ var queryTests = []struct { { "ts": "2019-09-13T18:32:23.380001319Z", "line": "super line with labels", - "labels": { + "nonIndexedLabels": { "foo": "a", "bar": "b" } @@ -212,7 +212,7 @@ var tailTests = []struct { { "ts": "2019-09-13T18:32:23.380001319Z", "line": "super line with labels", - "labels": { + "nonIndexedLabels": { "foo": "a", "bar": "b" } diff --git a/pkg/util/unmarshal/legacy/unmarshal_test.go b/pkg/util/unmarshal/legacy/unmarshal_test.go index 5492b22fa683f..92365bb91125b 100644 --- a/pkg/util/unmarshal/legacy/unmarshal_test.go +++ b/pkg/util/unmarshal/legacy/unmarshal_test.go @@ -50,7 +50,7 @@ var pushTests = []struct { { "ts": "2019-09-13T18:32:23.380001319Z", "line": "super line with labels", - "labels": { + "nonIndexedLabels": { "a": "1", "b": "2" } From f6e6918cb393dbd391935e63cecb78438eb5bd1d Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Wed, 12 Jul 2023 16:13:52 +0200 Subject: [PATCH 35/36] Don't use yolostring when deserializing push request --- pkg/loghttp/query.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/loghttp/query.go b/pkg/loghttp/query.go index 7a89052d68755..bcd6b02249ea6 100644 --- a/pkg/loghttp/query.go +++ b/pkg/loghttp/query.go @@ -75,7 +75,7 @@ func (s *LogProtoStream) UnmarshalJSON(data []byte) error { if dataType != jsonparser.String { return jsonparser.MalformedStringError } - labels[yoloString(key)] = yoloString(val) + labels[string(key)] = string(val) return nil }) if err != nil { @@ -163,8 +163,8 @@ func unmarshalHTTPToLogProtoEntry(data []byte) (logproto.Entry, error) { return jsonparser.MalformedStringError } nonIndexedLabels = append(nonIndexedLabels, labels.Label{ - Name: yoloString(key), - Value: yoloString(val), + Name: string(key), + Value: string(val), }) return nil }) @@ -561,7 +561,3 @@ func labelVolumeLimit(r *http.Request) error { return nil } - -func yoloString(buf []byte) string { - return *((*string)(unsafe.Pointer(&buf))) -} From f8c33aaf31eb5c421eed799c380ee4214aebca54 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Thu, 13 Jul 2023 08:46:37 +0200 Subject: [PATCH 36/36] Remove yolostring --- pkg/loghttp/entry.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/loghttp/entry.go b/pkg/loghttp/entry.go index c76e26856c720..f91db035b5b1c 100644 --- a/pkg/loghttp/entry.go +++ b/pkg/loghttp/entry.go @@ -63,8 +63,8 @@ func (e *Entry) UnmarshalJSON(data []byte) error { return jsonparser.MalformedStringError } nonIndexedLabels = append(nonIndexedLabels, labels.Label{ - Name: yoloString(key), - Value: yoloString(value), + Name: string(key), + Value: string(value), }) return nil }); err != nil {