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)

(cherry picked from commit 46be42e)

# Conflicts:
#	libbeat/cmd/instance/beat.go
  • Loading branch information
kvch authored and mergify-bot committed Mar 9, 2022
1 parent f8b2289 commit feff18e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...main[Check the HEAD dif
- Update docker/distribution dependency library to fix a security issues concerning OCI Manifest Type Confusion Issue. {pull}30462[30462]
- 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
11 changes: 11 additions & 0 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ func (b *Beat) warnAboutElasticsearchVersion() {
}

elasticsearch.RegisterGlobalCallback(func(conn *eslegclient.Connection) error {
<<<<<<< HEAD
warnAboutOldES.Do(func() {
esVersion := conn.GetVersion()
beatVersion, err := common.NewVersion(b.Info.Version)
Expand All @@ -882,6 +883,16 @@ func (b *Beat) warnAboutElasticsearchVersion() {
logp.Warn("Connecting to older version of Elasticsearch. From 8.1, connecting to older versions will be disabled by default.")
}
})
=======
esVersion := conn.GetVersion()
beatVersion, err := common.NewVersion(b.Info.Version)
if err != nil {
return err
}
if esVersion.LessThanMajorMinor(beatVersion) {
return fmt.Errorf("%v ES=%s, Beat=%s.", elasticsearch.ErrTooOld, esVersion.String(), b.Info.Version)
}
>>>>>>> 46be42e7d5 (Ignore bugfix version when running version compatibility check against Elasticsearch (#30746))
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 feff18e

Please sign in to comment.