MCPcopy
hub / github.com/grafana/tempo / NewReaderClient

Function NewReaderClient

pkg/ingest/reader_client.go:19–42  ·  view source on GitHub ↗

NewReaderClient returns the kgo.Client that should be used by the Reader.

(kafkaCfg KafkaConfig, metrics *kprom.Metrics, logger log.Logger, opts ...kgo.Opt)

Source from the content-addressed store, hash-verified

17
18// NewReaderClient returns the kgo.Client that should be used by the Reader.
19func NewReaderClient(kafkaCfg KafkaConfig, metrics *kprom.Metrics, logger log.Logger, opts ...kgo.Opt) (*kgo.Client, error) {
20 const fetchMaxBytes = 100_000_000
21
22 opts = append(opts, commonKafkaClientOptions(kafkaCfg, metrics, logger)...)
23 opts = append(opts,
24 kgo.FetchMinBytes(1),
25 kgo.FetchMaxBytes(fetchMaxBytes),
26 kgo.FetchMaxWait(5*time.Second),
27 kgo.FetchMaxPartitionBytes(50_000_000),
28
29 // BrokerMaxReadBytes sets the maximum response size that can be read from
30 // Kafka. This is a safety measure to avoid OOMing on invalid responses.
31 // franz-go recommendation is to set it 2x FetchMaxBytes.
32 kgo.BrokerMaxReadBytes(2*fetchMaxBytes),
33 )
34 client, err := kgo.NewClient(opts...)
35 if err != nil {
36 return nil, errors.Wrap(err, "creating kafka client")
37 }
38 if kafkaCfg.AutoCreateTopicEnabled {
39 kafkaCfg.SetDefaultNumberOfPartitionsForAutocreatedTopics(logger)
40 }
41 return client, nil
42}
43
44type Client struct {
45 logger log.Logger

Calls 3

commonKafkaClientOptionsFunction · 0.85
WrapMethod · 0.65