diff --git a/cmd/es-rollover/app/actions_test.go b/cmd/es-rollover/app/actions_test.go index c3208de8dfc..b1fd51c3238 100644 --- a/cmd/es-rollover/app/actions_test.go +++ b/cmd/es-rollover/app/actions_test.go @@ -121,5 +121,4 @@ func TestExecuteAction(t *testing.T) { } }) } - } diff --git a/cmd/es-rollover/app/flags.go b/cmd/es-rollover/app/flags.go index f1b9664d51e..c18b7221fb5 100644 --- a/cmd/es-rollover/app/flags.go +++ b/cmd/es-rollover/app/flags.go @@ -51,7 +51,6 @@ func AddFlags(flags *flag.FlagSet) { flags.Bool(useILM, false, "Use ILM to manage jaeger indices") flags.String(ilmPolicyName, "", "The name of the ILM policy to use if ILM is active") flags.Int(timeout, 120, "Number of seconds to wait for master node response") - } // InitFromViper initializes config from viper.Viper. diff --git a/cmd/es-rollover/app/index_options_test.go b/cmd/es-rollover/app/index_options_test.go index ec263396e8f..3c8c9d3c2f1 100644 --- a/cmd/es-rollover/app/index_options_test.go +++ b/cmd/es-rollover/app/index_options_test.go @@ -112,7 +112,6 @@ func TestRolloverIndices(t *testing.T) { assert.Equal(t, test.expected[i].readAliasName, r.ReadAliasName()) assert.Equal(t, test.expected[i].writeAliasName, r.WriteAliasName()) assert.Equal(t, test.expected[i].initialRolloverIndex, r.InitialRolloverIndex()) - } }) } diff --git a/cmd/es-rollover/app/init/action.go b/cmd/es-rollover/app/init/action.go index c4603a10b55..f5db9cfebc4 100644 --- a/cmd/es-rollover/app/init/action.go +++ b/cmd/es-rollover/app/init/action.go @@ -75,7 +75,6 @@ func (c Action) Do() error { return err } } - return nil } @@ -129,7 +128,6 @@ func (c Action) init(version uint, indexset app.IndexOption) error { readAlias := indexset.ReadAliasName() writeAlias := indexset.WriteAliasName() - aliases := []client.Alias{} if !filter.AliasExists(jaegerIndices, readAlias) { @@ -154,6 +152,5 @@ func (c Action) init(version uint, indexset app.IndexOption) error { return err } } - return nil } diff --git a/cmd/es-rollover/app/init/flags.go b/cmd/es-rollover/app/init/flags.go index ae11e487d47..763656a7b3c 100644 --- a/cmd/es-rollover/app/init/flags.go +++ b/cmd/es-rollover/app/init/flags.go @@ -38,7 +38,6 @@ type Config struct { func (c *Config) AddFlags(flags *flag.FlagSet) { flags.Int(shards, 5, "Number of shards") flags.Int(replicas, 1, "Number of replicas") - } // InitFromViper initializes config from viper.Viper. diff --git a/cmd/es-rollover/app/lookback/action.go b/cmd/es-rollover/app/lookback/action.go index 120be7e615d..cfa782e2d6d 100644 --- a/cmd/es-rollover/app/lookback/action.go +++ b/cmd/es-rollover/app/lookback/action.go @@ -43,15 +43,16 @@ func (a *Action) Do() error { } func (a *Action) lookback(indexSet app.IndexOption) error { - jaegerIndicex, err := a.IndicesClient.GetJaegerIndices(a.Config.IndexPrefix) + jaegerIndex, err := a.IndicesClient.GetJaegerIndices(a.Config.IndexPrefix) if err != nil { return err } readAliasName := indexSet.ReadAliasName() - readAliasIndices := filter.ByAlias(jaegerIndicex, []string{readAliasName}) + readAliasIndices := filter.ByAlias(jaegerIndex, []string{readAliasName}) excludedWriteIndex := filter.ByAliasExclude(readAliasIndices, []string{indexSet.WriteAliasName()}) finalIndices := filter.ByDate(excludedWriteIndex, getTimeReference(timeNow(), a.Unit, a.UnitCount)) + if len(finalIndices) == 0 { return fmt.Errorf("no indices to remove from alias %s", readAliasName) } @@ -64,6 +65,6 @@ func (a *Action) lookback(indexSet app.IndexOption) error { Name: readAliasName, }) } - return a.IndicesClient.DeleteAlias(aliases) + return a.IndicesClient.DeleteAlias(aliases) } diff --git a/cmd/es-rollover/app/lookback/action_test.go b/cmd/es-rollover/app/lookback/action_test.go index c49c4639c9d..d2af0804421 100644 --- a/cmd/es-rollover/app/lookback/action_test.go +++ b/cmd/es-rollover/app/lookback/action_test.go @@ -78,7 +78,6 @@ func TestLookBackAction(t *testing.T) { config Config expectedErr error }{ - { name: "success", setupCallExpectations: func(indexClient *mocks.MockIndexAPI) { diff --git a/cmd/es-rollover/app/lookback/flags.go b/cmd/es-rollover/app/lookback/flags.go index ffe1ab09144..b68d03eb898 100644 --- a/cmd/es-rollover/app/lookback/flags.go +++ b/cmd/es-rollover/app/lookback/flags.go @@ -46,5 +46,4 @@ func (c *Config) AddFlags(flags *flag.FlagSet) { func (c *Config) InitFromViper(v *viper.Viper) { c.Unit = v.GetString(unit) c.UnitCount = v.GetInt(unitCount) - } diff --git a/cmd/es-rollover/app/lookback/time_reference.go b/cmd/es-rollover/app/lookback/time_reference.go index 03aba135fd9..88b70f7b191 100644 --- a/cmd/es-rollover/app/lookback/time_reference.go +++ b/cmd/es-rollover/app/lookback/time_reference.go @@ -37,7 +37,5 @@ func getTimeReference(currentTime time.Time, units string, unitCount int) time.T year, month, day := currentTime.Date() return time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).AddDate(-1*unitCount, 0, 0) } - return currentTime.Truncate(time.Second).Add(-time.Duration(unitCount) * time.Second) - } diff --git a/cmd/es-rollover/app/rollover/action.go b/cmd/es-rollover/app/rollover/action.go index 0c09438ddce..7cb82ad7023 100644 --- a/cmd/es-rollover/app/rollover/action.go +++ b/cmd/es-rollover/app/rollover/action.go @@ -54,12 +54,12 @@ func (a *Action) rollover(indexSet app.IndexOption) error { if err != nil { return err } - jaegerIndicex, err := a.IndicesClient.GetJaegerIndices(a.Config.IndexPrefix) + jaegerIndex, err := a.IndicesClient.GetJaegerIndices(a.Config.IndexPrefix) if err != nil { return err } - indicesWithWriteAlias := filter.ByAlias(jaegerIndicex, []string{writeAlias}) + indicesWithWriteAlias := filter.ByAlias(jaegerIndex, []string{writeAlias}) aliases := make([]client.Alias, 0, len(indicesWithWriteAlias)) for _, index := range indicesWithWriteAlias { aliases = append(aliases, client.Alias{ diff --git a/cmd/es-rollover/app/rollover/flags.go b/cmd/es-rollover/app/rollover/flags.go index b0d66af087f..2e5cd66144d 100644 --- a/cmd/es-rollover/app/rollover/flags.go +++ b/cmd/es-rollover/app/rollover/flags.go @@ -36,7 +36,6 @@ type Config struct { // AddFlags adds flags for TLS to the FlagSet. func (c *Config) AddFlags(flags *flag.FlagSet) { flags.String(conditions, defaultRollbackCondition, "conditions used to rollover to a new write index") - } // InitFromViper initializes config from viper.Viper. diff --git a/cmd/es-rollover/main.go b/cmd/es-rollover/main.go index 2c4c035e274..847fea6d673 100644 --- a/cmd/es-rollover/main.go +++ b/cmd/es-rollover/main.go @@ -46,7 +46,7 @@ func main() { // Init command initCfg := &initialize.Config{} initCommand := &cobra.Command{ - Use: "init [ELASTICSEARCH_HOST]", + Use: "init http://HOSTNAME:PORT", Short: "creates indices and aliases", Long: "creates indices and aliases", Args: cobra.ExactArgs(1), @@ -83,7 +83,7 @@ func main() { rolloverCfg := &rollover.Config{} rolloverCommand := &cobra.Command{ - Use: "rollover [ELASTICSEARCH_HOST]", + Use: "rollover http://HOSTNAME:PORT", Short: "rollover to new write index", Long: "rollover to new write index", Args: cobra.ExactArgs(1), @@ -112,7 +112,7 @@ func main() { lookbackCfg := lookback.Config{} lookbackCommand := &cobra.Command{ - Use: "lookback [ELASTICSEARCH_HOST]", + Use: "lookback http://HOSTNAME:PORT", Short: "removes old indices from read alias", Long: "removes old indices from read alias", Args: cobra.ExactArgs(1), @@ -130,7 +130,6 @@ func main() { Client: c, MasterTimeoutSeconds: lookbackCfg.Timeout, } - return &lookback.Action{ IndicesClient: indicesClient, Config: lookbackCfg, diff --git a/pkg/es/client/basic_auth_test.go b/pkg/es/client/basic_auth_test.go index b25462dfbfc..124b9ca3866 100644 --- a/pkg/es/client/basic_auth_test.go +++ b/pkg/es/client/basic_auth_test.go @@ -46,7 +46,5 @@ func TestBasicAuth(t *testing.T) { assert.Equal(t, test.expectedResult, result) }) - } - } diff --git a/pkg/es/client/client.go b/pkg/es/client/client.go index 1bb62b2d8f3..04ff294e8b5 100644 --- a/pkg/es/client/client.go +++ b/pkg/es/client/client.go @@ -36,7 +36,7 @@ func (r ResponseError) Error() string { return r.Err.Error() } -func (r ResponseError) PrefixMessage(message string) ResponseError { +func (r ResponseError) prefixMessage(message string) ResponseError { return ResponseError{ Err: fmt.Errorf("%s, %w", message, r.Err), StatusCode: r.StatusCode, @@ -96,7 +96,6 @@ func (c *Client) request(esRequest elasticRequest) ([]byte, error) { if err != nil { return []byte{}, err } - return body, nil } @@ -114,7 +113,6 @@ func (c *Client) handleFailedRequest(res *http.Response) error { } body := string(bodyBytes) return newResponseError(fmt.Errorf("request failed, status code: %d, body: %s", res.StatusCode, body), res.StatusCode, bodyBytes) - } return newResponseError(fmt.Errorf("request failed, status code: %d", res.StatusCode), res.StatusCode, nil) } diff --git a/pkg/es/client/cluster_client.go b/pkg/es/client/cluster_client.go index a0d64ddf880..dfa7df0a881 100644 --- a/pkg/es/client/cluster_client.go +++ b/pkg/es/client/cluster_client.go @@ -22,6 +22,8 @@ import ( "strings" ) +var _ ClusterAPI = (*ClusterClient)(nil) + // ClusterClient is a client used to get ES cluster information type ClusterClient struct { Client diff --git a/pkg/es/client/ilm_client.go b/pkg/es/client/ilm_client.go index ddc130d500d..5d06328fc23 100644 --- a/pkg/es/client/ilm_client.go +++ b/pkg/es/client/ilm_client.go @@ -19,6 +19,8 @@ import ( "net/http" ) +var _ IndexManagementLifecycleAPI = (*ILMClient)(nil) + // ILMClient is a client used to manipulate Index lifecycle management policies. type ILMClient struct { Client @@ -31,14 +33,15 @@ func (i ILMClient) Exists(name string) (bool, error) { endpoint: fmt.Sprintf("_ilm/policy/%s", name), method: http.MethodGet, }) + if respError, isResponseErr := err.(ResponseError); isResponseErr { if respError.StatusCode == http.StatusNotFound { return false, nil } } + if err != nil { return false, fmt.Errorf("failed to get ILM policy: %s, %w", name, err) } return true, nil - } diff --git a/pkg/es/client/index_client.go b/pkg/es/client/index_client.go index ab6456b2e6c..0f853c5386f 100644 --- a/pkg/es/client/index_client.go +++ b/pkg/es/client/index_client.go @@ -43,6 +43,8 @@ type Alias struct { IsWriteIndex bool } +var _ IndexAPI = (*IndicesClient)(nil) + // IndicesClient is a client used to manipulate indices. type IndicesClient struct { Client @@ -112,12 +114,11 @@ func (i *IndicesClient) DeleteIndices(indices []Index) error { if err != nil { if responseError, isResponseError := err.(ResponseError); isResponseError { if responseError.StatusCode != http.StatusOK { - return responseError.PrefixMessage(fmt.Sprintf("failed to delete indices: %s", concatIndices)) + return responseError.prefixMessage(fmt.Sprintf("failed to delete indices: %s", concatIndices)) } } return fmt.Errorf("failed to delete indices: %w", err) } - return nil } @@ -130,12 +131,11 @@ func (i *IndicesClient) CreateIndex(index string) error { if err != nil { if responseError, isResponseError := err.(ResponseError); isResponseError { if responseError.StatusCode != http.StatusOK { - return responseError.PrefixMessage(fmt.Sprintf("failed to create index: %s", index)) + return responseError.prefixMessage(fmt.Sprintf("failed to create index: %s", index)) } } return fmt.Errorf("failed to create index: %w", err) } - return nil } @@ -145,7 +145,7 @@ func (i *IndicesClient) CreateAlias(aliases []Alias) error { if err != nil { if responseError, isResponseError := err.(ResponseError); isResponseError { if responseError.StatusCode != http.StatusOK { - return responseError.PrefixMessage(fmt.Sprintf("failed to create aliases: %s", i.aliasesString(aliases))) + return responseError.prefixMessage(fmt.Sprintf("failed to create aliases: %s", i.aliasesString(aliases))) } } return fmt.Errorf("failed to create aliases: %w", err) @@ -159,7 +159,7 @@ func (i *IndicesClient) DeleteAlias(aliases []Alias) error { if err != nil { if responseError, isResponseError := err.(ResponseError); isResponseError { if responseError.StatusCode != http.StatusOK { - return responseError.PrefixMessage(fmt.Sprintf("failed to delete aliases: %s", i.aliasesString(aliases))) + return responseError.prefixMessage(fmt.Sprintf("failed to delete aliases: %s", i.aliasesString(aliases))) } } return fmt.Errorf("failed to delete aliases: %w", err) @@ -218,7 +218,7 @@ func (i IndicesClient) CreateTemplate(template, name string) error { if err != nil { if responseError, isResponseError := err.(ResponseError); isResponseError { if responseError.StatusCode != http.StatusOK { - return responseError.PrefixMessage(fmt.Sprintf("failed to create template: %s", name)) + return responseError.prefixMessage(fmt.Sprintf("failed to create template: %s", name)) } } return fmt.Errorf("failed to create template: %w", err) @@ -246,7 +246,7 @@ func (i IndicesClient) Rollover(rolloverTarget string, conditions map[string]int if err != nil { if responseError, isResponseError := err.(ResponseError); isResponseError { if responseError.StatusCode != http.StatusOK { - return responseError.PrefixMessage(fmt.Sprintf("failed to create rollover target: %s", rolloverTarget)) + return responseError.prefixMessage(fmt.Sprintf("failed to create rollover target: %s", rolloverTarget)) } } return fmt.Errorf("failed to create rollover: %w", err) diff --git a/pkg/es/filter/date_test.go b/pkg/es/filter/date_test.go index e2b5846f571..946aa1b69ef 100644 --- a/pkg/es/filter/date_test.go +++ b/pkg/es/filter/date_test.go @@ -90,5 +90,4 @@ func TestByDate(t *testing.T) { result := ByDate(indices, beforeDateFilter) assert.Equal(t, expectedIndices, result) - }