Skip to content

Commit

Permalink
use canvas pipeline in visualize (#25996)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Dec 10, 2018
1 parent d86996b commit ef7cf4b
Show file tree
Hide file tree
Showing 39 changed files with 2,011 additions and 48 deletions.
4 changes: 4 additions & 0 deletions packages/kbn-interpreter/src/plugin/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { render } from './render';
import { shape } from './shape';
import { string } from './string';
import { style } from './style';
import { kibanaTable } from './kibana_table';
import { kibanaContext } from './kibana_context';

export const typeSpecs = [
boolean,
Expand All @@ -43,4 +45,6 @@ export const typeSpecs = [
shape,
string,
style,
kibanaTable,
kibanaContext,
];
36 changes: 36 additions & 0 deletions packages/kbn-interpreter/src/plugin/types/kibana_context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const kibanaContext = () => ({
name: 'kibana_context',
from: {
null: () => {
return {
type: 'kibana_context',
};
},
},
to: {
null: () => {
return {
type: 'null',
};
},
}
});
41 changes: 41 additions & 0 deletions packages/kbn-interpreter/src/plugin/types/kibana_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const kibanaTable = () => ({
name: 'kibana_table',
serialize: context => {
context.columns.forEach(column => {
column.aggConfig = column.aggConfig.toJSON();
});
return context;
},
validate: tabify => {
if (!tabify.columns) {
throw new Error('tabify must have a columns array, even if it is empty');
}
},
from: {
null: () => {
return {
type: 'kibana_table',
columns: [],
};
},
},
});
2 changes: 1 addition & 1 deletion packages/kbn-interpreter/src/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

export { populateBrowserRegistries, getBrowserRegistries } from './browser_registries';
export { createSocket } from './socket';
export { initializeInterpreter, interpretAst } from './interpreter';
export { initializeInterpreter, interpretAst, getInitializedFunctions } from './interpreter';
8 changes: 6 additions & 2 deletions packages/kbn-interpreter/src/public/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ export async function initializeInterpreter() {
return functionList;
}

export async function getInitializedFunctions() {
return functionList;
}

// Use the above promise to seed the interpreter with the functions it can defer to
export async function interpretAst(ast, context) {
export async function interpretAst(ast, context, handlers) {
// Load plugins before attempting to get functions, otherwise this gets racey
return Promise.all([functionList, getBrowserRegistries()])
.then(([serverFunctionList]) => {
return socketInterpreterProvider({
types: typesRegistry.toJS(),
handlers: createHandlers(socket),
handlers: { ...handlers, ...createHandlers(socket) },
functions: functionsRegistry.toJS(),
referableFunctions: serverFunctionList,
socket: socket,
Expand Down
97 changes: 97 additions & 0 deletions src/legacy/core_plugins/interpreter/public/functions/esaggs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import { CourierRequestHandlerProvider } from 'ui/vis/request_handlers/courier';
import { AggConfigs } from 'ui/vis/agg_configs';

// need to get rid of angular from these
import { IndexPatternsProvider } from 'ui/index_patterns';
import { SearchSourceProvider } from 'ui/courier/search_source';
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';

import chrome from 'ui/chrome';

const courierRequestHandlerProvider = CourierRequestHandlerProvider;
const courierRequestHandler = courierRequestHandlerProvider().handler;

export const esaggs = () => ({
name: 'esaggs',
type: 'kibana_table',
context: {
types: [
'kibana_context',
'null',
],
},
help: i18n.translate('common.core_plugins.interpreter.public.functions.esaggs.help', { defaultMessage: 'Run AggConfig aggregation' }),
args: {
index: {
types: ['string', 'null'],
default: null,
},
metricsAtAllLevels: {
types: ['boolean'],
default: false,
},
partialRows: {
types: ['boolean'],
default: false,
},
aggConfigs: {
types: ['string'],
default: '""',
},
},
async fn(context, args, handlers) {
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private = $injector.get('Private');
const indexPatterns = Private(IndexPatternsProvider);
const SearchSource = Private(SearchSourceProvider);
const queryFilter = Private(FilterBarQueryFilterProvider);

const aggConfigsState = JSON.parse(args.aggConfigs);
const indexPattern = await indexPatterns.get(args.index);
const aggs = new AggConfigs(indexPattern, aggConfigsState);

// we should move searchSource creation inside courier request handler
const searchSource = new SearchSource();
searchSource.setField('index', indexPattern);

const response = await courierRequestHandler({
searchSource: searchSource,
aggs: aggs,
timeRange: get(context, 'timeRange', null),
query: get(context, 'query', null),
filters: get(context, 'filters', null),
forceFetch: true,
isHierarchical: args.metricsAtAllLevels,
partialRows: args.partialRows,
inspectorAdapters: handlers.inspectorAdapters,
queryFilter,
});

return {
type: 'kibana_table',
index: args.index,
...response,
};
},
});
40 changes: 40 additions & 0 deletions src/legacy/core_plugins/interpreter/public/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { esaggs } from './esaggs';
import { kibana } from './kibana';
import { kibanaContext } from './kibana_context';
import { vega } from './vega';
import { timelionVis } from './timelion_vis';
import { tsvb } from './tsvb';
import { kibanaMarkdown } from './markdown';
import { inputControlVis } from './input_control';
import { metric } from './metric';
import { kibanaPie } from './pie';
import { regionmap } from './regionmap';
import { tilemap } from './tilemap';
import { kibanaTable } from './table';
import { tagcloud } from './tagcloud';
import { vislib } from './vislib';
import { visualization } from './visualization';

export const functions = [
esaggs, kibana, kibanaContext, vega, timelionVis, tsvb, kibanaMarkdown, inputControlVis,
metric, kibanaPie, regionmap, tilemap, kibanaTable, tagcloud, vislib, visualization
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { i18n } from '@kbn/i18n';

export const inputControlVis = () => ({
name: 'input_control_vis',
type: 'render',
context: {
types: [],
},
help: i18n.translate('common.core_plugins.interpreter.public.functions.input_control.help', {
defaultMessage: 'Input control visualization'
}),
args: {
visConfig: {
types: ['string'],
default: '"{}"',
}
},
fn(context, args) {
const params = JSON.parse(args.visConfig);
return {
type: 'render',
as: 'visualization',
value: {
visConfig: {
type: 'input_controls_vis',
params: params
},
}
};
}
});
51 changes: 51 additions & 0 deletions src/legacy/core_plugins/interpreter/public/functions/kibana.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { i18n } from '@kbn/i18n';

export const kibana = () => ({
name: 'kibana',
type: 'kibana_context',
context: {},
help: i18n.translate('common.core_plugins.interpreter.public.functions.kibana.help', {
defaultMessage: 'Gets kibana global context'
}),
args: {},
fn(context, args, handlers) {
const initialContext = handlers.getInitialContext ? handlers.getInitialContext() : {};

if (context.query) {
initialContext.query = initialContext.query.concat(context.query);
}

if (context.filters) {
initialContext.filters = initialContext.filters.concat(context.filters);
}

const timeRange = initialContext.timeRange || context.timeRange;

return {
...context,
type: 'kibana_context',
query: initialContext.query,
filters: initialContext.filters,
timeRange: timeRange,
};
},
});
Loading

0 comments on commit ef7cf4b

Please sign in to comment.