createClient creates a Kafka client based on the provided Kafka configuration.
()
| 103 | |
| 104 | // createClient creates a Kafka client based on the provided Kafka configuration. |
| 105 | func (f *CachedClientProvider) createClient() (*kgo.Client, error) { |
| 106 | kgoOpts, err := NewKgoConfig(f.cfg.Kafka, f.logger, f.cfg.MetricsNamespace, f.registry) |
| 107 | if err != nil { |
| 108 | return nil, apierrors.NewConnectError( |
| 109 | connect.CodeInternal, |
| 110 | fmt.Errorf("failed to build Kafka config: %w", err), |
| 111 | apierrors.NewErrorInfo(commonv1alpha1.Reason_REASON_SERVER_ERROR.String()), |
| 112 | ) |
| 113 | } |
| 114 | |
| 115 | kgoClient, err := kgo.NewClient(kgoOpts...) |
| 116 | if err != nil { |
| 117 | return nil, err |
| 118 | } |
| 119 | |
| 120 | // Track client creation with factory metrics |
| 121 | f.factoryMetrics.IncrementActiveClients() |
| 122 | |
| 123 | return kgoClient, nil |
| 124 | } |
| 125 | |
| 126 | // NewKgoConfig creates a new Config for the Kafka Client as exposed by the franz-go library. |
| 127 | // If TLS certificates can't be read an error will be returned. |
no test coverage detected