-
Notifications
You must be signed in to change notification settings - Fork 129
Check failure store when available during system tests #1973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jsoriano
merged 18 commits into
elastic:main
from
jsoriano:detect-errors-in-failure-store
Jul 24, 2024
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dfbb951
Add helper to enable or disable failure store in index template
jsoriano 67b9426
Don't update the data stream if already in the expected state
jsoriano 0199402
Fix typo
jsoriano 63b883c
Enable and check failure store on system tests
jsoriano 22fa9b7
Interrupt loop waiting docs if there are docs in the failure store
jsoriano 574a8a2
Include error message in results
jsoriano 12548f2
Ignore errors in the failure store caused by document conflicts
jsoriano e14ac74
Filter out errors about conflicting documents
jsoriano 08332d4
Add test case
jsoriano 842cc74
Ensure feature is enabled
jsoriano 42f9b52
Add missing fields to test package
jsoriano 9fe6090
Remove use of feature flag
jsoriano f9bcf0e
Enable failure store also in 8.14
jsoriano 0f63308
Explicitly check if the failure store is available
jsoriano a8c71d5
Rename method to check if failure stoe is available
jsoriano 69ffa36
Linting
jsoriano 11cddae
Support failure store since 8.15.0
jsoriano b911556
Show additional info in errors
jsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // 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 ingest | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/elastic/elastic-package/internal/elasticsearch" | ||
| ) | ||
|
|
||
| func EnableFailureStore(ctx context.Context, api *elasticsearch.API, indexTemplateName string, enabled bool) error { | ||
| resp, err := api.Indices.GetIndexTemplate( | ||
| api.Indices.GetIndexTemplate.WithContext(ctx), | ||
| api.Indices.GetIndexTemplate.WithName(indexTemplateName), | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get index template %s: %w", indexTemplateName, err) | ||
| } | ||
| defer resp.Body.Close() | ||
| if resp.IsError() { | ||
| return fmt.Errorf("failed to get index template %s: %s", indexTemplateName, resp.String()) | ||
| } | ||
|
|
||
| var templateResponse struct { | ||
| IndexTemplates []struct { | ||
| IndexTemplate map[string]any `json:"index_template"` | ||
| } `json:"index_templates"` | ||
| } | ||
| err = json.NewDecoder(resp.Body).Decode(&templateResponse) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to decode response while getting index template %s: %w", indexTemplateName, err) | ||
| } | ||
| if n := len(templateResponse.IndexTemplates); n != 1 { | ||
| return fmt.Errorf("unexpected number of index templates obtained while getting %s, expected 1, found %d", indexTemplateName, err) | ||
| } | ||
|
|
||
| template := templateResponse.IndexTemplates[0].IndexTemplate | ||
| dsSettings, found := template["data_stream"] | ||
| if found { | ||
| dsMap, ok := dsSettings.(map[string]any) | ||
| if !ok { | ||
| return fmt.Errorf("unexpected type for data stream settings in index template %s, expected map, found %T", indexTemplateName, dsMap) | ||
| } | ||
| if current, found := dsMap["failure_store"].(bool); found && current == enabled { | ||
| // Nothing to do, it already has the expected value. | ||
| return nil | ||
| } | ||
| dsMap["failure_store"] = enabled | ||
| template["data_stream"] = dsMap | ||
| } else { | ||
| template["data_stream"] = map[string]any{ | ||
| "failure_store": enabled, | ||
| } | ||
| } | ||
|
|
||
| d, err := json.Marshal(template) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal template after updating it: %w", err) | ||
| } | ||
|
|
||
| updateResp, err := api.Indices.PutIndexTemplate(indexTemplateName, bytes.NewReader(d), | ||
| api.Indices.PutIndexTemplate.WithContext(ctx), | ||
| api.Indices.PutIndexTemplate.WithCreate(false), | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to update index template %s: %w", indexTemplateName, err) | ||
| } | ||
| defer updateResp.Body.Close() | ||
| if updateResp.IsError() { | ||
| return fmt.Errorf("failed to update index template %s: %s", indexTemplateName, resp.String()) | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // 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 ingest | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/elastic/elastic-package/internal/elasticsearch" | ||
| estest "github.com/elastic/elastic-package/internal/elasticsearch/test" | ||
| ) | ||
|
|
||
| func TestEnableFailureStore(t *testing.T) { | ||
| client := estest.NewClient(t, "testdata/elasticsearch-8-enable-failure-store") | ||
|
|
||
| templateName := "ep-test-index-template" | ||
| templateBody := []byte(`{"index_patterns": ["metrics-eptest.failurestore-*"],"data_stream": {}}`) | ||
| createTempIndexTemplate(t, client.API, templateName, templateBody) | ||
| assertFailureStore(t, client.API, templateName, false) | ||
|
|
||
| err := EnableFailureStore(context.Background(), client.API, templateName, true) | ||
| assert.NoError(t, err) | ||
| assertFailureStore(t, client.API, templateName, true) | ||
|
|
||
| err = EnableFailureStore(context.Background(), client.API, templateName, false) | ||
| assert.NoError(t, err) | ||
| assertFailureStore(t, client.API, templateName, false) | ||
| } | ||
|
|
||
| func TestEnableFailureStoreNothingToDo(t *testing.T) { | ||
| client := estest.NewClient(t, "testdata/elasticsearch-8-enable-failure-store-noop") | ||
|
|
||
| templateName := "ep-test-index-template" | ||
| templateBody := []byte(`{"index_patterns": ["metrics-eptest.failurestore-*"],"data_stream": {"failure_store":true}}`) | ||
| createTempIndexTemplate(t, client.API, templateName, templateBody) | ||
| assertFailureStore(t, client.API, templateName, true) | ||
|
|
||
| err := EnableFailureStore(context.Background(), client.API, templateName, true) | ||
| assert.NoError(t, err) | ||
| assertFailureStore(t, client.API, templateName, true) | ||
| } | ||
|
|
||
| func createTempIndexTemplate(t *testing.T, api *elasticsearch.API, name string, body []byte) { | ||
| createResp, err := api.Indices.PutIndexTemplate(name, bytes.NewReader(body), | ||
| api.Indices.PutIndexTemplate.WithCreate(true), | ||
| ) | ||
| require.NoError(t, err) | ||
| require.False(t, createResp.IsError(), createResp.String()) | ||
| t.Cleanup(func() { | ||
| deleteResp, err := api.Indices.DeleteIndexTemplate(name) | ||
| require.NoError(t, err) | ||
| require.False(t, deleteResp.IsError()) | ||
| }) | ||
| } | ||
|
|
||
| func assertFailureStore(t *testing.T, api *elasticsearch.API, name string, expected bool) { | ||
| resp, err := api.Indices.GetIndexTemplate( | ||
| api.Indices.GetIndexTemplate.WithName(name), | ||
| ) | ||
| require.NoError(t, err) | ||
| require.False(t, resp.IsError()) | ||
| defer resp.Body.Close() | ||
|
|
||
| var templateResponse struct { | ||
| IndexTemplates []struct { | ||
| IndexTemplate struct { | ||
| DataStream struct { | ||
| FailureStore *bool `json:"failure_store"` | ||
| } `json:"data_stream"` | ||
| } `json:"index_template"` | ||
| } `json:"index_templates"` | ||
| } | ||
| err = json.NewDecoder(resp.Body).Decode(&templateResponse) | ||
| require.NoError(t, err) | ||
| require.Len(t, templateResponse.IndexTemplates, 1) | ||
| found := templateResponse.IndexTemplates[0].IndexTemplate.DataStream.FailureStore | ||
|
|
||
| if assert.NotNil(t, found) { | ||
| assert.Equal(t, expected, *found) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.