-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add es-index-cleaner golang implementation #3192
Add es-index-cleaner golang implementation #3192
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3192 +/- ##
==========================================
+ Coverage 95.93% 95.94% +0.01%
==========================================
Files 239 242 +3
Lines 14661 14786 +125
==========================================
+ Hits 14065 14187 +122
- Misses 519 521 +2
- Partials 77 78 +1
Continue to review full report at Codecov.
|
e4c0d79
to
0cd66b9
Compare
Added TLS and basic auth support to the PR. |
The coverage is weird, it should be green:
It also says that there is a regression in static handler which I didn't touch. |
Signed-off-by: Pavol Loffay <[email protected]>
03e9826
to
18aea51
Compare
// indices: jaeger-span-archive-000001 | ||
func (i *IndicesClient) GetJaegerIndices(prefix string) ([]Index, error) { | ||
prefix += "jaeger-*" | ||
r, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?flat_settings=true&filter_path=*.aliases,*.settings", i.Endpoint, prefix), nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question, do we need to URL encode the prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't the NewRequest encode the url?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, I don't think it is important. I was just wondering what happen if the prefix is for instance pattern is jaeger/tracing-*
return nil, fmt.Errorf("failed to query Jaeger indices: %q", err) | ||
} | ||
|
||
if response.StatusCode != 200 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to accept the whole 200 class (like 204), instead of specifically the 200.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you might want to have a list of errors that are retriable, making this more resilient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to be strict here ES returns only 200.
Retries can be added later as a separate feature.
cmd/es-index-cleaner/main.go
Outdated
) | ||
|
||
func main() { | ||
logger, _ := zap.NewDevelopment() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste from esmapping-generator
main
Signed-off-by: Pavol Loffay <[email protected]>
PR updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK to give it a try!
flags.String(indexPrefix, "", "Index prefix") | ||
flags.Bool(archive, false, "Whether to remove archive indices") | ||
flags.Bool(rollover, false, "Whether to remove indices created by rollover") | ||
flags.Int(timeout, 120, "Number of seconds to wait for master node response") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the reason for using seconds instead of Duration
for compatibility with the python version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
} | ||
var indicesInfo map[string]indexInfo | ||
if err = json.Unmarshal(body, &indicesInfo); err != nil { | ||
return nil, fmt.Errorf("failed to query indices and unmarshall response body: %q: %w", body, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("failed to query indices and unmarshall response body: %q: %w", body, err) | |
return nil, fmt.Errorf("failed to query indices and unmarshal response body: %q: %w", body, err) |
errContains: "failed to query indices: request failed, status code: 400", | ||
}, | ||
{ | ||
name: "unmarshall error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: "unmarshall error", | |
name: "unmarshal error", |
name: "unmarshall error", | ||
responseCode: http.StatusOK, | ||
response: "AAA", | ||
errContains: `failed to query indices and unmarshall response body: "AAA"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errContains: `failed to query indices and unmarshall response body: "AAA"`, | |
errContains: `failed to query indices and unmarshal response body: "AAA"`, |
Updates #3179
Sharing this early to get some reviews. The only missing part in this PR is to increase the test coverage.
Future PRs: