Skip to content

Commit

Permalink
[8.0](backport #1211) Report back the detected version of the remote …
Browse files Browse the repository at this point in the history
…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 7d5b7e1)

* changelog

(cherry picked from commit 2831340)

* working on something

(cherry picked from commit 4e5e5a4)

* wrong key

(cherry picked from commit 24a1c67)

Co-authored-by: Pier-Hugues Pellerin <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] and ph authored Mar 9, 2022
1 parent 0911f59 commit 8ffc748
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
==== Bugfixes

- Return a better error on enrolling and the Elasticsearch version is incompatible. {pull}1211[1211]
15 changes: 10 additions & 5 deletions cmd/fleet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
}

Expand Down
9 changes: 5 additions & 4 deletions internal/pkg/ver/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,29 @@ 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 (
ErrUnsupportedVersion = errors.New("unsupported version")
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 {
Expand Down

0 comments on commit 8ffc748

Please sign in to comment.