From 8ffc748b74ce1a26c0109364fe66d12a6f793fb3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 9 Mar 2022 20:38:40 +0000 Subject: [PATCH] [8.0](backport #1211) Report back the detected version of the remote Elasticsearch (#1212) * Report back the detected version of the remote Elasticsearch Previously the system was return an error with only the ``` Fleet Server - Error - failed version compatibility check with elasticsearch: unsupported version' ``` Instead we will return ``` Fleet Server - Error - failed version compatibility check with elasticsearch (Agent: 8.2.0, Elasticsearch: 7.19.0): unsupported version' ``` (cherry picked from commit 7d5b7e1d31e0026c2851f22da4c8a4a567981210) * changelog (cherry picked from commit 2831340d01b057067018c21cb70c5d35fb4c8e83) * working on something (cherry picked from commit 4e5e5a4f96d534dbf58155486e039318448b3a40) * wrong key (cherry picked from commit 24a1c67308bd0520ada2e84723dbc4607dbcc119) Co-authored-by: Pier-Hugues Pellerin Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- CHANGELOG.next.asciidoc | 3 +++ cmd/fleet/main.go | 15 ++++++++++----- internal/pkg/ver/check.go | 9 +++++---- 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 CHANGELOG.next.asciidoc diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc new file mode 100644 index 000000000..e87170eec --- /dev/null +++ b/CHANGELOG.next.asciidoc @@ -0,0 +1,3 @@ +==== Bugfixes + +- Return a better error on enrolling and the Elasticsearch version is incompatible. {pull}1211[1211] diff --git a/cmd/fleet/main.go b/cmd/fleet/main.go index 8eeaaa104..7858086c4 100644 --- a/cmd/fleet/main.go +++ b/cmd/fleet/main.go @@ -15,11 +15,12 @@ import ( "sync" "time" - "github.com/elastic/go-ucfg" - "github.com/elastic/go-ucfg/yaml" "go.elastic.co/apm" apmtransport "go.elastic.co/apm/transport" + "github.com/elastic/go-ucfg" + "github.com/elastic/go-ucfg/yaml" + "github.com/elastic/fleet-server/v7/internal/pkg/action" "github.com/elastic/fleet-server/v7/internal/pkg/build" "github.com/elastic/fleet-server/v7/internal/pkg/bulk" @@ -41,14 +42,15 @@ import ( "github.com/elastic/fleet-server/v7/internal/pkg/status" "github.com/elastic/fleet-server/v7/internal/pkg/ver" - "github.com/elastic/elastic-agent-client/v7/pkg/client" - "github.com/elastic/elastic-agent-client/v7/pkg/proto" "github.com/hashicorp/go-version" "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" + + "github.com/elastic/elastic-agent-client/v7/pkg/client" + "github.com/elastic/elastic-agent-client/v7/pkg/proto" ) const ( @@ -785,8 +787,11 @@ func (f *FleetServer) runSubsystems(ctx context.Context, cfg *config.Config, g * esCli := bulker.Client() // Check version compatibility with Elasticsearch - err = ver.CheckCompatibility(ctx, esCli, f.bi.Version) + remoteVersion, err := ver.CheckCompatibility(ctx, esCli, f.bi.Version) if err != nil { + if len(remoteVersion) != 0 { + return fmt.Errorf("failed version compatibility check with elasticsearch (Agent: %s, Elasticsearch: %s): %w", f.bi.Version, remoteVersion, err) + } return fmt.Errorf("failed version compatibility check with elasticsearch: %w", err) } diff --git a/internal/pkg/ver/check.go b/internal/pkg/ver/check.go index e504bf727..a577f2b4b 100644 --- a/internal/pkg/ver/check.go +++ b/internal/pkg/ver/check.go @@ -13,9 +13,10 @@ import ( esh "github.com/elastic/fleet-server/v7/internal/pkg/es" - "github.com/elastic/go-elasticsearch/v7" "github.com/hashicorp/go-version" "github.com/rs/zerolog/log" + + "github.com/elastic/go-elasticsearch/v7" ) var ( @@ -23,18 +24,18 @@ var ( ErrMalformedVersion = errors.New("malformed version") ) -func CheckCompatibility(ctx context.Context, esCli *elasticsearch.Client, fleetVersion string) error { +func CheckCompatibility(ctx context.Context, esCli *elasticsearch.Client, fleetVersion string) (string, error) { log.Debug().Str("fleet_version", fleetVersion).Msg("check version compatibility with elasticsearch") esVersion, err := esh.FetchESVersion(ctx, esCli) if err != nil { log.Error().Err(err).Msg("failed to fetch elasticsearch version") - return err + return "", err } log.Debug().Str("elasticsearch_version", esVersion).Msg("fetched elasticsearch version") - return checkCompatibility(fleetVersion, esVersion) + return esVersion, checkCompatibility(fleetVersion, esVersion) } func checkCompatibility(fleetVersion, esVersion string) error {