Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
Signed-off-by: zzzk1 <[email protected]>
  • Loading branch information
zzzk1 committed Jan 18, 2025
1 parent e8caadd commit 20d8aeb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 105 deletions.
65 changes: 1 addition & 64 deletions cmd/es-rollover/app/init/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"net/http"
"strings"

"github.com/elastic/go-elasticsearch/v8/typedapi/types"

"github.com/jaegertracing/jaeger/cmd/es-rollover/app"
"github.com/jaegertracing/jaeger/pkg/es"
"github.com/jaegertracing/jaeger/pkg/es/client"
Expand Down Expand Up @@ -58,10 +56,7 @@ func (c Action) Do() error {
return err
}
if !policyExist {
err := createDefaultILMPolicy(c.ILMClient, c.Config.ILMPolicyName)
if err != nil {
return fmt.Errorf("ILM policy %s Create/Update failed", c.Config.ILMPolicyName)
}
return fmt.Errorf("ILM policy %s doesn't exist in Elasticsearch. Please create it and re-run init", c.Config.ILMPolicyName)
}
}
rolloverIndices := app.RolloverIndices(c.Config.Archive, c.Config.SkipDependencies, c.Config.AdaptiveSampling, c.Config.Config.IndexPrefix)
Expand All @@ -73,64 +68,6 @@ func (c Action) Do() error {
return nil
}

const esILMPolicy = `
{
"policy": {
"phases": {
"hot": {
"min_age": "9999ms",
"actions": {
"rollover": {
"max_age": "1m"
},
"set_priority": {
"priority": 9999
}
}
},
"delete": {
"min_age": "9999m",
"actions": {
"delete": {}
}
}
}
}
}
`

func createDefaultILMPolicy(c client.IndexManagementLifecycleAPI, policy string) error {
ilmPolicy := types.NewIlmPolicy()
err := json.Unmarshal([]byte(esILMPolicy), ilmPolicy)
if err != nil {
return fmt.Errorf("error unmarshalling ILM policy: %w", err)
}
err = c.CreateOrUpdate(policy, client.Policy{ILMPolicy: *ilmPolicy})
if err != nil {
var esErr client.ResponseError
if errors.As(err, &esErr) {
if esErr.StatusCode != http.StatusBadRequest || esErr.Body == nil {
return esErr.Err
}
// check for the reason of the error
jsonError := map[string]any{}
err := json.Unmarshal(esErr.Body, &jsonError)
if err != nil {
// return unmarshal error
return err
}
errorMap := jsonError["error"].(map[string]any)
// check for reason, ignore already exist error
if strings.Contains(errorMap["type"].(string), "resource_already_exists_exception") {
return nil
}
}
// Return any other error unrelated to the response
return err
}
return nil
}

func createIndexIfNotExist(c client.IndexAPI, index string) error {
err := c.CreateIndex(index)
if err != nil {
Expand Down
13 changes: 3 additions & 10 deletions cmd/es-rollover/app/init/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,12 @@ func TestRolloverAction(t *testing.T) {
},
},
{
name: "create ILM policy",
setupCallExpectations: func(indexClient *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, ilmClient *mocks.IndexManagementLifecycleAPI) {
name: "ilm doesnt exist",
setupCallExpectations: func(_ *mocks.IndexAPI, clusterClient *mocks.ClusterAPI, ilmClient *mocks.IndexManagementLifecycleAPI) {
clusterClient.On("Version").Return(uint(7), nil)
ilmClient.On("Exists", "myilmpolicy").Return(false, nil)
indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, nil)
indexClient.On("CreateAlias", []client.Alias{
{Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-read", IsWriteIndex: false},
{Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-write", IsWriteIndex: true},
}).Return(nil)
ilmClient.On("CreateOrUpdate", "myilmpolicy", mock.Anything).Return(nil)
},
expectedErr: errors.New("ILM policy myilmpolicy doesn't exist in Elasticsearch. Please create it and re-run init"),
config: Config{
Config: app.Config{
Archive: true,
Expand Down
31 changes: 0 additions & 31 deletions plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
dependenciesTemplateName = "jaeger-dependencies"
primaryNamespace = "es"
archiveNamespace = "es-archive"
ilmPolicy = "jaeger-ilm-policy"
)

type ESStorageIntegration struct {
Expand Down Expand Up @@ -245,33 +244,3 @@ func (s *ESStorageIntegration) cleanESIndexTemplates(t *testing.T, prefix string
}
return nil
}

func TestElasticsearchStorage_ILMPolicy(t *testing.T) {
SkipUnlessEnv(t, "elasticsearch", "opensearch")
t.Cleanup(func() {
testutils.VerifyGoLeaksOnceForES(t)
})
c := getESHttpClient(t)
require.NoError(t, healthCheck(c))
s := &ESStorageIntegration{}
s.initializeES(t, c, true)
esVersion, err := s.getVersion()
require.NoError(t, err)
if esVersion == 8 {
request := s.v8Client.ILM.GetLifecycle.WithPolicy(ilmPolicy)
ilmPolicyExistsResponse, err := s.v8Client.ILM.GetLifecycle(request)
require.NoError(t, err)
assert.Equal(t, 200, ilmPolicyExistsResponse.StatusCode)
}
s.cleanEsILMPolicy(t)
}

func (s *ESStorageIntegration) cleanEsILMPolicy(t *testing.T) error {
version, err := s.getVersion()
require.NoError(t, err)
if version == 8 {
_, err := s.v8Client.ILM.RemovePolicy(ilmPolicy)
require.NoError(t, err)
}
return nil
}

0 comments on commit 20d8aeb

Please sign in to comment.