Skip to content

Commit

Permalink
pkg/kversion: add 3.7
Browse files Browse the repository at this point in the history
And make 'v' optional in FromString
  • Loading branch information
twmb committed Apr 2, 2024
1 parent f5106ae commit 54d3032
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
38 changes: 34 additions & 4 deletions pkg/kversion/kversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var versions = []struct {
{"v3.4", V3_4_0()},
{"v3.5", V3_5_0()},
{"v3.6", V3_6_0()},
{"v3.7", V3_7_0()},
}

// VersionStrings returns all recognized versions, minus any patch, that can be
Expand All @@ -82,12 +83,14 @@ func VersionStrings() []string {
// The expected input is:
// - for v0, v0.#.# or v0.#.#.#
// - for v1, v1.# or v1.#.#
//
// The "v" is optional.
func FromString(v string) *Versions {
reFromStringOnce.Do(func() {
// 0: entire string
// 1: v1+ match, minus patch
// 2: v0 match, minus subpatch
reFromString = regexp.MustCompile(`^(?:(v[1-9]+\.\d+)(?:\.\d+)?|(v0\.\d+\.\d+)(?:\.\d+)?)$`)
reFromString = regexp.MustCompile(`^(?:(v?[1-9]+\.\d+)(?:\.\d+)?|(v?0\.\d+\.\d+)(?:\.\d+)?)$`)
})
m := reFromString.FindStringSubmatch(v)
if m == nil {
Expand All @@ -97,8 +100,9 @@ func FromString(v string) *Versions {
if m[2] != "" {
v = m[2]
}
withv := "v" + v
for _, v2 := range versions {
if v2.name == v {
if v2.name == v || v2.name == withv {
return v2.v
}
}
Expand Down Expand Up @@ -381,6 +385,7 @@ func (vs *Versions) versionGuess(opts ...VersionGuessOpt) guess {
{max340, "v3.4"},
{max350, "v3.5"},
{max360, "v3.6"},
{max370, "v3.7"},
} {
for k, v := range comparison.cmp.filter(cfg.listener) {
if v == -1 {
Expand Down Expand Up @@ -522,6 +527,7 @@ func V3_3_0() *Versions { return zkBrokerOf(max330) }
func V3_4_0() *Versions { return zkBrokerOf(max340) }
func V3_5_0() *Versions { return zkBrokerOf(max350) }
func V3_6_0() *Versions { return zkBrokerOf(max360) }
func V3_7_0() *Versions { return zkBrokerOf(max370) }

func zkBrokerOf(lks listenerKeys) *Versions {
return &Versions{lks.filter(zkBroker)}
Expand Down Expand Up @@ -992,7 +998,7 @@ var max280 = nextMax(max270, func(v listenerKeys) listenerKeys {

// KAFKA-12204 / KAFKA-10851 302eee63c479fd4b955c44f1058a5e5d111acb57 KIP-700
v = append(v,
k(zkBroker, rBroker), // 60 describe cluster
k(zkBroker, rBroker, rController), // 60 describe cluster; rController in KAFKA-15396 41b695b6e30baa4243d9ca4f359b833e17ed0e77 KIP-919
)

// KAFKA-12212 7a1d1d9a69a241efd68e572badee999229b3942f KIP-700
Expand Down Expand Up @@ -1136,8 +1142,32 @@ var max360 = nextMax(max350, func(v listenerKeys) listenerKeys {
return v
})

var max370 = nextMax(max360, func(v listenerKeys) listenerKeys {
// KAFKA-15661 c8f687ac1505456cb568de2b60df235eb1ceb5f0 KIP-951
v[0].inc() // 10 produce
v[1].inc() // 16 fetch

// 7826d5fc8ab695a5ad927338469ddc01b435a298 KIP-848
// (change introduced in 3.6 but was marked unstable and not visible)
v[8].inc() // 9 offset commit
// KAFKA-14499 7054625c45dc6edb3c07271fe4a6c24b4638424f KIP-848 (and prior)
v[9].inc() // 9 offset fetch

// KAFKA-15368 41b695b6e30baa4243d9ca4f359b833e17ed0e77 KIP-919
// (added rController as well, see above)
v[60].inc() // 1 describe cluster

// KAFKA-14391 3be7f7d611d0786f2f98159d5c7492b0d94a2bb7 KIP-848
// as well as some patches following
v = append(v,
k(zkBroker, rBroker), // 68 consumer group heartbeat
)

return v
})

var (
maxStable = max360
maxStable = max370
maxTip = nextMax(maxStable, func(v listenerKeys) listenerKeys {
return v
})
Expand Down
1 change: 1 addition & 0 deletions pkg/kversion/kversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func TestFromString(t *testing.T) {
{"v2.1", "v2.1"},
{"v2.1.3", "v2.1"},
{"v3.1", "v3.1"},
{"3.1", "v3.1"},

{"v0.7.0", ""}, // too low
{"v999.9", ""}, // too high
Expand Down

0 comments on commit 54d3032

Please sign in to comment.