Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/platform/plugins/shared/data_view_editor/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"data",
"dataViews"
],
"optionalPlugins": [
"cps"
],
"requiredBundles": [
"kibanaReact",
"kibanaUtils",
Expand Down
2 changes: 2 additions & 0 deletions src/platform/plugins/shared/data_view_editor/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dependsOn:
- '@kbn/code-editor'
- '@kbn/rollup'
- '@kbn/css-utils'
- '@kbn/cps-utils'
- '@kbn/cps'
tags:
- plugin
- prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const DataViewFlyoutContentContainer = ({
getDataViewHelpText,
}: DataViewEditorProps) => {
const {
services: { dataViews, notifications, http },
services: { dataViews, notifications, http, cps },
} = useKibana<DataViewEditorContext>();

const [dataViewEditorService] = useState(
() =>
new DataViewEditorService({
services: { http, dataViews },
services: { http, dataViews, cpsManager: cps?.cpsManager },
initialValues: {
name: editData?.name,
type: editData?.type as INDEX_PATTERN_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
DataViewField,
} from '@kbn/data-views-plugin/public';
import { INDEX_PATTERN_TYPE } from '@kbn/data-views-plugin/public';
import type { ICPSManager } from '@kbn/cps-utils';

import type {
RollupIndicesCapsResponse,
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface DataViewEditorServiceConstructorArgs {
services: {
http: HttpSetup;
dataViews: DataViewsServicePublic;
cpsManager?: ICPSManager;
};
/**
* Whether service requires requireTimestampField
Expand Down Expand Up @@ -93,7 +95,7 @@ export const stateSelectorFactory =

export class DataViewEditorService {
constructor({
services: { http, dataViews },
services: { http, dataViews, cpsManager },
initialValues: {
type: initialType = INDEX_PATTERN_TYPE.DEFAULT,
indexPattern: initialIndexPattern = '',
Expand All @@ -106,6 +108,7 @@ export class DataViewEditorService {
this.requireTimestampField = requireTimestampField;
this.type = initialType;
this.indexPattern = removeSpaces(initialIndexPattern);
this.cpsManager = cpsManager;

// fire off a couple of requests that we know we'll need
this.rollupCapsResponse = this.getRollupIndexCaps();
Expand Down Expand Up @@ -140,12 +143,20 @@ export class DataViewEditorService {
this.rollupIndexForProvider$.next(rollupIndex);
this.rollupIndexForProvider$.next(undefined);
});

// Subscribe to CPS project routing changes
if (cpsManager) {
this.cpsProjectRoutingSub = cpsManager.getProjectRouting$().subscribe(() => {
this.loadIndices();
});
}
}

private http: HttpSetup;
private dataViews: DataViewsServicePublic;
// config
private requireTimestampField: boolean;
private cpsManager?: ICPSManager;
private type = INDEX_PATTERN_TYPE.DEFAULT;

private indexPattern = '';
Expand All @@ -157,6 +168,7 @@ export class DataViewEditorService {
private loadTimestampFieldsSub: Subscription;
private matchedIndicesForProviderSub: Subscription;
private rollupIndexForProviderSub: Subscription;
private cpsProjectRoutingSub?: Subscription;

private state$: BehaviorSubject<DataViewEditorState>;

Expand Down Expand Up @@ -316,7 +328,8 @@ export class DataViewEditorService {
pattern: string;
showAllIndices?: boolean | undefined;
}) => {
const key = JSON.stringify(props);
const projectRouting = this.cpsManager?.getProjectRouting();
const key = JSON.stringify({ ...props, projectRouting });

this.getIndicesMemory[key] =
this.getIndicesMemory[key] ||
Expand Down Expand Up @@ -348,7 +361,8 @@ export class DataViewEditorService {
getFieldsOptions: GetFieldsOptions,
requireTimestampField: boolean
) => {
const key = JSON.stringify(getFieldsOptions) + requireTimestampField;
const projectRouting = this.cpsManager?.getProjectRouting();
const key = JSON.stringify({ getFieldsOptions, requireTimestampField, projectRouting });

const getTimestampOptionsPromise = this.getTimestampOptionsForWildcard(
getFieldsOptions,
Expand Down Expand Up @@ -423,5 +437,6 @@ export class DataViewEditorService {
this.loadTimestampFieldsSub.unsubscribe();
this.matchedIndicesForProviderSub.unsubscribe();
this.rollupIndexForProviderSub.unsubscribe();
this.cpsProjectRoutingSub?.unsubscribe();
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import React from 'react';
import type { CoreStart, OverlayRef } from '@kbn/core/public';
import type { DataView, DataViewsServicePublic } from '@kbn/data-views-plugin/public';
import type { CPSPluginStart } from '@kbn/cps/public';

import { toMountPoint } from '@kbn/react-kibana-mount';
import type { DataPublicPluginStart } from './shared_imports';
Expand All @@ -22,10 +23,11 @@ interface Dependencies {
core: CoreStart;
searchClient: DataPublicPluginStart['search']['search'];
dataViews: DataViewsServicePublic;
cps?: CPSPluginStart;
}

export const getEditorOpener =
({ core, searchClient, dataViews }: Dependencies) =>
({ core, searchClient, dataViews, cps }: Dependencies) =>
(options: DataViewEditorProps): CloseEditor => {
const { uiSettings, overlays, docLinks, notifications, http, application } = core;
const { Provider: KibanaReactContextProvider } =
Expand All @@ -38,6 +40,7 @@ export const getEditorOpener =
dataViews,
overlays,
searchClient,
cps,
});

let overlayRef: OverlayRef | null = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DataViewEditorPlugin

public start(core: CoreStart, plugins: StartPlugins) {
const { application, uiSettings, docLinks, http, notifications, overlays } = core;
const { data, dataViews } = plugins;
const { data, dataViews, cps } = plugins;

return {
/**
Expand All @@ -41,6 +41,7 @@ export class DataViewEditorPlugin
core,
dataViews,
searchClient: data.search.search,
cps,
}),
/**
* Data view editor flyout via react component
Expand All @@ -58,6 +59,7 @@ export class DataViewEditorPlugin
overlays,
dataViews,
searchClient: data.search.search,
cps,
}}
{...props}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
INDEX_PATTERN_TYPE,
MatchedItem,
} from '@kbn/data-views-plugin/public';
import type { CPSPluginStart } from '@kbn/cps/public';
import type { DataViewEditorService } from './data_view_editor_service';
import type { DataPublicPluginStart, IndexPatternAggRestrictions } from './shared_imports';

Expand All @@ -37,6 +38,7 @@ export interface DataViewEditorContext {
overlays: OverlayStart;
dataViews: DataViewsServicePublic;
searchClient: DataPublicPluginStart['search']['search'];
cps?: CPSPluginStart;
}

/** @public */
Expand Down Expand Up @@ -110,6 +112,7 @@ export interface SetupPlugins {}
export interface StartPlugins {
data: DataPublicPluginStart;
dataViews: DataViewsServicePublic;
cps?: CPSPluginStart;
}

export type CloseEditor = () => void;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/plugins/shared/data_view_editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"@kbn/code-editor",
"@kbn/rollup",
"@kbn/css-utils",
"@kbn/cps-utils",
"@kbn/cps",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,26 @@ export function registerResolveIndexRoute(router: IRouter): void {
schema.literal('none'),
])
),
project_routing: schema.maybe(schema.string()),
}),
},
},
async (context, req, res) => {
const esClient = (await context.core).elasticsearch.client;
try {
const body = await esClient.asCurrentUser.indices.resolveIndex({
const params = {
name: req.params.query,
expand_wildcards: req.query.expand_wildcards || 'open',
});
// TODO: we should be sending this param here and esClient should pass it to body but it is not yet supported in esClient
// ...(req.query.project_routing ? { project_routing: req.query.project_routing } : {}),
// so we do this for now:
...(req.query.project_routing
? { body: { project_routing: req.query.project_routing } }
: {}),
};

// @ts-ignore because the types for resolveIndex do not yet include body param
const body = await esClient.asCurrentUser.indices.resolveIndex(params);
return res.ok({ body });
} catch (e) {
// 403: no_such_remote_cluster_exception
Expand Down
3 changes: 2 additions & 1 deletion src/platform/plugins/shared/data_views/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"contentManagement"
],
"optionalPlugins": [
"usageCollection"
"usageCollection",
"cps"
],
"requiredBundles": [
"kibanaUtils"
Expand Down
1 change: 1 addition & 0 deletions src/platform/plugins/shared/data_views/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependsOn:
- '@kbn/logging-mocks'
- '@kbn/doc-links'
- '@kbn/core-deprecations-common'
- '@kbn/cps'
tags:
- plugin
- prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface DataViewsServicePublicDeps extends DataViewsServiceDeps {
pattern: string;
showAllIndices?: boolean;
isRollupIndex: (indexName: string) => boolean;
projectRouting?: string;
}) => Promise<MatchedItem[]>;

getRollupsEnabled: () => boolean;
Expand All @@ -52,6 +53,7 @@ export class DataViewsServicePublic extends DataViewsService {
pattern: string;
showAllIndices?: boolean;
isRollupIndex: (indexName: string) => boolean;
projectRouting?: string;
}) => Promise<MatchedItem[]>;
public hasData: HasDataService;
private rollupsEnabled: boolean = false;
Expand Down
10 changes: 8 additions & 2 deletions src/platform/plugins/shared/data_views/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class DataViewsPublicPlugin

public start(
core: CoreStart,
{ fieldFormats, contentManagement }: DataViewsPublicStartDependencies
{ fieldFormats, contentManagement, cps }: DataViewsPublicStartDependencies
): DataViewsPublicPluginStart {
const { uiSettings, http, notifications, application } = core;

Expand Down Expand Up @@ -106,7 +106,13 @@ export class DataViewsPublicPlugin
getCanSaveSync: () => application.capabilities.indexPatterns.save === true,
getCanSaveAdvancedSettings: () =>
Promise.resolve(application.capabilities.advancedSettings.save === true),
getIndices: (props) => getIndices({ ...props, http: core.http }),
getIndices: (props) =>
getIndices({
...props,
http: core.http,
projectRouting:
'projectRouting' in props ? props.projectRouting : cps?.cpsManager?.getProjectRouting(),
}),
getRollupsEnabled: () => this.rollupsEnabled,
scriptedFieldsEnabled: config.scriptedFieldsEnabled === false ? false : true, // accounting for null value
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { sortBy } from 'lodash';
import type { HttpStart } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { sanitizeProjectRoutingForES } from '@kbn/es-query';
import type { Tag } from '../types';
import { INDEX_PATTERN_TYPE } from '../types';
import type { MatchedItem, ResolveIndexResponse } from '../types';
Expand Down Expand Up @@ -48,18 +49,27 @@ export const getIndicesViaResolve = async ({
pattern,
showAllIndices,
isRollupIndex,
projectRouting,
}: {
http: HttpStart;
pattern: string;
showAllIndices: boolean;
isRollupIndex: (indexName: string) => boolean;
projectRouting?: string;
}) => {
const encodedPattern = encodeURIComponent(pattern);
const query: Record<string, string> = {};
if (showAllIndices) {
query.expand_wildcards = 'all';
}
if (projectRouting) {
query.project_routing = projectRouting;
}
return http
.get<ResolveIndexResponse>(
`/internal/index-pattern-management/resolve_index/${encodedPattern}`,
{
query: showAllIndices ? { expand_wildcards: 'all' } : undefined,
query: Object.keys(query).length > 0 ? query : undefined,
}
)
.then((response) => {
Expand All @@ -76,11 +86,13 @@ export async function getIndices({
pattern: rawPattern = '',
showAllIndices = false,
isRollupIndex,
projectRouting,
}: {
http: HttpStart;
pattern: string;
showAllIndices?: boolean;
isRollupIndex: (indexName: string) => boolean;
projectRouting?: string;
}): Promise<MatchedItem[]> {
const pattern = rawPattern.trim();

Expand All @@ -107,6 +119,7 @@ export async function getIndices({
pattern,
showAllIndices,
isRollupIndex,
projectRouting: sanitizeProjectRoutingForES(projectRouting),
}).catch(() => []);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function getIndices(props: {
pattern: string;
showAllIndices?: boolean;
isRollupIndex: (indexName: string) => boolean;
projectRouting?: string;
}): Promise<MatchedItem[]> {
const { getIndices: getIndicesLazy } = await import('./get_indices');
return getIndicesLazy(props);
Expand Down
6 changes: 6 additions & 0 deletions src/platform/plugins/shared/data_views/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
ContentManagementPublicSetup,
ContentManagementPublicStart,
} from '@kbn/content-management-plugin/public';
import type { CPSPluginStart } from '@kbn/cps/public';
import type { DataViewsServicePublicMethods } from './data_views';
import type { HasDataService } from '../common';

Expand Down Expand Up @@ -105,6 +106,10 @@ export interface DataViewsPublicStartDependencies {
* Content management
*/
contentManagement: ContentManagementPublicStart;
/**
* CPS plugin (optional)
*/
cps?: CPSPluginStart;
}

/**
Expand All @@ -121,6 +126,7 @@ export interface DataViewsServicePublic extends DataViewsServicePublicMethods {
pattern: string;
showAllIndices?: boolean;
isRollupIndex: (indexName: string) => boolean;
projectRouting?: string;
}) => Promise<MatchedItem[]>;
getRollupsEnabled: () => boolean;
scriptedFieldsEnabled: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/platform/plugins/shared/data_views/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@kbn/logging-mocks",
"@kbn/doc-links",
"@kbn/core-deprecations-common",
"@kbn/cps",
],
"exclude": [
"target/**/*",
Expand Down
Loading