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

Move buildEsQuery to a package #23345

Merged
merged 42 commits into from
Nov 22, 2018
Merged

Conversation

lukasolson
Copy link
Member

@lukasolson lukasolson commented Sep 19, 2018

This PR moves the buildESQuery module (including filters and kuery) into a separate package so that it can be imported on both the client and server (in preparation to support Kuery in Timelion and TSVB).

/cc @timroes @lukeelmers

To do:

  • Figure out why errors are no longer handled the same way
  • Fix tests

@lukasolson lukasolson added WIP Work in progress Feature:Query Bar Querying and query bar features Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:KQL KQL labels Sep 19, 2018
@elasticmachine
Copy link
Contributor

💔 Build Failed

.eslintignore Outdated
/src/ui/public/kuery/ast/kuery.js
/src/ui/public/kuery/ast/legacy_kuery.js
/src/utils/kuery/ast/kuery.js
/src/utils/kuery/ast/legacy_kuery.js
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of interest: why are we ignoring those two files for linting? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

They're generated by PEG

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@lukasolson lukasolson self-assigned this Sep 24, 2018
Copy link
Contributor

@Bargs Bargs left a comment

Choose a reason for hiding this comment

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

Looks great overall, just had a couple minor questions. Tested some queries and filters in the UI and everything seemed to work still.

throw parseError;
}
throw new Error(
`It looks like you're using an outdated Kuery syntax. See what changed in the [docs](${queryDocs.kueryQuerySyntax})!`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove the link to the docs? Without any direction I think it'll be impossible for a user to find the right information.

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 didn't want it to rely on something in public/ (which is where documentationLinks is). I guess I could just make the invoking function in public/ check for this type of error and add the links.

Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation_links module could also probably be moved to utils?

Copy link
Member Author

Choose a reason for hiding this comment

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

That module relies on ui/metadata which I'm not sure could be moved to utils...

Copy link
Contributor

Choose a reason for hiding this comment

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

It only uses the branch name though. I think the stuff in metadata ultimately comes from the server, so the branch name should be accessible somewhere.

catch (parseError) {
if (parseError instanceof NoLeadingWildcardsError) {
throw parseError;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What was this condition doing and why was it removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I got rid of the NoLeadingWildcardsError since it relied on KbnError in public. Instead, we just throw a regular error. This condition wasn't actually really necessary anyway since we end up throwing the error anyway below (unless it parses successfully in the old syntax). So in theory, the only thing that changes by removing this condition is when something would parse successfully in the old grammar but also has a leading wildcard, which I can't imagine of a scenario.

decorateQuery,
buildQueryFromFilters,
luceneStringToDsl
} from '../../../../utils/es_query';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we even need to export these from here now are can existing users of this module just import the functions from the new directory?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could, it just seemed like fewer changes to do it this way rather than go through each of the imports and change them. I'm open to changing this if you think it makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I missed some, but it looked to me like the imports had already been changed. Intellij's refactoring tools should handle it. I'd just rip the band aid off cleanly so folks in the future aren't confused about where they should be importing from.

Copy link
Member Author

Choose a reason for hiding this comment

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

Made the change. Wasn't even bad at all

try {
flatData.body.query = buildESQuery(flatData.index, flatData.query, flatData.filters);
} catch (e) {
throw new KbnError(e.message, KbnError);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok now that I see this, I'm assuming that's why you removed the wildcard error type?

export * from './ast';
export * from './filter_migration';
export * from './node_types';
export * from '../../../utils/kuery';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just delete this module now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same comment as above, we could, but we'd have to update all of the references, which is fine by me if you think it's best.

@lukasolson
Copy link
Member Author

Responded to your feedback @Bargs. I also updated it so it retains the link to the docs in the outdated syntax error.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@lukeelmers lukeelmers self-requested a review October 3, 2018 15:25
Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

code makes sense & LGTM - just added one question

if (e.message === 'OutdatedKuerySyntaxError') {
const message = `It looks like you're using an outdated Kuery syntax.
See what changed in the [docs](${documentationLinks.query.kueryQuerySyntax})!`;
throw new KbnError(message, KbnError);
Copy link
Member

Choose a reason for hiding this comment

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

Rather than adding the message / link back here, would it be better to add a class for this error type to errors.js? It seems that's a convention we've followed elsewhere, but not sure if it's something we are sticking with.

@lukasolson lukasolson changed the title [WIP] Move buildEsQuery to utils Move buildEsQuery to utils Oct 4, 2018
@lukasolson lukasolson added review and removed WIP Work in progress labels Oct 4, 2018
@ppisljar
Copy link
Member

ppisljar commented Oct 17, 2018

couldn't we move this to a package, so it could then be imported with import { ... } from '@kbn/kuery' ?

@lukasolson
Copy link
Member Author

@ppisljar Yeah, that makes a lot of sense. I'll see if I can get that working.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@markov00
Copy link
Member

@mattapperson @sqren @weltenwort Would you mind taking another quick look at this PR if we miss something for Infra/APM? We are trying to get this merged soon because we have some other PRs that depends on this.
Nothing really changed since your comments, we just fixed the CI failures that was related to a wrong babel configuration.
Thanks

@weltenwort
Copy link
Member

still looks good as far as the infra ui usage is concerned 👍

@sorenlouv
Copy link
Member

Everything looks good from APM POV 👍

@markov00 markov00 merged commit e36767a into elastic:master Nov 22, 2018
@markov00
Copy link
Member

@Bargs @lukasolson I've merged on master, but there is a conflict on backporting this PR because of this missing backported PR: #15640.
It was a breacking change that goes only into 7.0, so I will let you decide if we should backport to 6.6 as this PR label says or not

@spalger
Copy link
Contributor

spalger commented Nov 22, 2018

@lukasolson when backporting this PR please remove the x-pack/yarn.lock file, it was removed when we moved to yarn workspaces.

lukasolson added a commit to lukasolson/kibana that referenced this pull request Nov 27, 2018
* fix: move buildEsQuery to utils

* fix: tests that I broke

* fix: add back link to the docs

* fix: don't export from ui/ and link to utils

* fix: move to a package

* fix: move error to errors.js

* fix: paths for peg task

* fix: update reference to kuery

* fix: build step for transpilation

* fix: add typescript declaration file

* fix: test

* tmp: debug individual tests

* debug: add debug stuff for reporting tests

* try to debug test

* Testing splitting reporting jobs in two

* Testing splitting each job

* Fix ci yaml

* Skipping job to check failing test

* debug - adding a catch to jobResponseHandler on report

* Testing a different job and enabling verbose mode

* Testing verbose on phantom_api skipping other CI tests

* Fix script mode

* fix: try running tests in chromium

* fix: move out of devDependencies

* fix: remove commented test

* Revert "fix: try running tests in chromium"

This reverts commit 991d46f.

* Revert testing changes

* Fixing build for phantomjs

* Revert CI configuration to master. Remove verbose logging for tests
lukasolson pushed a commit to lukasolson/kibana that referenced this pull request Nov 27, 2018
lukasolson added a commit that referenced this pull request Dec 18, 2018
* Move buildEsQuery to a package (#23345)

* fix: move buildEsQuery to utils

* fix: tests that I broke

* fix: add back link to the docs

* fix: don't export from ui/ and link to utils

* fix: move to a package

* fix: move error to errors.js

* fix: paths for peg task

* fix: update reference to kuery

* fix: build step for transpilation

* fix: add typescript declaration file

* fix: test

* tmp: debug individual tests

* debug: add debug stuff for reporting tests

* try to debug test

* Testing splitting reporting jobs in two

* Testing splitting each job

* Fix ci yaml

* Skipping job to check failing test

* debug - adding a catch to jobResponseHandler on report

* Testing a different job and enabling verbose mode

* Testing verbose on phantom_api skipping other CI tests

* Fix script mode

* fix: try running tests in chromium

* fix: move out of devDependencies

* fix: remove commented test

* Revert "fix: try running tests in chromium"

This reverts commit 991d46f.

* Revert testing changes

* Fixing build for phantomjs

* Revert CI configuration to master. Remove verbose logging for tests

* remove x-pack/yarn.lock, accidentally added back in #23345

* Fix import sorting
@lukasolson lukasolson deleted the fix/filtersEverywhere branch December 2, 2019 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:KQL KQL Feature:Query Bar Querying and query bar features review Team:Visualizations Visualization editors, elastic-charts and infrastructure v6.6.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.