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

[DataView] Fix multiple pattern matching #152552

Closed
wants to merge 17 commits into from

Conversation

shahzad31
Copy link
Contributor

Summary

If multiple patterns are provided and it matches no indices. it should return 404.

Example

heartbeat-8*,heartbeat-7*,synthetics-*

@shahzad31 shahzad31 requested a review from a team as a code owner March 2, 2023 10:47
@shahzad31 shahzad31 added v8.7.0 v8.8.0 release_note:skip Skip the PR/issue when compiling release notes labels Mar 2, 2023
Comment on lines 76 to 79
if (patternListActive.length === 0) {
throw new DataViewMissingIndices(patternList.join(','));
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Since Matt is on PTO and also has been working on this issue, could you provide some context about this change, what is being fixed, and how it can be tested? Many thx!

BTW: some recent change in this area, to raise awareness #151788

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello, so the integration Test added by matt speaks for itself. when multiple heartbeat-8*,heartbeat-7*,synthetics-* like this was provided and if none of them contained any index, request was matching to all the indices.

@kertal kertal added the Feature:Data Views Data Views code and UI - index patterns before 8.0 label Mar 9, 2023
@mattkime mattkime added backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) and removed v8.7.0 labels Mar 20, 2023
await supertest
.get('/api/index_patterns/_fields_for_wildcard')
.query({ pattern: 'bad_index,bad_index_2' })
.expect(404);
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 think you will need to update test as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -72,6 +72,9 @@ export class IndexPatternsFetcher {
// if only one pattern, don't bother with validation. We let getFieldCapabilities fail if the single pattern is bad regardless
if (patternList.length > 1 && !allowNoIndices) {
patternListActive = await this.validatePatternListActive(patternList);
if (patternListActive.length === 0) {
return { fields: [], indices: [] };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO we should back-port this as empty fields/indices list to 8.7 but in 8.8.0 we should throw error and communicate it to handle the error in UI.

Copy link
Contributor

@mattkime mattkime Mar 20, 2023

Choose a reason for hiding this comment

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

@shahzad31 we recently decided against that behavior since it can often result in 'toast storms' and does not align with the getting started experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. So i think in this case, if someone needs to really determine they can check length of indices to see if it actually matched any thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

@shahzad31 Yes, exactly, and handle it well for the user instead of depending upon the toast.

@mattkime
Copy link
Contributor

@shahzad31 does other work depend upon this PR? It seems that addressing tests will be more work than 'fixing' the code.

Comment on lines +95 to +97
if (indices.length === 0 && allowNoIndex !== true) {
throw new DataViewMissingIndices(pattern);
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? shouldn't it just return an empty array of fields + indices in this case?

Copy link
Member

Choose a reason for hiding this comment

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

@mattkime these changes should be removed, to make the PR green

@mattkime
Copy link
Contributor

This PR looks easier and removes unneeded code - #153350

@kertal
Copy link
Member

kertal commented Mar 24, 2023

This PR looks easier and removes unneeded code - #153350

@mattkime this looks like good follow up, but I also recommend to move forward here, since it's a minimal change, good to backport, which we should ... it needs just small changes, to make this green

await supertest
.get('/api/index_patterns/_fields_for_wildcard')
.query({ pattern: 'bad_index,bad_index_2' })
.expect(404);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.expect(404);
.expect(200);

since it's no longer an error condition, this, with the reverting the change for fields_for should make this PR ready to merge

@mattkime
Copy link
Contributor

Closing in favor of #153350 - will bring over the api integration test.

@mattkime mattkime closed this Mar 24, 2023
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 433 436 +3

Total ESLint disabled count

id before after diff
securitySolution 513 516 +3

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @mattkime @shahzad31

@shahzad31 shahzad31 deleted the fix-data-view branch March 24, 2023 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:skip Skip the PR/issue when compiling release notes v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants