mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
The concurrency of this library is easier to handle than Sarama. Notably, it is more compatible with the new model of "almost share nothing" we use for the inlet and the outlet. The lock for workers in outlet is removed. We can now use sync.Pool to allocate slice of bytes in inlet. It may also be more performant. In the future, we may want to commit only when pushing data to ClickHouse. However, this does not seem easy when there is a rebalance. In case of rebalance, we need to do something when a partition is revoked to avoid duplicating data. For example, we could flush the current batch to ClickHouse. Have a look at the `example/mark_offsets/main.go` file in franz-go repository for a possible approach. In the meantime, we rely on autocommit. Another contender could be https://github.com/segmentio/kafka-go. Also see https://github.com/twmb/franz-go/pull/1064.
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
// SPDX-FileCopyrightText: 2025 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package kafka
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"net/http"
|
|
|
|
"github.com/twmb/franz-go/pkg/sasl/oauth"
|
|
"golang.org/x/oauth2"
|
|
"golang.org/x/oauth2/clientcredentials"
|
|
)
|
|
|
|
// tokenProvider implements OAuth token provider for franz-go.
|
|
type tokenProvider struct {
|
|
tokenSource oauth2.TokenSource
|
|
}
|
|
|
|
// newOAuthTokenProvider returns a token provider function using OAuth credentials.
|
|
func newOAuthTokenProvider(tlsConfig *tls.Config, oauthConfig clientcredentials.Config) func(context.Context) (oauth.Auth, error) {
|
|
return func(ctx context.Context) (oauth.Auth, error) {
|
|
httpClient := &http.Client{Transport: &http.Transport{
|
|
Proxy: http.ProxyFromEnvironment,
|
|
TLSClientConfig: tlsConfig,
|
|
}}
|
|
ctx = context.WithValue(ctx, oauth2.HTTPClient, httpClient)
|
|
tokenSource := oauthConfig.TokenSource(ctx)
|
|
token, err := tokenSource.Token()
|
|
if err != nil {
|
|
return oauth.Auth{}, err
|
|
}
|
|
return oauth.Auth{Token: token.AccessToken}, nil
|
|
}
|
|
}
|