Skip to content
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
5 changes: 5 additions & 0 deletions x-pack/metricbeat/module/autoops_es/events/error_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,10 @@ func getHTTPResponseBodyInfo(err error) (int, string, string) {
return 0, "CLUSTER_NOT_READY", clusterErr.Message
}

var versionErr *utils.VersionMismatchError
if errors.As(err, &versionErr) {
return 0, "VERSION_MISMATCH", fmt.Sprintf("expected %s, got %s", versionErr.ExpectedVersion, versionErr.ActualVersion)
}

return 0, "UNKNOWN_ERROR", ""
}
10 changes: 10 additions & 0 deletions x-pack/metricbeat/module/autoops_es/events/error_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func TestGetHTTPResponseBodyInfo(t *testing.T) {
expectedCode: "CLUSTER_NOT_READY",
expectedBody: "Cluster not ready",
},
{
name: "Error is of type VersionMismatchError",
inputError: &utils.VersionMismatchError{
ExpectedVersion: "7.10.0",
ActualVersion: "7.9.3",
},
expectedStatus: 0,
expectedCode: "VERSION_MISMATCH",
expectedBody: "expected 7.10.0, got 7.9.3",
},
{
name: "Error is not of a known type",
inputError: errors.New("some other error"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package metricset

import (
"fmt"
"os"
"time"

Expand Down Expand Up @@ -46,7 +45,10 @@ func GetInfo(m *elasticsearch.MetricSet) (*utils.ClusterInfo, error) {
func checkEsVersion(esVersion *libversion.V, errChan chan error) error {
if esVersion.LessThan(minVersion) {
isVersionChecked = true
err := fmt.Errorf("version %s is less than the minimum required version %s", esVersion.String(), minVersion)
err := &utils.VersionMismatchError{
ExpectedVersion: minVersion.String(),
ActualVersion: esVersion.String(),
}
errChan <- err
return err
}
Expand Down
18 changes: 18 additions & 0 deletions x-pack/metricbeat/module/autoops_es/utils/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package utils

import (
"fmt"
)

type VersionMismatchError struct {
ExpectedVersion string
ActualVersion string
}

func (e *VersionMismatchError) Error() string {
return fmt.Sprintf("version mismatch: expected %s, got %s", e.ExpectedVersion, e.ActualVersion)
}