@@ -5,10 +5,8 @@ import (
55 "errors"
66 "fmt"
77 "io"
8- "strconv"
98 "sync"
109 "time"
11- "unicode/utf8"
1210
1311 "github.com/coder/quartz"
1412 "github.com/go-kit/log"
@@ -24,6 +22,7 @@ import (
2422 "github.com/grafana/loki/v3/pkg/dataobj/metastore/multitenancy"
2523 "github.com/grafana/loki/v3/pkg/dataobj/uploader"
2624 "github.com/grafana/loki/v3/pkg/kafka"
25+ "github.com/grafana/loki/v3/pkg/kafka/partition"
2726 "github.com/grafana/loki/v3/pkg/logproto"
2827 "github.com/grafana/loki/v3/pkg/scratch"
2928)
@@ -39,7 +38,7 @@ type builder interface {
3938
4039// committer allows mocking of certain [kgo.Client] methods in tests.
4140type committer interface {
42- CommitRecords (ctx context.Context , records ... * kgo. Record ) error
41+ Commit (ctx context.Context , offset int64 ) error
4342}
4443
4544type producer interface {
@@ -52,10 +51,10 @@ type partitionProcessor struct {
5251 topic string
5352 partition int32
5453 // Processing pipeline
55- records chan * kgo .Record
54+ records chan partition .Record
5655 // lastRecord contains the last record appended to the builder. It is used
5756 // to commit the correct offset after a flush.
58- lastRecord * kgo .Record
57+ lastRecord * partition .Record
5958 builder builder
6059 decoder * kafka.Decoder
6160 uploader * uploader.Uploader
@@ -94,14 +93,12 @@ type partitionProcessor struct {
9493
9594func newPartitionProcessor (
9695 ctx context.Context ,
97- client * kgo. Client ,
96+ committer committer ,
9897 builderCfg logsobj.BuilderConfig ,
9998 uploaderCfg uploader.Config ,
10099 metastoreCfg metastore.Config ,
101100 bucket objstore.Bucket ,
102101 scratchStore scratch.Store ,
103- topic string ,
104- partition int32 ,
105102 logger log.Logger ,
106103 reg prometheus.Registerer ,
107104 idleFlushTimeout time.Duration ,
@@ -112,10 +109,10 @@ func newPartitionProcessor(
112109 if err != nil {
113110 panic (err )
114111 }
115- reg = prometheus .WrapRegistererWith (prometheus.Labels {
116- "topic" : topic ,
117- "partition" : strconv .Itoa (int (partition )),
118- }, reg )
112+ // reg = prometheus.WrapRegistererWith(prometheus.Labels{
113+ // "topic": topic,
114+ // "partition": strconv.Itoa(int(partition)),
115+ // }, reg)
119116
120117 metrics := newPartitionOffsetMetrics ()
121118 if err := metrics .register (reg ); err != nil {
@@ -128,11 +125,9 @@ func newPartitionProcessor(
128125 }
129126
130127 return & partitionProcessor {
131- committer : client ,
132- logger : log .With (logger , "partition" , partition ),
133- topic : topic ,
134- partition : partition ,
135- records : make (chan * kgo.Record , 1000 ),
128+ committer : committer ,
129+ logger : logger ,
130+ records : make (chan partition.Record , 1000 ),
136131 ctx : ctx ,
137132 cancel : cancel ,
138133 decoder : decoder ,
@@ -188,7 +183,7 @@ func (p *partitionProcessor) stop() {
188183
189184// Drops records from the channel if the processor is stopped.
190185// Returns false if the processor is stopped, true otherwise.
191- func (p * partitionProcessor ) Append (records []* kgo .Record ) bool {
186+ func (p * partitionProcessor ) Append (records []partition .Record ) bool {
192187 for _ , record := range records {
193188 select {
194189 // must check per-record in order to not block on a full channel
@@ -241,7 +236,7 @@ func (p *partitionProcessor) emitObjectWrittenEvent(objectPath string) error {
241236 return results .FirstErr ()
242237}
243238
244- func (p * partitionProcessor ) processRecord (record * kgo .Record ) {
239+ func (p * partitionProcessor ) processRecord (record partition .Record ) {
245240 // Update offset metric at the end of processing
246241 defer p .metrics .updateOffset (record .Offset )
247242
@@ -254,14 +249,8 @@ func (p *partitionProcessor) processRecord(record *kgo.Record) {
254249 return
255250 }
256251
257- tenant := string (record .Key )
258- if ! utf8 .ValidString (tenant ) {
259- // This shouldn't happen, but we catch it here.
260- level .Error (p .logger ).Log ("msg" , "record key is not valid UTF-8" )
261- return
262- }
263-
264- stream , err := p .decoder .DecodeWithoutLabels (record .Value )
252+ tenant := record .TenantID
253+ stream , err := p .decoder .DecodeWithoutLabels (record .Content )
265254 if err != nil {
266255 level .Error (p .logger ).Log ("msg" , "failed to decode record" , "err" , err )
267256 return
@@ -287,7 +276,7 @@ func (p *partitionProcessor) processRecord(record *kgo.Record) {
287276 }
288277 }
289278
290- p .lastRecord = record
279+ p .lastRecord = & record
291280 p .lastModified = p .clock .Now ()
292281}
293282
@@ -349,7 +338,7 @@ func (p *partitionProcessor) commit() error {
349338 backoff .Reset ()
350339 for backoff .Ongoing () {
351340 p .metrics .incCommitsTotal ()
352- err := p .committer .CommitRecords (p .ctx , p .lastRecord )
341+ err := p .committer .Commit (p .ctx , p .lastRecord . Offset )
353342 if err == nil {
354343 return nil
355344 }
0 commit comments