Skip to content

make kafka config global variable#49347

Merged
khushijain21 merged 4 commits intoelastic:mainfrom
khushijain21:kafka-output
Mar 10, 2026
Merged

make kafka config global variable#49347
khushijain21 merged 4 commits intoelastic:mainfrom
khushijain21:kafka-output

Conversation

@khushijain21
Copy link
Copy Markdown
Contributor

@khushijain21 khushijain21 commented Mar 9, 2026

Proposed commit message

This PR makes kafka config a global parameter - this is required for kafka output translation to kafka exporter

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 9, 2026

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @khushijain21? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

CI failure is from golangci-lint in lint (ubuntu-latest) for workflow run 22849321678; the failing step is golangci-lint in job 66273610042.

Root cause (from lint (ubuntu-latest)/5_golangci-lint.txt):

  • libbeat/outputs/kafka/config.go:245G115 (uint -> int conversion)
  • libbeat/outputs/kafka/config.go:273G115 (int -> int16 conversion)
  • libbeat/outputs/kafka/config.go:340G115 (int64 -> uint64 conversion)
  • libbeat/outputs/kafka/config.go:179QF1001 (De Morgan simplification)
  • libbeat/outputs/kafka/config.go:278ST1005 (capitalized error string)
  • libbeat/outputs/kafka/config.go:307ST1005 (capitalized error string)

Recommended minimal remediation:

  1. Replace risky numeric casts with explicit bounds checks before conversion (especially AuthType, RequiredACKs, and retry backoff math) so conversions are provably safe.
  2. Rewrite the condition at line ~179 to the De Morgan equivalent expected by staticcheck.
  3. Change error strings to lowercase (e.g., unknown compression mode..., unknown/unsupported kafka version...).
  4. Re-run golangci-lint locally for the touched package/file, then re-run CI.

Tests/checks run:

  • Inspected failed GitHub Actions run 22849321678 and job logs for 66273610042.
  • No additional local test commands were run in this investigation.

What is this? | From workflow: PR Actions Detective

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@khushijain21 khushijain21 marked this pull request as ready for review March 9, 2026 12:00
@khushijain21 khushijain21 requested a review from a team as a code owner March 9, 2026 12:00
@khushijain21
Copy link
Copy Markdown
Contributor Author

/test

@khushijain21 khushijain21 added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Mar 9, 2026
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 9, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

This change exports previously private configuration-related types and functions in the Kafka output package. The unexported kafkaConfig type is renamed to KafkaConfig. The unexported readConfig() function is renamed to ReadConfig(). The Validate() method receiver is updated to use the renamed type. The newSaramaConfig() function signature is updated to reference the exported type. All call sites in tests and the main Kafka output module are updated to use the new public function names.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
libbeat/outputs/kafka/config.go (1)

231-253: ⚠️ Potential issue | 🟠 Major

Fix the unsigned-to-signed cast in the Kerberos path.

Line 245 is currently tripping golangci-lint (G115), so this stays red. config.Kerberos.AuthType is being cast to int for sarama.GSSAPIConfig.AuthType; please add an explicit bound check or map the supported auth-type enum values before assigning.

If libbeat/common/transport/kerberos confirms an unsigned backing type, this cast needs guarding.

#!/bin/bash
set -euo pipefail

# Inspect the Kerberos auth type definition and its valid values.
rg -n -C3 --type=go '\btype\s+\w*AuthType\b|\bAuthType\b' libbeat/common/transport/kerberos

# Show the cast site that triggers G115.
rg -n -C2 --type=go 'AuthType:\s+int\(config\.Kerberos\.AuthType\)' libbeat/outputs/kafka/config.go
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libbeat/outputs/kafka/config.go` around lines 231 - 253, The code casts
config.Kerberos.AuthType directly to int when populating
sarama.GSSAPIConfig.AuthType (inside k.Net.SASL.GSSAPI), which trips an
unsigned-to-signed lint (G115); add an explicit bounds check or map allowable
libbeat/common/transport/kerberos AuthType values to the expected sarama integer
constants before assignment (e.g., switch/map on config.Kerberos.AuthType), and
if the value is out of range return or surface a clear error/default instead of
blind casting; update the assignment to use the validated/mapped int value so
the cast is safe and lint-clean.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@libbeat/outputs/kafka/config.go`:
- Around line 231-253: The code casts config.Kerberos.AuthType directly to int
when populating sarama.GSSAPIConfig.AuthType (inside k.Net.SASL.GSSAPI), which
trips an unsigned-to-signed lint (G115); add an explicit bounds check or map
allowable libbeat/common/transport/kerberos AuthType values to the expected
sarama integer constants before assignment (e.g., switch/map on
config.Kerberos.AuthType), and if the value is out of range return or surface a
clear error/default instead of blind casting; update the assignment to use the
validated/mapped int value so the cast is safe and lint-clean.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ce570ab1-e9c8-4398-932f-974ae4f91c7c

📥 Commits

Reviewing files that changed from the base of the PR and between 94fc2ab and b04df3a.

📒 Files selected for processing (4)
  • libbeat/outputs/kafka/config.go
  • libbeat/outputs/kafka/config_nofips_test.go
  • libbeat/outputs/kafka/config_test.go
  • libbeat/outputs/kafka/kafka.go

@github-actions
Copy link
Copy Markdown
Contributor

Checked workflow run 22883384048 for this PR and there is no failure to debug: the only job (check) completed with success, and all steps (including Run check-default) also concluded success.

Root cause: none found in this run because no step failed.

Recommended action: no remediation needed for this specific run; if you expected a failure, please share the exact failing run ID and I can analyze that one.

Tests/log evidence:

  • Workflow conclusion: success
  • Jobs: 1 total, 0 failed
  • Failed-job log scan: No failed jobs found in this workflow run

What is this? | From workflow: PR Actions Detective

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@github-actions
Copy link
Copy Markdown
Contributor

The workflow failure is from golangci-lint on lint (ubuntu-latest) in run 22883384061 (job 66390863691), not from checkout/setup.

Root cause from job logs:

  • libbeat/outputs/kafka/config.go:245:27G115 (uint -> int)
  • libbeat/outputs/kafka/config.go:273:48G115 (int -> int16)
  • libbeat/outputs/kafka/config.go:340:30G115 (int64 -> uint64)
  • libbeat/outputs/kafka/config.go:179:47QF1001 (De Morgan simplification)
  • libbeat/outputs/kafka/config.go:278:15ST1005 (capitalized error string)
  • libbeat/outputs/kafka/config.go:307:15ST1005 (capitalized error string)

Recommended minimal remediation:

  1. Fix the six linter findings in libbeat/outputs/kafka/config.go (safe conversions/range checks for G115, lowercase error messages for ST1005, simplify boolean condition for QF1001).
  2. Re-run golangci-lint locally for the file/package before pushing.

Tests run by me: no local test execution; analysis is based on GitHub Actions job logs for the failed run.


What is this? | From workflow: PR Actions Detective

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@khushijain21 khushijain21 merged commit ece5f0f into elastic:main Mar 10, 2026
200 of 204 checks passed
@khushijain21 khushijain21 added the backport-8.19 Automated backport to the 8.19 branch label Mar 10, 2026
mergify bot pushed a commit that referenced this pull request Mar 10, 2026
* add changelog

* make kafka config global variable

(cherry picked from commit ece5f0f)
khushijain21 pushed a commit that referenced this pull request Mar 10, 2026
belimawr pushed a commit to belimawr/beats that referenced this pull request Mar 12, 2026
* add changelog

* make kafka config global variable
belimawr pushed a commit to belimawr/beats that referenced this pull request Mar 12, 2026
* add changelog

* make kafka config global variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-8.19 Automated backport to the 8.19 branch Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants