Skip to content
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

Ignore bugfix version when running version compatibility check against Elasticsearch #30746

Merged
merged 3 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 @@ -883,7 +883,7 @@ func (b *Beat) checkElasticsearchVersion() {
if err != nil {
return err
}
if esVersion.LessThan(beatVersion) {
if esVersion.LessThanMajorMinor(beatVersion) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't our comparison be LessThanOrEqual?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we return an error if the version of ES is less than the version of Beats. If this was LessThanOrEqual, we would return an error when ES and Beats is on the same version.

Copy link
Contributor

Choose a reason for hiding this comment

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

I compared the wrong way around 🤦‍♂️

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)
}
}