Skip to content

Commit

Permalink
TSVB doesn't communicate it's index-patterns to dashboard (elastic#82964
Browse files Browse the repository at this point in the history
)

* TSVB doesn't communicate it's index-patterns to dashboard

Closes: elastic#81476

* useCustomSearchSource -> getUsedIndexPattern

* fix CI

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	src/plugins/vis_type_timeseries/public/metrics_type.ts
#	src/plugins/visualizations/public/embeddable/create_vis_embeddable_from_object.ts
#	src/plugins/visualizations/public/vis_types/base_vis_type.ts
#	src/plugins/visualizations/public/vis_types/types.ts
  • Loading branch information
alexwizp committed Dec 18, 2020
1 parent 5814610 commit 9fa2cc9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/plugins/vis_type_timeseries/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export const MAX_BUCKETS_SETTING = 'metrics:max_buckets';
export const INDEXES_SEPARATOR = ',';
16 changes: 16 additions & 0 deletions src/plugins/vis_type_timeseries/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,21 @@ export const metricsVisDefinition = {
return [VIS_EVENT_TO_TRIGGER.applyFilter];
},
inspectorAdapters: {},
getUsedIndexPattern: async (params: VisParams) => {
const { indexPatterns } = getDataStart();
const indexes: string = params.index_pattern;

if (indexes) {
const cachedIndexes = await indexPatterns.getIdsWithTitle();
const ids = indexes
.split(INDEXES_SEPARATOR)
.map((title) => cachedIndexes.find((i) => i.title === title)?.id)
.filter((id) => id);

return Promise.all(ids.map((id) => indexPatterns.get(id!)));
}

return [];
},
responseHandler: 'none',
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory';
import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants';
import { SavedVisualizationsLoader } from '../saved_visualizations';
import { AttributeService } from '../../../dashboard/public';
import { IndexPattern } from '../../../data/public';

export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDeps) => async (
vis: Vis,
Expand Down Expand Up @@ -66,8 +67,14 @@ export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDe
return new DisabledLabEmbeddable(vis.title, input);
}

const indexPattern = vis.data.indexPattern;
const indexPatterns = indexPattern ? [indexPattern] : [];
let indexPatterns: IndexPattern[] = [];

if (vis.type.getUsedIndexPattern) {
indexPatterns = await vis.type.getUsedIndexPattern(vis.params);
} else if (vis.data.indexPattern) {
indexPatterns = [vis.data.indexPattern];
}

const editable = getCapabilities().visualize.save as boolean;

return new VisualizeEmbeddable(
Expand Down
1 change: 0 additions & 1 deletion src/plugins/visualizations/public/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class Vis<TVisParams = VisParams> {
if (state.params || typeChanged) {
this.params = this.getParams(state.params);
}

if (state.data && state.data.searchSource) {
this.data.searchSource = await getSearch().searchSource.create(state.data.searchSource!);
this.data.indexPattern = this.data.searchSource.getField('index');
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/vis_types/base_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class BaseVisType<TVisParams = VisParams> implements VisType<TVisParams>
public readonly responseHandler;
public readonly hierarchicalData;
public readonly setup;
public readonly getUsedIndexPattern;
public readonly useCustomNoDataScreen;
public readonly inspectorAdapters;
public readonly toExpressionAst;
Expand Down Expand Up @@ -113,6 +114,7 @@ export class BaseVisType<TVisParams = VisParams> implements VisType<TVisParams>
this.responseHandler = opts.responseHandler ?? 'none';
this.setup = opts.setup;
this.hierarchicalData = opts.hierarchicalData ?? false;
this.getUsedIndexPattern = opts.getUsedIndexPattern;
this.useCustomNoDataScreen = opts.useCustomNoDataScreen ?? false;
this.inspectorAdapters = opts.inspectorAdapters;
this.toExpressionAst = opts.toExpressionAst;
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/visualizations/public/vis_types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { IconType } from '@elastic/eui';
import React from 'react';
import { Adapters } from 'src/plugins/inspector';
import { IndexPattern } from 'src/plugins/data/public';
import { ISchemas } from 'src/plugins/vis_default_editor/public';
import { TriggerContextMapping } from '../../../ui_actions/public';
import { Vis, VisToExpressionAst, VisualizationControllerConstructor } from '../types';
Expand Down Expand Up @@ -62,6 +63,13 @@ export interface VisType<TVisParams = unknown> {
readonly toExpressionAst?: VisToExpressionAst<TVisParams>;
readonly visualization?: VisualizationControllerConstructor;

/**
* Some visualizations are created without SearchSource and may change the used indexes during the visualization configuration.
* Using this method we can rewrite the standard mechanism for getting used indexes
*/
readonly getUsedIndexPattern?: (visParams: VisParams) => IndexPattern[] | Promise<IndexPattern[]>;


readonly setup?: (vis: Vis<TVisParams>) => Promise<Vis<TVisParams>>;
hidden: boolean;

Expand Down

0 comments on commit 9fa2cc9

Please sign in to comment.