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

visualize canvas pipeline #23185

Closed
wants to merge 8 commits into from
Closed
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
4 changes: 4 additions & 0 deletions packages/kbn-interpreter/plugin_src/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/plugin_src/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',
};
},
}
});
138 changes: 138 additions & 0 deletions packages/kbn-interpreter/plugin_src/types/kibana_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* 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 _ from 'lodash';

export const kibanaTable = () => ({
name: 'kibana_table',
serialize: context => {
context.columns.forEach(column => {
column.aggConfig = column.aggConfig.toJSON();
});
return context;
},
deserialize: () => {
// config.visData.columns.forEach(column => {
// column.aggConfig = new AggConfig(a, column.aggConfig);
// });
},
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: [],
};
},
datatable: context => {
const converted = {
columns: context.columns.map(column => {
return {
id: column.name,
title: column.name,
...column
};
}),
rows: context.rows.map(row => {
const crow = {};
context.columns.forEach(column => {
crow[column.name] = (row[column.name]);
});
return crow;
})
};
return {
type: 'kibana_table',
...converted,
};
},
number: context => {
return {
type: 'kibana_table',
columns: [{ id: 'col-0', title: 'Count' }],
rows: [{ 'col-0': context }]
};
},
pointseries: context => {
const converted = {
tables: [{
columns: _.map(context.columns, (column, name) => {
return {
title: column.name || name,
...column
};
}),
rows: context.rows.map(row => {
const crow = [];
_.each(context.columns, (column, i) => {
crow.push(row[i]);
});
return crow;
})
}]
};
return {
type: 'kibana_table',
value: converted,
};
}
},
to: {
datatable: context => {
const columns = context.columns.map(column => {
return { name: column.title, ...column };
});
const rows = context.rows.map(row => {
const converted = {};
columns.forEach((column) => {
converted[column.name] = row[column.id];
});
return converted;
});

return {
type: 'datatable',
columns: columns,
rows: rows,
};
},
pointseries: context => {
const columns = context.value.tables[0].columns.map(column => {
return { name: column.title, ...column };
});
const rows = context.value.tables[0].rows.map(row => {
const converted = {};
columns.forEach((column, i) => {
converted[column.name] = row[i];
});
return converted;
});

return {
type: 'pointseries',
columns: columns,
rows: rows,
};
}
}
});
4 changes: 2 additions & 2 deletions packages/kbn-interpreter/public/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export async function initialize() {
}

// 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
100 changes: 100 additions & 0 deletions src/core_plugins/interpreter/public/functions/esaggs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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 _ from 'lodash';
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 default () => ({
name: 'esaggs',
type: 'kibana_table',
context: {
types: [
'kibana_context',
'null',
],
},
help: 'Run AggConfig aggregation.',
args: {
index: {
types: ['string', 'null'],
default: null,
},
metricsAtAllLevels: {
types: ['boolean'],
default: false,
},
partialRows: {
types: ['boolean'],
default: false,
},
aggConfigs: {
types: ['string'],
default: '""',
help: 'AggConfig definition',
multi: false,
},
},
fn(context, args, handlers) {
return chrome.dangerouslyGetActiveInjector().then(async $injector => {
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,
};

});
},
});
32 changes: 32 additions & 0 deletions src/core_plugins/interpreter/public/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 visualization from './visualization';
import esaggs from './esaggs';
import kibana from './kibana';
import kibanaContext from './kibana_context';
import vega from './vega';
import timelion from './timelion_vis';
import tsvb from './tsvb';
import markdown from './markdown';
import inputControl from './input_control';

export const functions = [
visualization, esaggs, kibana, kibanaContext, vega, timelion, tsvb, markdown, inputControl
];
48 changes: 48 additions & 0 deletions src/core_plugins/interpreter/public/functions/input_control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 default () => ({
name: 'input_control_vis',
type: 'render',
context: {
types: [],
},
help: 'A input control visualization.',
args: {
visConfig: {
types: ['string'],
default: '"{}"',
help: 'markdown configuration object',
multi: false,
}
},
fn(context, args) {
const params = args.visConfig ? JSON.parse(args.visConfig) : {};
return {
type: 'render',
as: 'visualization',
value: {
visConfig: {
type: 'input_controls_vis',
params: params
},
}
};
}
});
Loading