Skip to content

kafkaexporter: Opt-in to use franz-go client #40364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

marclop
Copy link
Contributor

@marclop marclop commented May 29, 2025

Description

Adds the option to use the franz-go client in the kafkaexporter. The
main rationale for this change is to allow users to opt-in to use a
more performant Kafka client, as the default Sarama client has been
known to have performance issues in high-throughput scenarios.

The change should be backward compatible, and significantly increases
the production performance of the kafkaexporter when in use.

$ benchstat sarama.txt franz-go.txt
goos: darwin
goarch: arm64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter
cpu: Apple M2 Pro
           │ sarama.txt  │             franz-go.txt             │
           │   sec/op    │    sec/op     vs base                │
Logs-12      55.56µ ± 5%   33.40µ ±  4%  -39.88% (p=0.000 n=10)
Metrics-12   60.69µ ± 6%   39.34µ ± 17%  -35.18% (p=0.001 n=10)
Traces-12    57.09µ ± 9%   35.71µ ± 13%  -37.44% (p=0.000 n=10)
geomean      57.74µ        36.07µ        -37.53%

           │  sarama.txt  │             franz-go.txt              │
           │     B/op     │     B/op       vs base                │
Logs-12      5.792Ki ± 0%   2.207Ki ±  1%  -61.90% (p=0.000 n=10)
Metrics-12   9.545Ki ± 0%   4.339Ki ± 16%  -54.54% (p=0.000 n=10)
Traces-12    7.329Ki ± 0%   2.967Ki ±  5%  -59.52% (p=0.000 n=10)
geomean      7.400Ki        3.051Ki        -58.76%

           │ sarama.txt │            franz-go.txt            │
           │ allocs/op  │ allocs/op   vs base                │
Logs-12      55.00 ± 0%   29.00 ± 0%  -47.27% (p=0.000 n=10)
Metrics-12   58.00 ± 0%   32.00 ± 0%  -44.83% (p=0.000 n=10)
Traces-12    55.00 ± 0%   29.00 ± 0%  -47.27% (p=0.000 n=10)
geomean      55.98        29.97       -46.47%

Link to tracking issue

Improves the exporter's production performance.

Testing

Unit tested, benchmarked against a local Kafka broker.

Documentation

Updated the Readme.

marclop added 4 commits May 29, 2025 17:34
Adds the option to use the franz-go client in the `kafkaexporter`. The
main rationale for this change is to allow users to opt-in to use a
more performant Kafka client, as the default Sarama client has been
known to have performance issues in high-throughput scenarios.

The change _should_ be backward compatible, and significantly increases
the production performance of the `kafkaexporter` when in use.

```
$ benchstat sarama.txt franz-go.txt                                                                                                                                  <region:us-east-1>
goos: darwin
goarch: arm64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter
cpu: Apple M2 Pro
           │ sarama.txt  │             franz-go.txt             │
           │   sec/op    │    sec/op     vs base                │
Logs-12      55.56µ ± 5%   33.40µ ±  4%  -39.88% (p=0.000 n=10)
Metrics-12   60.69µ ± 6%   39.34µ ± 17%  -35.18% (p=0.001 n=10)
Traces-12    57.09µ ± 9%   35.71µ ± 13%  -37.44% (p=0.000 n=10)
geomean      57.74µ        36.07µ        -37.53%

           │  sarama.txt  │             franz-go.txt              │
           │     B/op     │     B/op       vs base                │
Logs-12      5.792Ki ± 0%   2.207Ki ±  1%  -61.90% (p=0.000 n=10)
Metrics-12   9.545Ki ± 0%   4.339Ki ± 16%  -54.54% (p=0.000 n=10)
Traces-12    7.329Ki ± 0%   2.967Ki ±  5%  -59.52% (p=0.000 n=10)
geomean      7.400Ki        3.051Ki        -58.76%

           │ sarama.txt │            franz-go.txt            │
           │ allocs/op  │ allocs/op   vs base                │
Logs-12      55.00 ± 0%   29.00 ± 0%  -47.27% (p=0.000 n=10)
Metrics-12   58.00 ± 0%   32.00 ± 0%  -44.83% (p=0.000 n=10)
Traces-12    55.00 ± 0%   29.00 ± 0%  -47.27% (p=0.000 n=10)
geomean      55.98        29.97       -46.47%
```

Signed-off-by: Marc Lopez Rubio <[email protected]>
Signed-off-by: Marc Lopez Rubio <[email protected]>
marclop added 2 commits May 29, 2025 18:18
Signed-off-by: Marc Lopez Rubio <[email protected]>
Signed-off-by: Marc Lopez Rubio <[email protected]>
var errs []error
for _, r := range result {
if r.Err != nil {
fmt.Println(r.Err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid calling fmt.Println since it doesn't adhere to the logging configuration set, you must use the provided logger within the collector defined constructors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I was doing some debugging earlier and forgot to remove it, thanks for the callout

Comment on lines +14 to +17
goleak:
ignore:
top:
- github.com/twmb/franz-go/pkg/kfake.(*group).manage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bug in kfake. I think we could work around it by deleting the consumer groups prior to shutting down the kfake cluster, but this seems OK. Should we open an issue against franz-go?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking with @axw there is still a few things that is to be ironed out, so I'll come back once the PR is ready.

My advice for preparing to adopt a new client is:

  • Make it easy to review by separating out changes into their own files
    • Also provides the ability to exclude them in builds if that is helpful with go build tags
    • It also makes it easier to remove the older files once ready
  • Use the feature gate for this type of change since we are planning for it to be a one way door since there is an advantage in moving.
    • It also gives users the ability to find where to reach out to on a github issue if things have gone wrong.

Signed-off-by: Marc Lopez Rubio <[email protected]>
@marclop marclop changed the title F/add kafkaexporter franz go client kafkaexporter: Opt-in to use franz-go client May 30, 2025
marclop added 2 commits May 30, 2025 17:54
Signed-off-by: Marc Lopez Rubio <[email protected]>
Signed-off-by: Marc Lopez Rubio <[email protected]>
@marclop marclop requested review from axw and MovieStoreGuy June 2, 2025 03:27
@marclop marclop marked this pull request as ready for review June 2, 2025 03:35
@marclop marclop requested a review from a team as a code owner June 2, 2025 03:35
@marclop
Copy link
Contributor Author

marclop commented Jun 2, 2025

I can address conflicts once the PR is approved

Copy link
Contributor

@MovieStoreGuy MovieStoreGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks great for me, @axw has already called out some work but I am not sure if it is blocking.

Comment on lines +44 to +46
makeHeader func(key string, value []byte) H,
getHeaders func(M) []H,
setHeadersFunc func(M, []H),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway around needing to pass callback functions here?

Copy link
Contributor Author

@marclop marclop Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can refactor this once we permanently remove Sarama to not have this abstraction.

Currently, this ensures the same logic is applied for both adapters. I don't love it but it seems like the best approach to apply this generic flow consistently.

Copy link
Contributor

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. I have some more minor questions/suggestions, otherwise LGTM

Copy link
Contributor

@axw axw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@MovieStoreGuy MovieStoreGuy merged commit 7a9a390 into open-telemetry:main Jun 4, 2025
177 checks passed
@github-actions github-actions bot added this to the next release milestone Jun 4, 2025
@marclop marclop deleted the f/add-kafkaexporter-franz-go-client branch June 4, 2025 03:36
dd-jasminesun pushed a commit to DataDog/opentelemetry-collector-contrib that referenced this pull request Jun 23, 2025
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Adds the option to use the franz-go client in the `kafkaexporter`. The
main rationale for this change is to allow users to opt-in to use a
more performant Kafka client, as the default Sarama client has been
known to have performance issues in high-throughput scenarios.

The change _should_ be backward compatible, and significantly increases
the production performance of the `kafkaexporter` when in use.

```
$ benchstat sarama.txt franz-go.txt
goos: darwin
goarch: arm64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kafkaexporter
cpu: Apple M2 Pro
           │ sarama.txt  │             franz-go.txt             │
           │   sec/op    │    sec/op     vs base                │
Logs-12      55.56µ ± 5%   33.40µ ±  4%  -39.88% (p=0.000 n=10)
Metrics-12   60.69µ ± 6%   39.34µ ± 17%  -35.18% (p=0.001 n=10)
Traces-12    57.09µ ± 9%   35.71µ ± 13%  -37.44% (p=0.000 n=10)
geomean      57.74µ        36.07µ        -37.53%

           │  sarama.txt  │             franz-go.txt              │
           │     B/op     │     B/op       vs base                │
Logs-12      5.792Ki ± 0%   2.207Ki ±  1%  -61.90% (p=0.000 n=10)
Metrics-12   9.545Ki ± 0%   4.339Ki ± 16%  -54.54% (p=0.000 n=10)
Traces-12    7.329Ki ± 0%   2.967Ki ±  5%  -59.52% (p=0.000 n=10)
geomean      7.400Ki        3.051Ki        -58.76%

           │ sarama.txt │            franz-go.txt            │
           │ allocs/op  │ allocs/op   vs base                │
Logs-12      55.00 ± 0%   29.00 ± 0%  -47.27% (p=0.000 n=10)
Metrics-12   58.00 ± 0%   32.00 ± 0%  -44.83% (p=0.000 n=10)
Traces-12    55.00 ± 0%   29.00 ± 0%  -47.27% (p=0.000 n=10)
geomean      55.98        29.97       -46.47%
```

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Improves the exporter's production performance.

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Unit tested, benchmarked against a local Kafka broker.

<!--Describe the documentation added.-->
#### Documentation

Updated the Readme.

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Signed-off-by: Marc Lopez Rubio <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants