Skip to content
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

Merged
merged 2 commits into from
Aug 12, 2021

Conversation

pavolloffay
Copy link
Member

Updates #3179

Sharing this early to get some reviews. The only missing part in this PR is to increase the test coverage.

Future PRs:

  • add support for user/pass and TLS
  • add docker build and include this in ES integration tests
  • remove old python implementation

@pavolloffay pavolloffay requested a review from a team as a code owner August 6, 2021 16:11
@codecov
Copy link

codecov bot commented Aug 9, 2021

Codecov Report

Merging #3192 (7907934) into master (4019fe9) will increase coverage by 0.01%.
The diff coverage is 95.20%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
cmd/es-index-cleaner/app/index_client.go 91.78% <91.78%> (ø)
cmd/es-index-cleaner/app/flags.go 100.00% <100.00%> (ø)
cmd/es-index-cleaner/app/index_filter.go 100.00% <100.00%> (ø)
cmd/query/app/static_handler.go 95.80% <0.00%> (-1.80%) ⬇️
plugin/storage/badger/spanstore/reader.go 96.21% <0.00%> (+0.70%) ⬆️
cmd/query/app/server.go 95.58% <0.00%> (+1.47%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4019fe9...7907934. Read the comment docs.

@pavolloffay pavolloffay force-pushed the es-cleaner-golang branch 2 times, most recently from e4c0d79 to 0cd66b9 Compare August 10, 2021 09:44
@pavolloffay
Copy link
Member Author

Added TLS and basic auth support to the PR.

@pavolloffay
Copy link
Member Author

The coverage is weird, it should be green:

 go test -coverprofile=cover.out  ./cmd/es-index-cleaner...                                            ploffay@fedora
?   	github.com/jaegertracing/jaeger/cmd/es-index-cleaner	[no test files]
ok  	github.com/jaegertracing/jaeger/cmd/es-index-cleaner/app	0.004s	coverage: 96.6% of statements

It also says that there is a regression in static handler which I didn't touch.

cmd/es-index-cleaner/app/index_client.go Outdated Show resolved Hide resolved
// 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)
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

@rubenvp8510 rubenvp8510 Aug 12, 2021

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-*

cmd/es-index-cleaner/app/index_client.go Outdated Show resolved Hide resolved
cmd/es-index-cleaner/app/index_client.go Outdated Show resolved Hide resolved
cmd/es-index-cleaner/app/index_client.go Outdated Show resolved Hide resolved
return nil, fmt.Errorf("failed to query Jaeger indices: %q", err)
}

if response.StatusCode != 200 {
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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/app/index_client.go Outdated Show resolved Hide resolved
cmd/es-index-cleaner/app/index_client.go Outdated Show resolved Hide resolved
cmd/es-index-cleaner/app/index_filter_test.go Outdated Show resolved Hide resolved
cmd/es-index-cleaner/app/index_filter_test.go Outdated Show resolved Hide resolved
)

func main() {
logger, _ := zap.NewDevelopment()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this appropriate?

Copy link
Member Author

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

cmd/es-index-cleaner/main.go Outdated Show resolved Hide resolved
cmd/es-index-cleaner/main.go Outdated Show resolved Hide resolved
Signed-off-by: Pavol Loffay <[email protected]>
@pavolloffay
Copy link
Member Author

PR updated

Copy link
Contributor

@rubenvp8510 rubenvp8510 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@jpkrohling jpkrohling left a 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!

@pavolloffay pavolloffay merged commit 94bc987 into jaegertracing:master Aug 12, 2021
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")
Copy link
Contributor

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?

Copy link
Member Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: "unmarshall error",
name: "unmarshal error",

name: "unmarshall error",
responseCode: http.StatusOK,
response: "AAA",
errContains: `failed to query indices and unmarshall response body: "AAA"`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errContains: `failed to query indices and unmarshall response body: "AAA"`,
errContains: `failed to query indices and unmarshal response body: "AAA"`,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants