elastic / elastic/beats

[bug-hunter] Kafka major alias "4" resolves to 4.0.0 instead of latest 4.1.0

Open
#49,491 1 comment 0 reactions 0 assignees View on GitHub
needs_team
Dominant language
Go
Stars
12.7k
Forks
5k
Avg merge
2d 15m
Merged PRs (30d)
385

Description

## Impact
Users who set `output.kafka.version: "4"` (major shorthand) are routed to Kafka protocol `4.0.0` instead of the latest supported `4.x` (`4.1.0`). This can silently disable newer Kafka 4.1 protocol behavior while users believe they selected the latest in the major stream.

## Reproduction Steps
1. From repo root, create a minimal test:

```go
// libbeat/common/kafka/zzz_repro_test.go
package kafka

import (
"testing"

"github.com/elastic/sarama"
)

func TestRepro_MajorVersionAliasUsesLatestMinor(t *testing.T) {
got, ok := Version("4").Get()
if !ok {
t.Fatal("Version(\"4\") should parse")
}
if got != sarama.V4_1_0_0 {
t.Fatalf("expected alias 4 to resolve to latest 4.x (%v), got %v", sarama.V4_1_0_0, got)
}
}
```

2. Run:

```bash
go test ./libbeat/common/kafka -run TestRepro_MajorVersionAliasUsesLatestMinor -count=1
```

3. Remove repro file:

```bash
rm libbeat/common/kafka/zzz_repro_test.go
```

## Expected vs Actual
**Expected:** `Version("4").Get()` resolves to the latest supported `4.x` version (`sarama.V4_1_0_0`), consistent with the abbreviation contract in comments.

**Actual:** It resolves to `sarama.V4_0_0_0` and the test fails.

Observed output:

```text
--- FAIL: TestRepro_MajorVersionAliasUsesLatestMinor (0.00s)
zzz_repro_test.go:15: expected alias 4 to resolve to latest 4.x (4.1.0), got 4.0.0
FAIL
FAIL github.com/elastic/beats/v7/libbeat/common/kafka 0.004s
FAIL
```

## Failing Test
```go
package kafka

import (
"testing"

"github.com/elastic/sarama"
)

func TestRepro_MajorVersionAliasUsesLatestMinor(t *testing.T) {
got, ok := Version("4").Get()
if !ok {
t.Fatal("Version(\"4\") should parse")
}
if got != sarama.V4_1_0_0 {
t.Fatalf("expected alias 4 to resolve to latest 4.x (%v), got %v", sarama.V4_1_0_0, got)
}
}
```

## Evidence
- Abbreviation contract says major prefixes map to the most recent matching version: `libbeat/common/kafka/version.go:30-33`.
- Current mapping sets `"4"` to `sarama.V4_0_0_0`: `libbeat/common/kafka/version.go:76-78`.
- `git blame` on those lines points to commit `9eb4e0e5984` (Sarama update in the last 28 days).
- Checked `/tmp/previous-findings.json`; no matching prior bug-hunter issue for this behavior.

---
[What is this?](https://ela.st/github-ai-tools) | [From workflow: Bug Hunter](https://github.com/elastic/beats/actions/runs/23141061964)

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.
> - [x] expires on Mar 23, 2026, 11:32 AM UTC

Contributor guide

Open the contributing guide

Research direction

Start in libbeat/common/kafka/version.go, especially the abbreviation contract at lines 30-33 and the major-version mapping at lines 76-78. Run the provided focused test in ./libbeat/common/kafka; done means the test passes and Version("4").Get() returns sarama.V4_1_0_0 without leaving the temporary repro file.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kafka
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.