Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Explicitly check if the failure store is available
  • Loading branch information
jsoriano committed Jul 18, 2024
commit 0f633087383574cb81c67ea753f96c3e6f35b601
14 changes: 4 additions & 10 deletions cmd/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sort"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/spf13/cobra"

"github.com/elastic/elastic-package/internal/cobraext"
Expand Down Expand Up @@ -535,15 +534,6 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("can't create Kibana client: %w", err)
}
versionInfo, err := kibanaClient.Version()
if err != nil {
return fmt.Errorf("can't get version info from Kibana client: %w", err)
}
stackVersion, err := semver.NewVersion(versionInfo.Number)
if err != nil {
return fmt.Errorf("can't parse Kibana version %q: %w", versionInfo.Number, err)
}
checkFailureStore := !stackVersion.LessThan(semver.MustParse("8.14.0"))

esClient, err := stack.NewElasticsearchClientFromProfile(profile)
if err != nil {
Expand All @@ -553,6 +543,10 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
checkFailureStore, err := esClient.CheckFailureStore(ctx)
if err != nil {
return fmt.Errorf("can't check if failure store is available: %w", err)
}

if runTearDown || runTestsOnly {
if variantFlag != "" {
Expand Down
26 changes: 26 additions & 0 deletions internal/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ func (client *Client) CheckHealth(ctx context.Context) error {
return nil
}

// CheckFailureStore checks if the failure store is available.
func (client *Client) CheckFailureStore(ctx context.Context) (bool, error) {
// FIXME: Using the low-level transport till the API SDK supports the failure store.
request, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/_search?failure_store=only"), nil)
if err != nil {
return false, fmt.Errorf("failed to create search request: %w", err)
}
request.Header.Set("Content-Type", "application/json")

resp, err := client.Transport.Perform(request)
if err != nil {
return false, fmt.Errorf("failed to perform search request: %w", err)
}
defer resp.Body.Close()

switch resp.StatusCode {
case http.StatusOK:
return true, nil
case http.StatusBadRequest:
// Error expected when using an unrecognized parameter.
return false, nil
default:
return false, fmt.Errorf("unexpected status code received: %d", resp.StatusCode)
}
}

// redHealthCause tries to identify the cause of a cluster in red state. This could be
// also used as a replacement of CheckHealth, but keeping them separated because it uses
// internal undocumented APIs that might change.
Expand Down