Skip to content

Commit

Permalink
Fix some code styles, extra spaces etc..
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 committed Sep 9, 2021
1 parent 751aa02 commit ff0cc79
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 36 deletions.
1 change: 0 additions & 1 deletion cmd/es-rollover/app/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,4 @@ func TestExecuteAction(t *testing.T) {
}
})
}

}
1 change: 0 additions & 1 deletion cmd/es-rollover/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion cmd/es-rollover/app/index_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

}
})
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/es-rollover/app/init/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (c Action) Do() error {
return err
}
}

return nil
}

Expand Down Expand Up @@ -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) {
Expand All @@ -154,6 +152,5 @@ func (c Action) init(version uint, indexset app.IndexOption) error {
return err
}
}

return nil
}
1 change: 0 additions & 1 deletion cmd/es-rollover/app/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions cmd/es-rollover/app/lookback/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -64,6 +65,6 @@ func (a *Action) lookback(indexSet app.IndexOption) error {
Name: readAliasName,
})
}
return a.IndicesClient.DeleteAlias(aliases)

return a.IndicesClient.DeleteAlias(aliases)
}
1 change: 0 additions & 1 deletion cmd/es-rollover/app/lookback/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func TestLookBackAction(t *testing.T) {
config Config
expectedErr error
}{

{
name: "success",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI) {
Expand Down
1 change: 0 additions & 1 deletion cmd/es-rollover/app/lookback/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
2 changes: 0 additions & 2 deletions cmd/es-rollover/app/lookback/time_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}
4 changes: 2 additions & 2 deletions cmd/es-rollover/app/rollover/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion cmd/es-rollover/app/rollover/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions cmd/es-rollover/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -130,7 +130,6 @@ func main() {
Client: c,
MasterTimeoutSeconds: lookbackCfg.Timeout,
}

return &lookback.Action{
IndicesClient: indicesClient,
Config: lookbackCfg,
Expand Down
2 changes: 0 additions & 2 deletions pkg/es/client/basic_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,5 @@ func TestBasicAuth(t *testing.T) {
assert.Equal(t, test.expectedResult, result)

})

}

}
4 changes: 1 addition & 3 deletions pkg/es/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -96,7 +96,6 @@ func (c *Client) request(esRequest elasticRequest) ([]byte, error) {
if err != nil {
return []byte{}, err
}

return body, nil
}

Expand All @@ -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)
}
2 changes: 2 additions & 0 deletions pkg/es/client/cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"strings"
)

var _ ClusterAPI = (*ClusterClient)(nil)

// ClusterClient is a client used to get ES cluster information
type ClusterClient struct {
Client
Expand Down
5 changes: 4 additions & 1 deletion pkg/es/client/ilm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

}
16 changes: 8 additions & 8 deletions pkg/es/client/index_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pkg/es/filter/date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,4 @@ func TestByDate(t *testing.T) {

result := ByDate(indices, beforeDateFilter)
assert.Equal(t, expectedIndices, result)

}

0 comments on commit ff0cc79

Please sign in to comment.