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

Refine getIndices() to return an empty array if there are no matching indices. #12659

Merged

Conversation

cjcenizal
Copy link
Contributor

@cjcenizal cjcenizal commented Jul 4, 2017

This fixes a bug that caused an array of the original query and undefined to be returned when the indices API response was a 404, e.g. submitting .kib as the query will return [".kib", undefined], but we would expect to get back [].

Extracted from bbbe8d3.

- Return deduplicated aggregate of both alias and indices.
- Fix bug that caused an array of the original query and undefined to be returned when the API response was a 404.
Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

Hmm. I don't understand the need to combine both result sets.

When I did the initial discovery here, I found the .getAlias endpoint returned everything we needed, but only if an existing alias existed. If no aliases were found, then we just need to search against indices (since there are no aliases to also search against).

What are the reasons for always making and combining the two separate calls?

@cjcenizal cjcenizal force-pushed the improvement/get-indices-and-aliases branch from d3f9c00 to e6f5b01 Compare July 5, 2017 16:47
@cjcenizal cjcenizal changed the title Refine getIndices() to return deduplicated aggregate of both alias and indices. Refine getIndices() to return an empty array if there are no matching indices. Jul 5, 2017
@cjcenizal
Copy link
Contributor Author

@chrisronline Ah you're right. Sorry, I think that must have been leftover from my exploration. I've updated the PR and the title/description. Could you take another look?

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

Mostly looks good! One minor suggestion

@@ -1,6 +1,10 @@
import { pluck, reduce, size } from 'lodash';

const getIndicesFromResponse = json => {
const getIndexNamesFromAliasesResponse = json => {
if (json.status === 404) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be necessary as it's handled on line 30

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about this too... after chewing it over, I think we should consider it incidental that it's handled on line 30. My basis for this reasoning is that this function doesn't "know" about line 30. So by handling the 404 case we've future-proofed it. We'll never need to change it even if the surrounding code changes (e.g. by exporting this function and using it elsewhere, or by removing the condition on line 30). What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I'm not so sure I agree, but I don't mind it living here too if you feel strongly about it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd be OK removing this check if we were to scope both helpers to the caller, e.g. by moving them to line 27. Want me to do that? It's just that since they're outside, they look like they're more generalized helper functions, which tend to be a little more bullet proof.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but can you define the right under export function IndicesGetIndicesProvider(esAdmin) {?

@cjcenizal
Copy link
Contributor Author

@chrisronline Done!

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

LGTM!

@cjcenizal cjcenizal merged commit 0e6af88 into elastic:master Jul 5, 2017
@cjcenizal cjcenizal deleted the improvement/get-indices-and-aliases branch July 5, 2017 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants