Skip to content

Commit

Permalink
Ignore bugfix version when running version compatibility check agains…
Browse files Browse the repository at this point in the history
…t Elasticsearch (#30746) (#30750)

(cherry picked from commit 46be42e)

Co-authored-by: Noémi Ványi <[email protected]>
  • Loading branch information
mergify[bot] and kvch authored Mar 10, 2022
1 parent 8eca962 commit 38bb73f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...main[Check the HEAD dif
- Fixes Beats crashing when glibc >= 2.35 is used {issue}30576[30576]
- Log errors when parsing and applying config blocks and if the input is disabled. {pull}30534[30534]
- Wildcard fields no longer have a default ignore_above setting of 1024. {issue}30096[30096] {pull}30668[30668]
- Ignore bugfix version when running version compatibility check against Elasticsearch. {pull}30746[30746]

*Auditbeat*

Expand Down
2 changes: 1 addition & 1 deletion libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ func (b *Beat) checkElasticsearchVersion() {
if err != nil {
return err
}
if esVersion.LessThan(beatVersion) {
if esVersion.LessThanMajorMinor(beatVersion) {
return fmt.Errorf("%v ES=%s, Beat=%s.", elasticsearch.ErrTooOld, esVersion.String(), b.Info.Version)
}
return nil
Expand Down
21 changes: 17 additions & 4 deletions libbeat/common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,28 @@ func (v *Version) LessThanOrEqual(withMeta bool, v1 *Version) bool {
// LessThan returns true if v is strictly smaller than v1. When comparing, the major,
// minor and bugfix numbers are compared in order. The meta part is not taken into account.
func (v *Version) LessThan(v1 *Version) bool {
lessThan := v.LessThanMajorMinor(v1)
if lessThan {
return true
}

if v.Minor == v1.Minor {
if v.Bugfix < v1.Bugfix {
return true
}
}

return false
}

// LessThanMajorMinor returns true if v is smaller or equal to v1 based on the major and minor version. The bugfix version and meta part are not taken into account.
// minor numbers are compared in order. The and bugfix version and meta part is not taken into account.
func (v *Version) LessThanMajorMinor(v1 *Version) bool {
if v.Major < v1.Major {
return true
} else if v.Major == v1.Major {
if v.Minor < v1.Minor {
return true
} else if v.Minor == v1.Minor {
if v.Bugfix < v1.Bugfix {
return true
}
}
}
return false
Expand Down
49 changes: 49 additions & 0 deletions libbeat/common/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,52 @@ func TestVersionLessThan(t *testing.T) {
assert.Equal(t, v.LessThan(v1), test.result, test.name)
}
}

func TestVersionLessThanMajorMinor(t *testing.T) {
tests := []struct {
name string
version string
version1 string
result bool
}{
{
name: "1.2.x < 2.0.x",
version: "1.2.3",
version1: "2.0.0",
result: true,
},
{
name: "1.2.3 = 1.2.3-beta1",
version: "1.2.3",
version1: "1.2.3-beta1",
result: false,
},
{
name: "5.4.x == 5.4.x",
version: "5.4.1",
version1: "5.4.2",
result: false,
},
{
name: "5.5.x > 5.4.x",
version: "5.5.1",
version1: "5.4.2",
result: false,
},
{
name: "6.1.x < 6.2.x",
version: "6.1.1-alpha3",
version1: "6.2.0",
result: true,
},
}

for _, test := range tests {
v, err := NewVersion(test.version)
assert.NoError(t, err)
v1, err := NewVersion(test.version1)
assert.NoError(t, err)

assert.Equal(t, v.LessThanMajorMinor(v1), test.result, test.name)
}
}

0 comments on commit 38bb73f

Please sign in to comment.