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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e27ba53
fix: move buildEsQuery to utils
lukasolson Sep 19, 2018
1308202
fix: tests that I broke
lukasolson Sep 21, 2018
0480b9c
Merge branch 'master' into fix/filtersEverywhere
lukasolson Sep 24, 2018
72fbe52
Merge branch 'master' into fix/filtersEverywhere
lukasolson Oct 1, 2018
7c93a4b
fix: add back link to the docs
lukasolson Oct 1, 2018
391060f
fix: don't export from ui/ and link to utils
lukasolson Oct 2, 2018
fb63b64
Merge branch 'master' into fix/filtersEverywhere
lukasolson Oct 17, 2018
dafa660
Merge branch 'master' into fix/filtersEverywhere
lukasolson Oct 17, 2018
a96841a
fix: move to a package
lukasolson Oct 18, 2018
09a69ed
fix: move error to errors.js
lukasolson Oct 18, 2018
844037d
Merge branch 'master' into fix/filtersEverywhere
lukasolson Oct 18, 2018
96f133f
fix: paths for peg task
lukasolson Oct 18, 2018
a2fb932
Merge branch 'master' into fix/filtersEverywhere
lukasolson Oct 18, 2018
8f2480c
fix: update reference to kuery
lukasolson Oct 19, 2018
63d230d
fix: build step for transpilation
lukasolson Oct 22, 2018
3884518
fix: add typescript declaration file
lukasolson Oct 22, 2018
cb0aea2
Merge branch 'master' into fix/filtersEverywhere
lukasolson Oct 23, 2018
0a0a6d6
Merge branch 'master' into fix/filtersEverywhere
lukasolson Nov 2, 2018
09e4331
Merge branch 'master' into fix/filtersEverywhere
lukasolson Nov 2, 2018
b783ea9
fix: test
lukasolson Nov 2, 2018
36b4259
tmp: debug individual tests
lukasolson Nov 5, 2018
f124678
debug: add debug stuff for reporting tests
lukasolson Nov 5, 2018
d8bfa36
try to debug test
lukasolson Nov 6, 2018
414c311
Merge branch 'master' into fix/filtersEverywhere
lukasolson Nov 7, 2018
a13a749
Merge branch 'master' into fix/filtersEverywhere
lukasolson Nov 12, 2018
4fbac25
Merge branch 'master' into lukasolson/fix/filtersEverywhere
markov00 Nov 13, 2018
887c97a
Testing splitting reporting jobs in two
markov00 Nov 13, 2018
103ee2b
Testing splitting each job
markov00 Nov 13, 2018
d1d0970
Fix ci yaml
markov00 Nov 13, 2018
59f978f
Skipping job to check failing test
markov00 Nov 13, 2018
e36d7ab
debug - adding a catch to jobResponseHandler on report
markov00 Nov 14, 2018
f0149b1
Testing a different job and enabling verbose mode
markov00 Nov 14, 2018
99a8bc0
Testing verbose on phantom_api skipping other CI tests
markov00 Nov 14, 2018
245f72c
Fix script mode
markov00 Nov 14, 2018
991d46f
fix: try running tests in chromium
lukasolson Nov 14, 2018
04f5e37
fix: move out of devDependencies
lukasolson Nov 15, 2018
9fd38fe
fix: remove commented test
lukasolson Nov 15, 2018
7db5961
Revert "fix: try running tests in chromium"
lukasolson Nov 15, 2018
df364f0
Revert testing changes
markov00 Nov 19, 2018
408ddb4
Merge branch 'master' into pr/23345
markov00 Nov 19, 2018
ffa8657
Fixing build for phantomjs
markov00 Nov 20, 2018
ee4ddc2
Revert CI configuration to master. Remove verbose logging for tests
markov00 Nov 20, 2018
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
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 @@ -88,6 +88,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 @@ -384,4 +385,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/[email protected]"
},
"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,11 @@
* under the License.
*/

import expect from 'expect.js';
import { buildQueryFromFilters } from '../from_filters';
import ngMock from 'ng_mock';
import { expectDeepEqual } from '../../../../../../test_utils/expect_deep_equal.js';

describe('build query', function () {
describe('buildQueryFromFilters', function () {
beforeEach(ngMock.module('kibana'));

it('should return the parameters of an Elasticsearch bool query', function () {
const result = buildQueryFromFilters([]);
const expected = {
Expand All @@ -33,7 +30,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 @@ -55,7 +52,7 @@ describe('build query', function () {

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,7 +67,7 @@ describe('build query', function () {

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,7 +86,7 @@ describe('build query', function () {

const result = buildQueryFromFilters(filters);

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

it('should migrate deprecated match syntax', function () {
Expand All @@ -108,7 +105,7 @@ describe('build query', function () {

const result = buildQueryFromFilters(filters);

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

it('should not add query:queryString:options to query_string filters', function () {
Expand All @@ -122,7 +119,7 @@ describe('build query', function () {

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,7 +34,7 @@ export function BuildESQueryProvider(config) {
const queriesByLanguage = groupBy(validQueries, 'language');

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

return {
Expand Down
Loading