Skip to content

Commit

Permalink
Move buildEsQuery to a package (elastic#23345)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lukasolson committed Nov 27, 2018
1 parent 75aa88e commit b233ff8
Show file tree
Hide file tree
Showing 128 changed files with 14,955 additions and 352 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ bower_components
/src/fixtures/vislib/mock_data
/src/ui/public/angular-bootstrap
/src/ui/public/flot-charts
/src/ui/public/kuery/ast/kuery.js
/src/ui/public/kuery/ast/legacy_kuery.js
/test/fixtures/scenarios
/src/core_plugins/console/public/webpackShims
/src/core_plugins/console/public/tests/webpackShims
Expand All @@ -19,6 +17,8 @@ bower_components
/packages/*/target
/packages/eslint-config-kibana
/packages/eslint-plugin-kibana-custom
/packages/kbn-es-query/src/kuery/ast/kuery.js
/packages/kbn-es-query/src/kuery/ast/legacy_kuery.js
/packages/kbn-pm/dist
/packages/kbn-plugin-generator/sao_template/template
/packages/kbn-ui-framework/dist
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"@kbn/babel-preset": "1.0.0",
"@kbn/config-schema": "1.0.0",
"@kbn/datemath": "5.0.0",
"@kbn/es-query": "1.0.0",
"@kbn/i18n": "1.0.0",
"@kbn/pm": "1.0.0",
"@kbn/test-subj-selector": "0.2.1",
Expand Down Expand Up @@ -406,4 +407,4 @@
"node": "8.11.4",
"yarn": "^1.10.1"
}
}
}
3 changes: 3 additions & 0 deletions packages/kbn-es-query/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@kbn/babel-preset/webpack_preset"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from 'ui/kuery/ast';
export * from './src';
20 changes: 20 additions & 0 deletions packages/kbn-es-query/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@kbn/es-query",
"main": "target/index.js",
"version": "1.0.0",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "babel src --out-dir target",
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
},
"dependencies": {
"lodash": "npm:@elastic/lodash@3.10.1-kibana1"
},
"devDependencies": {
"@kbn/babel-preset": "1.0.0",
"babel-cli": "^6.26.0",
"expect.js": "0.3.1"
}
}
5 changes: 5 additions & 0 deletions packages/kbn-es-query/src/__fixtures__/filter_skeleton.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"meta": {
"index": "logstash-*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"id": "logstash-*",
"title": "logstash-*",
"fields": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,23 @@
* under the License.
*/

import expect from 'expect.js';
import { BuildESQueryProvider } from '../build_es_query';
import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import ngMock from 'ng_mock';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';
import { fromKueryExpression, toElasticsearchQuery } from '../../../../kuery';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import { fromKueryExpression, toElasticsearchQuery } from '../../kuery';
import { luceneStringToDsl } from '../lucene_string_to_dsl';
import { decorateQuery } from '../../decorate_query';
import { decorateQuery } from '../decorate_query';

let indexPattern;
let buildEsQuery;

describe('build query', function () {
const configStub = { get: () => ({}) };
const privateStub = fn => fn(configStub);

describe('build query', function () {
describe('buildESQuery', function () {

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(StubbedLogstashIndexPatternProvider);
buildEsQuery = Private(BuildESQueryProvider);
}));
beforeEach(() => {
buildEsQuery = privateStub(BuildESQueryProvider);
});

it('should return the parameters of an Elasticsearch bool query', function () {
const result = buildEsQuery();
Expand All @@ -48,7 +45,7 @@ describe('build query', function () {
must_not: [],
}
};
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});

it('should combine queries and filters from multiple query languages into a single ES bool query', function () {
Expand All @@ -66,7 +63,7 @@ describe('build query', function () {
const expectedResult = {
bool: {
must: [
decorateQuery(luceneStringToDsl('bar:baz')),
decorateQuery(luceneStringToDsl('bar:baz'), configStub),
{ match_all: {} },
],
filter: [
Expand All @@ -79,7 +76,7 @@ describe('build query', function () {

const result = buildEsQuery(indexPattern, queries, filters);

expectDeepEqual(result, expectedResult);
expect(result).to.eql(expectedResult);
});

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
*/

import expect from 'expect.js';
import chrome from '../../../chrome';
import { decorateQuery } from '../decorate_query';

const config = chrome.getUiSettingsClient();
describe('Query decorator', function () {
const configStub = {
get: () => ({ analyze_wildcard: true })
};

describe('Query decorator', function () {
it('should be a function', function () {
expect(decorateQuery).to.be.a(Function);
});

it('should merge in the query string options', function () {
config.set('query:queryString:options', { analyze_wildcard: true });
const decoratedQuery = decorateQuery({ query_string: { query: '*' } });
const decoratedQuery = decorateQuery({ query_string: { query: '*' } }, configStub);
expect(decoratedQuery).to.eql({ query_string: { query: '*', analyze_wildcard: true } });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
* under the License.
*/

import expect from 'expect.js';
import { buildQueryFromFilters } from '../from_filters';
import { decorateQuery } from '../../decorate_query.js';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';

describe('build query', function () {

describe('buildQueryFromFilters', function () {

it('should return the parameters of an Elasticsearch bool query', function () {
const result = buildQueryFromFilters([]);
const expected = {
Expand All @@ -33,7 +31,7 @@ describe('build query', function () {
should: [],
must_not: [],
};
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});

it('should transform an array of kibana filters into ES queries combined in the bool clauses', function () {
Expand All @@ -53,9 +51,9 @@ describe('build query', function () {
{ exists: { field: 'foo' } }
];

const result = buildQueryFromFilters(filters, decorateQuery);
const result = buildQueryFromFilters(filters);

expectDeepEqual(result.must, expectedESQueries);
expect(result.must).to.eql(expectedESQueries);
});

it('should place negated filters in the must_not clause', function () {
Expand All @@ -70,9 +68,9 @@ describe('build query', function () {
{ match_all: {} },
];

const result = buildQueryFromFilters(filters, decorateQuery);
const result = buildQueryFromFilters(filters);

expectDeepEqual(result.must_not, expectedESQueries);
expect(result.must_not).to.eql(expectedESQueries);
});

it('should translate old ES filter syntax into ES 5+ query objects', function () {
Expand All @@ -89,9 +87,9 @@ describe('build query', function () {
}
];

const result = buildQueryFromFilters(filters, decorateQuery);
const result = buildQueryFromFilters(filters);

expectDeepEqual(result.must, expectedESQueries);
expect(result.must).to.eql(expectedESQueries);
});

it('should migrate deprecated match syntax', function () {
Expand All @@ -108,11 +106,9 @@ describe('build query', function () {
}
];

const result = buildQueryFromFilters(filters, decorateQuery);
const result = buildQueryFromFilters(filters);

expectDeepEqual(result.must, expectedESQueries);
expect(result.must).to.eql(expectedESQueries);
});

});

});
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,14 @@
*/

import { buildQueryFromKuery } from '../from_kuery';
import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import ngMock from 'ng_mock';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import expect from 'expect.js';
import { fromKueryExpression, toElasticsearchQuery } from '../../../../kuery';

let indexPattern;
import { fromKueryExpression, toElasticsearchQuery } from '../../kuery';

describe('build query', function () {
const configStub = { get: () => true };

describe('buildQueryFromKuery', function () {

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(StubbedLogstashIndexPatternProvider);
}));

it('should return the parameters of an Elasticsearch bool query', function () {
const result = buildQueryFromKuery(null, [], configStub);
const expected = {
Expand All @@ -44,7 +34,7 @@ describe('build query', function () {
should: [],
must_not: [],
};
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});

it('should transform an array of kuery queries into ES queries combined in the bool\'s filter clause', function () {
Expand All @@ -61,7 +51,7 @@ describe('build query', function () {

const result = buildQueryFromKuery(indexPattern, queries, configStub);

expectDeepEqual(result.filter, expectedESQueries);
expect(result.filter).to.eql(expectedESQueries);
});

it('should throw a useful error if it looks like query is using an old, unsupported syntax', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* under the License.
*/

import expect from 'expect.js';
import { buildQueryFromLucene } from '../from_lucene';
import { decorateQuery } from '../../decorate_query';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal';
import { decorateQuery } from '../decorate_query';
import { luceneStringToDsl } from '../lucene_string_to_dsl';

const configStub = { get: () => ({}) };

describe('build query', function () {

Expand All @@ -35,7 +36,7 @@ describe('build query', function () {
should: [],
must_not: [],
};
expectDeepEqual(result, expected);
expect(result).to.eql(expected);
});

it('should transform an array of lucene queries into ES queries combined in the bool\'s must clause', function () {
Expand All @@ -46,23 +47,23 @@ describe('build query', function () {

const expectedESQueries = queries.map(
(query) => {
return decorateQuery(luceneStringToDsl(query.query));
return decorateQuery(luceneStringToDsl(query.query), configStub);
}
);

const result = buildQueryFromLucene(queries, decorateQuery);
const result = buildQueryFromLucene(queries, configStub);

expectDeepEqual(result.must, expectedESQueries);
expect(result.must).to.eql(expectedESQueries);
});

it('should also accept queries in ES query DSL format, simply passing them through', function () {
const queries = [
{ query: { match_all: {} }, language: 'lucene' },
];

const result = buildQueryFromLucene(queries, decorateQuery);
const result = buildQueryFromLucene(queries, configStub);

expectDeepEqual(result.must, [queries[0].query]);
expect(result.must).to.eql([queries[0].query]);
});

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { luceneStringToDsl } from '../lucene_string_to_dsl';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';
import expect from 'expect.js';

describe('build query', function () {
Expand All @@ -30,23 +29,23 @@ describe('build query', function () {
const expectedResult = {
query_string: { query: 'foo:bar' }
};
expectDeepEqual(result, expectedResult);
expect(result).to.eql(expectedResult);
});

it('should return a match_all query for empty strings and whitespace', function () {
const expectedResult = {
match_all: {}
};

expectDeepEqual(luceneStringToDsl(''), expectedResult);
expectDeepEqual(luceneStringToDsl(' '), expectedResult);
expect(luceneStringToDsl('')).to.eql(expectedResult);
expect(luceneStringToDsl(' ')).to.eql(expectedResult);
});

it('should return non-string arguments without modification', function () {
const expectedResult = {};
const result = luceneStringToDsl(expectedResult);
expect(result).to.be(expectedResult);
expectDeepEqual(result, expectedResult);
expect(result).to.eql(expectedResult);
});

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { groupBy, has } from 'lodash';
import { decorateQuery } from '../decorate_query';
import { buildQueryFromKuery } from './from_kuery';
import { buildQueryFromFilters } from './from_filters';
import { buildQueryFromLucene } from './from_lucene';
Expand All @@ -35,8 +34,8 @@ export function BuildESQueryProvider(config) {
const queriesByLanguage = groupBy(validQueries, 'language');

const kueryQuery = buildQueryFromKuery(indexPattern, queriesByLanguage.kuery, config);
const luceneQuery = buildQueryFromLucene(queriesByLanguage.lucene, decorateQuery);
const filterQuery = buildQueryFromFilters(filters, decorateQuery, indexPattern);
const luceneQuery = buildQueryFromLucene(queriesByLanguage.lucene, config);
const filterQuery = buildQueryFromFilters(filters, indexPattern, config);

return {
bool: {
Expand Down
Loading

0 comments on commit b233ff8

Please sign in to comment.