@@ -10,8 +10,6 @@ import (
10
10
"net/http"
11
11
"strings"
12
12
13
- "github.com/elastic/go-elasticsearch/v8/typedapi/types"
14
-
15
13
"github.com/jaegertracing/jaeger/cmd/es-rollover/app"
16
14
"github.com/jaegertracing/jaeger/pkg/es"
17
15
"github.com/jaegertracing/jaeger/pkg/es/client"
@@ -58,10 +56,7 @@ func (c Action) Do() error {
58
56
return err
59
57
}
60
58
if ! policyExist {
61
- err := createDefaultILMPolicy (c .ILMClient , c .Config .ILMPolicyName )
62
- if err != nil {
63
- return fmt .Errorf ("ILM policy %s Create/Update failed" , c .Config .ILMPolicyName )
64
- }
59
+ return fmt .Errorf ("ILM policy %s doesn't exist in Elasticsearch. Please create it and re-run init" , c .Config .ILMPolicyName )
65
60
}
66
61
}
67
62
rolloverIndices := app .RolloverIndices (c .Config .Archive , c .Config .SkipDependencies , c .Config .AdaptiveSampling , c .Config .Config .IndexPrefix )
@@ -73,64 +68,6 @@ func (c Action) Do() error {
73
68
return nil
74
69
}
75
70
76
- const esILMPolicy = `
77
- {
78
- "policy": {
79
- "phases": {
80
- "hot": {
81
- "min_age": "9999ms",
82
- "actions": {
83
- "rollover": {
84
- "max_age": "1m"
85
- },
86
- "set_priority": {
87
- "priority": 9999
88
- }
89
- }
90
- },
91
- "delete": {
92
- "min_age": "9999m",
93
- "actions": {
94
- "delete": {}
95
- }
96
- }
97
- }
98
- }
99
- }
100
- `
101
-
102
- func createDefaultILMPolicy (c client.IndexManagementLifecycleAPI , policy string ) error {
103
- ilmPolicy := types .NewIlmPolicy ()
104
- err := json .Unmarshal ([]byte (esILMPolicy ), ilmPolicy )
105
- if err != nil {
106
- return fmt .Errorf ("error unmarshalling ILM policy: %w" , err )
107
- }
108
- err = c .CreateOrUpdate (policy , client.Policy {ILMPolicy : * ilmPolicy })
109
- if err != nil {
110
- var esErr client.ResponseError
111
- if errors .As (err , & esErr ) {
112
- if esErr .StatusCode != http .StatusBadRequest || esErr .Body == nil {
113
- return esErr .Err
114
- }
115
- // check for the reason of the error
116
- jsonError := map [string ]any {}
117
- err := json .Unmarshal (esErr .Body , & jsonError )
118
- if err != nil {
119
- // return unmarshal error
120
- return err
121
- }
122
- errorMap := jsonError ["error" ].(map [string ]any )
123
- // check for reason, ignore already exist error
124
- if strings .Contains (errorMap ["type" ].(string ), "resource_already_exists_exception" ) {
125
- return nil
126
- }
127
- }
128
- // Return any other error unrelated to the response
129
- return err
130
- }
131
- return nil
132
- }
133
-
134
71
func createIndexIfNotExist (c client.IndexAPI , index string ) error {
135
72
err := c .CreateIndex (index )
136
73
if err != nil {
0 commit comments