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

[WIP] KQL in TSVB with full QueryBar #36175

Closed

Conversation

TinaHeiligers
Copy link
Contributor

@TinaHeiligers TinaHeiligers commented May 7, 2019

Note: #36784 has been opened in favor of this PR.

Summary

References Support KQL in TSVB Filter aggregations
Adds KQL to Visual Builder (TSVB)
Still TODO:

  • Replace the full QueryBar with the QueryBarInput.
  • Update components accordingly
  • Update this summary
  • Complete checks below

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@TinaHeiligers TinaHeiligers requested review from a team and Bargs May 7, 2019 13:59
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@TinaHeiligers
Copy link
Contributor Author

jenkins, test this

@elasticmachine
Copy link
Contributor

💔 Build Failed

@TinaHeiligers TinaHeiligers force-pushed the KQL_in_TSVB_rebased_May6_am branch from d0c7454 to 0d72b39 Compare May 7, 2019 22:31
@elasticmachine
Copy link
Contributor

💔 Build Failed

@TinaHeiligers TinaHeiligers force-pushed the KQL_in_TSVB_rebased_May6_am branch from 0d72b39 to 1a3ef1c Compare May 8, 2019 17:05
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@TinaHeiligers TinaHeiligers force-pushed the KQL_in_TSVB_rebased_May6_am branch from b6a4b7b to 8724d68 Compare May 9, 2019 14:34
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

async componentDidMount() {
await this.fetchIndexPatternsForQuery();
}
fetchIndexPatternsForQuery = async () => {
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 reuse this method? I see you duplicated this method 7 times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The index pattern we use to fetch the index pattern from SavedObjects has a different reference in each method and it needs to set state in each component. Each method is slightly different and that is why it is redefined. If you have a recommendation on how to more easily set state in a component with a shared method, please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

@TinaHeiligers I've checked that,
We have similar body for:

src/legacy/core_plugins/metrics/public/components/annotations_editor.js
src/legacy/core_plugins/metrics/public/components/panel_config/gauge.js
src/legacy/core_plugins/metrics/public/components/panel_config/markdown.js
src/legacy/core_plugins/metrics/public/components/panel_config/metric.js 
src/legacy/core_plugins/metrics/public/components/panel_config/table.js
src/legacy/core_plugins/metrics/public/components/panel_config/timeseries.js 
src/legacy/core_plugins/metrics/public/components/panel_config/top_n.js 
src/legacy/core_plugins/metrics/public/components/series.js

and only one different implementation for
src/legacy/core_plugins/metrics/public/components/split.js

I still think that we should somehow to reuse it

}
fetchIndexPatternsForQuery = async () => {
const searchIndexPattern = this.props.model.index_pattern ?
this.props.model.index_pattern :
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we can save 2 lines using || operator
const searchIndexPattern = this.props.model.index_pattern || this.props.model.default_index_pattern


handleSubmit = (model, query) => {
const part = { query_string: query.query };
collectionActions.handleChange(this.props, _.assign({}, model, part));
Copy link
Contributor

Choose a reason for hiding this comment

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

we are trying to remove all references to _. in our code and don't add the new one.

what do you think about:

collectionActions.handleChange(this.props, {
   ...model, 
   ...part
});`

: this.state.uiQueryLanguage,
query: model.query_string.query,
}}
screenTitle={'AnnotationsEditor'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we localize this value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The value is localized internally within the QueryBarInputUI component.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks!

this.state = {
selectedTab: 'data',
indexPatternForQuery: {},
uiQuerylanguage: uiSettingsQueryLanguage,
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 have any cases when this value will be changed in the 'state'? If not probably we can remove it from state and do something like

<QueryBar
                    query={{
                      language: model.filter.language || uiSettingsQueryLanguage ,
                      query: model.filter.query,
                    }}

const { model } = this.props;
if (!model.background_color_rules || (model.background_color_rules && model.background_color_rules.length === 0)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's try to use isEmpty method from lodash here?

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 didn't add that but can change it if preferred.

let indexPatternObject;
const indexPatternsFromSavedObjects = await chrome.getSavedObjectsClient().find({
type: 'index-pattern',
fields: ['title', 'fields'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we can exclude'fields'from this array

constructor(props) {
super(props);
this.state = {
indexPatternForQuery: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the 'QueryBar' works with the index pattern object but not sure that we should add one more field for storing index pattern value.

I offer you 2 different ways:

  1. create a wrapper upper the 'QueryBar' component and move all this logic related to uiQueryLanguage and indexPatternForQuery to this component. It helps you to remove all code duplication
  2. more complex way. TSVB should work with index pattern object instead of string value of index pattern. But I see a lot of changes here.

@timroes @markov00 what do you think?

search_fields: ['title'],
});
const exactMatch = indexPatternsFromSavedObjects.savedObjects.find(
indexPattern => indexPattern.attributes.title === indexPatternString
Copy link
Contributor

Choose a reason for hiding this comment

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

TSVB allow us to work with wildcards e.g. kibana_*. Looks like for my example this method always return us false
Should we support this types of indexes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The QueryBar needs an exact index pattern for autocomplete and suggestions. If we allow a wildcard then we cannot be certain that the index pattern returned from getFromSavedObject is the one that we need.

@elasticmachine
Copy link
Contributor

💔 Build Failed

onChange={this.handleChange(model, 'query_string')}
value={model.query_string}
fullWidth
<QueryBar
Copy link
Contributor

Choose a reason for hiding this comment

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

@TinaHeiligers @Bargs Can we disable the refresh functionality for the QueryBar?

With this one we have 4 components which somehow related to the refresh functionality. Adding one more refresh button can confuse our users.
Also it's not working property with Auto-update. I expect that if user turn on this check-box next filter should be applying without pressing the refresh/update button.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that's already in progress.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@TinaHeiligers TinaHeiligers force-pushed the KQL_in_TSVB_rebased_May6_am branch from 51620a4 to 061a01d Compare May 18, 2019 19:56
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@TinaHeiligers
Copy link
Contributor Author

@alexwizp @Bargs would you mind if I address your comments in a new PR and close this one? I've had a nightmare time with rebasing all these commits against master. Since there's still a lot of work to be done, I've squash-merged the work to date into a new branch to continue with the work from there. It will make progress much quicker.

@alexwizp
Copy link
Contributor

Issue:

  1. Install kibana_sample_data_ecommerce (set as default index) and kibana_sample_data_logs sample data

  2. Create new TSVB visualization

  3. Go to TSVB panel options and type something in a Panel filter input.

    Important:
    We see fields related to default index pattern. It's correct

  4. Change index pattern to kibana_sample_data_logs and try to change value for Panel filter

image

async componentDidMount() {
await this.fetchIndexPatternsForQuery();
}
fetchIndexPatternsForQuery = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@TinaHeiligers I've checked that,
We have similar body for:

src/legacy/core_plugins/metrics/public/components/annotations_editor.js
src/legacy/core_plugins/metrics/public/components/panel_config/gauge.js
src/legacy/core_plugins/metrics/public/components/panel_config/markdown.js
src/legacy/core_plugins/metrics/public/components/panel_config/metric.js 
src/legacy/core_plugins/metrics/public/components/panel_config/table.js
src/legacy/core_plugins/metrics/public/components/panel_config/timeseries.js 
src/legacy/core_plugins/metrics/public/components/panel_config/top_n.js 
src/legacy/core_plugins/metrics/public/components/series.js

and only one different implementation for
src/legacy/core_plugins/metrics/public/components/split.js

I still think that we should somehow to reuse it

fullWidth
<QueryBar
query={{
language: model.filter.language ? model.filter.language : 'kuery',
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you use 'kuery' only here. In other places you use uiSettingsQueryLanguage. Is it correct?

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 will change it.

return <Component {...params} />;
}
return (
<div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure we need that extra div? I don't see any reason to refactor this this file

@alexwizp
Copy link
Contributor

@TinaHeiligers @Bargs From my point of view we should continue to work in scope of this PR.
But if you want to continue with that PR and merge it please get approval from @timroes / @markov00

@TinaHeiligers
Copy link
Contributor Author

TinaHeiligers commented May 21, 2019

@alexwizp Please hold off on reviewing while the WIP label is on this PR.
All comments will be addressed in #36784 opened in favor of this one.

@TinaHeiligers TinaHeiligers dismissed alexwizp’s stale review May 21, 2019 14:48

The work is still in progress and not ready for review yet

@TinaHeiligers TinaHeiligers mentioned this pull request May 21, 2019
4 tasks
@TinaHeiligers TinaHeiligers deleted the KQL_in_TSVB_rebased_May6_am branch October 14, 2020 15:56
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