Skip to content

Commit b3ba50f

Browse files
committed
partition
1 parent e266fea commit b3ba50f

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

libbeat/outputs/kafka/partition.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func initPartitionStrategy(
7777
}
7878

7979
if len(partition) > 1 {
80-
return nil, false, errors.New("Too many partitioners")
80+
return nil, false, errors.New("too many partitioners")
8181
}
8282

8383
// extract partitioner from config
@@ -273,7 +273,7 @@ func makeFieldsHashPartitioner(log *logp.Logger, fields []string, dropFail bool)
273273
}
274274

275275
func Hash2Partition(hash uint32, numPartitions int32) int32 {
276-
p := int32(hash) & 0x7FFFFFFF
276+
p := int32(hash) & 0x7FFFFFFF //nolint:gosec // Conversion from int to int32 is safe here.
277277
return p % numPartitions
278278
}
279279

x-pack/otel/extension/kafkapartitionerextension/extension.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"go.opentelemetry.io/collector/component"
1414
"go.opentelemetry.io/collector/extension"
1515
"go.uber.org/zap"
16-
"go.uber.org/zap/zapcore"
1716

1817
"github.com/elastic/elastic-agent-libs/logp"
1918
)
@@ -28,9 +27,11 @@ type kafkaPartitioner struct {
2827
}
2928

3029
func (k *kafkaPartitioner) Start(context.Context, component.Host) error {
31-
partitioner, err := makePartitioner(logp.NewLogger("", zap.WrapCore(func(zapcore.Core) zapcore.Core {
32-
return k.logger.Core()
33-
})), k.cfg.PartitionerConfig)
30+
logger, err := logp.NewZapLogger(k.logger)
31+
if err != nil {
32+
return fmt.Errorf("error creating logger: %w", err)
33+
}
34+
partitioner, err := makePartitioner(logger, k.cfg.PartitionerConfig)
3435
if err != nil {
3536
return fmt.Errorf("error configuring the partitioner: %w", err)
3637
}

x-pack/otel/extension/kafkapartitionerextension/partitioner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func makeHashKgoPartitioner() kgo.Partitioner {
156156
hasher.Reset()
157157
_, _ = hasher.Write(msg.Key)
158158

159-
return int(kafka.Hash2Partition(rand.Uint32(), int32(numPartitions)))
159+
return int(kafka.Hash2Partition(rand.Uint32(), int32(numPartitions))) //nolint:gosec // Conversion from int to int32 is safe here.
160160
}
161161
})
162162
}
@@ -176,7 +176,7 @@ func makeFieldsHashPartitioner(
176176
if dropFail {
177177
return -1
178178
}
179-
return int(kafka.Hash2Partition(rand.Uint32(), int32(numPartitions)))
179+
return int(kafka.Hash2Partition(rand.Uint32(), int32(numPartitions))) //nolint:gosec // Conversion from int to int32 is safe here.
180180
}
181181

182182
hasher.Reset()
@@ -197,7 +197,7 @@ func makeFieldsHashPartitioner(
197197
hash = hasher.Sum32()
198198
}
199199

200-
return int(kafka.Hash2Partition(hash, int32(numPartitions)))
200+
return int(kafka.Hash2Partition(hash, int32(numPartitions))) //nolint:gosec // Conversion from int to int32 is safe here.
201201
}
202202
}
203203

0 commit comments

Comments
 (0)