Skip to content

Commit

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

* TSVB doesn't communicate it's index-patterns to dashboard (#82964)

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

Closes: #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

* fix CI
  • Loading branch information
alexwizp authored Dec 18, 2020
1 parent 5814610 commit 1723328
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ export declare class IndexPattern implements IIndexPattern
| [getTimeField()](./kibana-plugin-plugins-data-public.indexpattern.gettimefield.md) | | |
| [isTimeBased()](./kibana-plugin-plugins-data-public.indexpattern.istimebased.md) | | |
| [isTimeNanosBased()](./kibana-plugin-plugins-data-public.indexpattern.istimenanosbased.md) | | |
<<<<<<< HEAD
| [isUnsupportedTimePattern()](./kibana-plugin-plugins-data-public.indexpattern.isunsupportedtimepattern.md) | | |
| [popularizeField(fieldName, unit)](./kibana-plugin-plugins-data-public.indexpattern.popularizefield.md) | | |
=======
>>>>>>> cdb922f2a2... Move indexPattern.popularizeField into discover (#77668)
| [removeScriptedField(fieldName)](./kibana-plugin-plugins-data-public.indexpattern.removescriptedfield.md) | | Remove scripted field from field list |
| [toSpec()](./kibana-plugin-plugins-data-public.indexpattern.tospec.md) | | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternsService](./kibana-plugin-plugins-data-public.indexpatternsservice.md) &gt; [find](./kibana-plugin-plugins-data-public.indexpatternsservice.find.md)

## IndexPatternsService.find property

<b>Signature:</b>

```typescript
find: (search: string, size?: number) => Promise<IndexPattern[]>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export declare class IndexPatternsService
| [clearCache](./kibana-plugin-plugins-data-public.indexpatternsservice.clearcache.md) | | <code>(id?: string &#124; undefined) =&gt; void</code> | Clear index pattern list cache |
| [ensureDefaultIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.ensuredefaultindexpattern.md) | | <code>EnsureDefaultIndexPattern</code> | |
| [fieldArrayToMap](./kibana-plugin-plugins-data-public.indexpatternsservice.fieldarraytomap.md) | | <code>(fields: FieldSpec[]) =&gt; Record&lt;string, FieldSpec&gt;</code> | Converts field array to map |
| [find](./kibana-plugin-plugins-data-public.indexpatternsservice.find.md) | | <code>(search: string, size?: number) =&gt; Promise&lt;IndexPattern[]&gt;</code> | |
| [get](./kibana-plugin-plugins-data-public.indexpatternsservice.get.md) | | <code>(id: string) =&gt; Promise&lt;IndexPattern&gt;</code> | Get an index pattern by id. Cache optimized |
| [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
Expand All @@ -43,10 +44,6 @@ export declare class IndexPatternsService
| [createAndSave(spec, override, skipFetchFields)](./kibana-plugin-plugins-data-public.indexpatternsservice.createandsave.md) | | Create a new index pattern and save it right away |
| [createSavedObject(indexPattern, override)](./kibana-plugin-plugins-data-public.indexpatternsservice.createsavedobject.md) | | Save a new index pattern |
| [delete(indexPatternId)](./kibana-plugin-plugins-data-public.indexpatternsservice.delete.md) | | Deletes an index pattern from .kibana index |
<<<<<<< HEAD
| [migrate(indexPattern, newTitle)](./kibana-plugin-plugins-data-public.indexpatternsservice.migrate.md) | | |
| [updateSavedObject(indexPattern, saveAttempts)](./kibana-plugin-plugins-data-public.indexpatternsservice.updatesavedobject.md) | | Save existing index pattern. Will attempt to merge differences if there are conflicts |
=======
| [updateSavedObject(indexPattern, saveAttempts, ignoreErrors)](./kibana-plugin-plugins-data-public.indexpatternsservice.updatesavedobject.md) | | Save existing index pattern. Will attempt to merge differences if there are conflicts |
>>>>>>> cdb922f2a2... Move indexPattern.popularizeField into discover (#77668)

Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,20 @@ export class IndexPatternsService {
return indexPattern;
}

find = async (search: string, size: number = 10): Promise<IndexPattern[]> => {
const savedObjects = await this.savedObjectsClient.find<IndexPatternSavedObjectAttrs>({
type: 'index-pattern',
fields: ['title'],
search,
searchFields: ['title'],
perPage: size,
});
const getIndexPatternPromises = savedObjects.map(async (savedObject) => {
return await this.get(savedObject.id);
});
return await Promise.all(getIndexPatternPromises);
};

/**
* Create a new index pattern and save it right away
* @param spec
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,8 @@ export class IndexPatternsService {
// (undocumented)
ensureDefaultIndexPattern: EnsureDefaultIndexPattern;
fieldArrayToMap: (fields: FieldSpec[]) => Record<string, FieldSpec>;
// (undocumented)
find: (search: string, size?: number) => Promise<IndexPattern[]>;
get: (id: string) => Promise<IndexPattern>;
// Warning: (ae-forgotten-export) The symbol "IndexPatternSavedObjectAttrs" needs to be exported by the entry point index.d.ts
//
Expand Down
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 = ',';
6 changes: 6 additions & 0 deletions src/plugins/vis_type_timeseries/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { EditorController } from './application';
import { PANEL_TYPES } from '../common/panel_types';
import { VisEditor } from './application/components/vis_editor_lazy';
import { VIS_EVENT_TO_TRIGGER } from '../../visualizations/public';
import { getDataStart } from './services';

export const metricsVisDefinition = {
name: 'metrics',
Expand Down Expand Up @@ -83,5 +84,10 @@ export const metricsVisDefinition = {
return [VIS_EVENT_TO_TRIGGER.applyFilter];
},
inspectorAdapters: {},
getUsedIndexPattern: async (params: any) => {
const { indexPatterns } = getDataStart();

return params.index_pattern ? await indexPatterns.find(params.index_pattern) : [];
},
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
3 changes: 3 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 @@ -33,6 +33,7 @@ interface CommonBaseVisTypeOptions<TVisParams>
| 'icon'
| 'image'
| 'inspectorAdapters'
| 'getUsedIndexPattern'
| 'name'
| 'requestHandler'
| 'responseHandler'
Expand Down Expand Up @@ -86,6 +87,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 +115,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
9 changes: 9 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,14 @@ 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: TVisParams
) => IndexPattern[] | Promise<IndexPattern[]>;

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

Expand Down

0 comments on commit 1723328

Please sign in to comment.