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

[1.x][Bug] Restore timeline legacy functions and filters #827

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export default new Datasource('es', {
description: '"date" is a field type and should not be translated.',
}),
},
{
name: 'kibana',
types: ['boolean', 'null'],
help: i18n.translate('timeline.help.functions.opensearch.args.opensearchDashboardsHelpText', {
defaultMessage:
'Respect filters on OpenSearch Dashboards dashboards. Only has an effect when using on OpenSearch Dashboards dashboards',
}),
},
{
name: 'opensearchDashboards',
types: ['boolean', 'null'],
Expand All @@ -110,14 +118,15 @@ export default new Datasource('es', {
help: i18n.translate('timeline.help.functions.opensearchHelpText', {
defaultMessage: 'Pull data from an opensearch instance',
}),
aliases: ['es'],
aliases: ['elasticsearch', 'opensearch'],
fn: async function opensearchFn(args, tlConfig) {
const config = _.defaults(_.clone(args.byName), {
q: '*',
metric: ['count'],
index: tlConfig.settings['timeline:es.default_index'],
timefield: tlConfig.settings['timeline:es.timefield'],
interval: tlConfig.time.interval,
kibana: true,
opensearchDashboards: true,
fit: 'nearest',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export default function buildRequest(config, tlConfig, scriptedFields, timeout)
};
bool.must.push(timeFilter);

// Use the opensearchDashboards filter bar filters
if (config.opensearchDashboards) {
bool.filter = _.get(tlConfig, 'request.body.extended.opensearch.filter');
// Use the opensearchDashboards and kibana filter bar filters
if (config.opensearchDashboards && config.kibana) {
bool.filter = _.get(tlConfig, 'request.body.extended.es.filter');
}

const aggs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('opensearch', () => {
request: {
body: {
extended: {
opensearch: {
es: {
filter: {
bool: {
must: [{ query: { query_string: { query: 'foo' } } }],
Expand All @@ -281,8 +281,9 @@ describe('opensearch', () => {
});
});

it('adds the contents of body.extended.opensearch.filter to a filter clause of the bool', () => {
it('adds the contents of body.extended.es.filter to a filter clause of the bool', () => {
config.opensearchDashboards = true;
config.kibana = true;
const request = fn(config, tlConfig, emptyScriptedFields);
const filter = request.params.body.query.bool.filter.bool;
expect(filter.must.length).to.eql(1);
Expand All @@ -291,6 +292,21 @@ describe('opensearch', () => {

it('does not include filters if config.opensearchDashboards = false', () => {
config.opensearchDashboards = false;
config.kibana = true;
const request = fn(config, tlConfig, emptyScriptedFields);
expect(request.params.body.query.bool.filter).to.eql(undefined);
});

it('does not include filters if config.kibana = false', () => {
config.opensearchDashboards = true;
config.kibana = false;
const request = fn(config, tlConfig, emptyScriptedFields);
expect(request.params.body.query.bool.filter).to.eql(undefined);
});

it('does not include filters if config.opensearchDashboards = false and config.kibana = false', () => {
config.opensearchDashboards = false;
config.kibana = false;
const request = fn(config, tlConfig, emptyScriptedFields);
expect(request.params.body.query.bool.filter).to.eql(undefined);
});
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/timeline/_expression_typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function ({ getPageObjects }) {
await PageObjects.timeline.setExpression('.es');
await PageObjects.timeline.clickSuggestion();
const suggestions = await PageObjects.timeline.getSuggestionItemsText();
expect(suggestions.length).to.eql(9);
expect(suggestions.length).to.eql(10);
expect(suggestions[0].includes('fit=')).to.eql(true);
});

Expand Down