-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
KQL support in filter ratio in TSVB #75033
Changes from 7 commits
33cc09e
e88b697
f1c790f
ee340b2
cfa58f2
4715136
75a9e08
aba3865
e1024e7
94fc2c2
60081d8
b682341
a35e0b5
e85ff76
93a533e
22a0071
84fe114
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,19 +24,19 @@ import { FieldSelect } from './field_select'; | |
import { AggRow } from './agg_row'; | ||
import { createChangeHandler } from '../lib/create_change_handler'; | ||
import { createSelectHandler } from '../lib/create_select_handler'; | ||
import { createTextHandler } from '../lib/create_text_handler'; | ||
import { | ||
htmlIdGenerator, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiFormLabel, | ||
EuiFieldText, | ||
EuiSpacer, | ||
EuiFormRow, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { KBN_FIELD_TYPES } from '../../../../../../plugins/data/public'; | ||
import { getSupportedFieldsByMetricType } from '../lib/get_supported_fields_by_metric_type'; | ||
import { getDefaultQueryLanguage } from '../lib/get_default_query_language'; | ||
import { QueryBarWrapper } from '../query_bar_wrapper'; | ||
|
||
const isFieldHistogram = (fields, indexPattern, field) => { | ||
const indexFields = fields[indexPattern]; | ||
|
@@ -51,13 +51,13 @@ export const FilterRatioAgg = (props) => { | |
|
||
const handleChange = createChangeHandler(props.onChange, props.model); | ||
const handleSelectChange = createSelectHandler(handleChange); | ||
const handleTextChange = createTextHandler(handleChange); | ||
const handleQueryChange = (name, value) => handleChange?.({ [name]: value }); | ||
alexwizp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const indexPattern = | ||
(series.override_index_pattern && series.series_index_pattern) || panel.index_pattern; | ||
|
||
const defaults = { | ||
numerator: '*', | ||
denominator: '*', | ||
numerator: { query: '', language: getDefaultQueryLanguage() }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to use |
||
denominator: { query: '', language: getDefaultQueryLanguage() }, | ||
metric_agg: 'count', | ||
}; | ||
|
||
|
@@ -101,7 +101,14 @@ export const FilterRatioAgg = (props) => { | |
/> | ||
} | ||
> | ||
<EuiFieldText onChange={handleTextChange('numerator')} value={model.numerator} /> | ||
<QueryBarWrapper | ||
query={{ | ||
alexwizp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
language: model.numerator.language, | ||
query: model.numerator.query, | ||
}} | ||
onChange={(query) => handleQueryChange('numerator', query)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used to wrap callbacks into
I know this won't give a lot of effect, since the |
||
indexPatterns={[indexPattern]} | ||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
|
||
|
@@ -115,7 +122,14 @@ export const FilterRatioAgg = (props) => { | |
/> | ||
} | ||
> | ||
<EuiFieldText onChange={handleTextChange('denominator')} value={model.denominator} /> | ||
<QueryBarWrapper | ||
query={{ | ||
language: model.denominator.language, | ||
query: model.denominator.query, | ||
}} | ||
onChange={(query) => handleQueryChange('denominator', query)} | ||
indexPatterns={[indexPattern]} | ||
/> | ||
</EuiFormRow> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,45 @@ const migratePercentileRankAggregation: SavedObjectMigrationFn<any, any> = (doc) | |
return doc; | ||
}; | ||
|
||
// [TSVB] Replace string query with object | ||
const migrateFilterRatioQuery: SavedObjectMigrationFn<any, any> = (doc) => { | ||
const visStateJSON = get(doc, 'attributes.visState'); | ||
let visState; | ||
|
||
if (visStateJSON) { | ||
try { | ||
visState = JSON.parse(visStateJSON); | ||
} catch (e) { | ||
// Let it go, the data is invalid and we'll leave it as is | ||
} | ||
if (visState && visState.type === 'metrics') { | ||
const series: any[] = get(visState, 'params.series') || []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume we can't avoid these anys here, right? 😢 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm not wrong it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh... sorry, it's a migration script. I'm ok to see |
||
|
||
series.forEach((part) => { | ||
(part.metrics || []).forEach((metric: any) => { | ||
if (metric.type === 'filter_ratio') { | ||
if (metric.numerator && typeof metric.numerator === 'string') { | ||
alexwizp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
metric.numerator = { query: metric.numerator, language: 'lucene' }; | ||
} | ||
if (metric.denominator && typeof metric.denominator === 'string') { | ||
metric.denominator = { query: metric.denominator, language: 'lucene' }; | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
return { | ||
...doc, | ||
attributes: { | ||
...doc.attributes, | ||
visState: JSON.stringify(visState), | ||
}, | ||
}; | ||
} | ||
} | ||
return doc; | ||
}; | ||
|
||
// [TSVB] Remove stale opperator key | ||
const migrateOperatorKeyTypo: SavedObjectMigrationFn<any, any> = (doc) => { | ||
const visStateJSON = get(doc, 'attributes.visState'); | ||
|
@@ -713,4 +752,5 @@ export const visualizationSavedObjectTypeMigrations = { | |
'7.4.2': flow(transformSplitFiltersStringToQueryObject), | ||
'7.7.0': flow(migrateOperatorKeyTypo, migrateSplitByChartRow), | ||
'7.8.0': flow(migrateTsvbDefaultColorPalettes), | ||
'7.10.0': flow(migrateFilterRatioQuery), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a
queryObject
variable to replace