Skip to content

Commit

Permalink
[7.8] Removes legacy infra plugin and moves saved objects registratio…
Browse files Browse the repository at this point in the history
…n to NP (#64848) (#65530)
  • Loading branch information
jasonrhodes committed May 6, 2020
1 parent 912bab4 commit 3d43166
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 101 deletions.
2 changes: 0 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { dashboardMode } from './legacy/plugins/dashboard_mode';
import { beats } from './legacy/plugins/beats_management';
import { maps } from './legacy/plugins/maps';
import { spaces } from './legacy/plugins/spaces';
import { infra } from './legacy/plugins/infra';
import { taskManager } from './legacy/plugins/task_manager';
import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects';
import { ingestManager } from './legacy/plugins/ingest_manager';
Expand All @@ -27,7 +26,6 @@ module.exports = function(kibana) {
dashboardMode(kibana),
beats(kibana),
maps(kibana),
infra(kibana),
taskManager(kibana),
encryptedSavedObjects(kibana),
ingestManager(kibana),
Expand Down
25 changes: 0 additions & 25 deletions x-pack/legacy/plugins/infra/index.ts

This file was deleted.

20 changes: 10 additions & 10 deletions x-pack/plugins/infra/common/saved_objects/inventory_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ElasticsearchMappingOf } from '../../server/utils/typed_elasticsearch_mappings';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { WaffleViewState } from '../../public/pages/metrics/inventory_view/hooks/use_waffle_view_state';
import { SavedObjectsType } from 'src/core/server';

export const inventoryViewSavedObjectType = 'inventory-view';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { SavedViewSavedObject } from '../../public/hooks/use_saved_view';
export const inventoryViewSavedObjectName = 'inventory-view';

export const inventoryViewSavedObjectMappings: {
[inventoryViewSavedObjectType]: ElasticsearchMappingOf<SavedViewSavedObject<WaffleViewState>>;
} = {
[inventoryViewSavedObjectType]: {
export const inventoryViewSavedObjectType: SavedObjectsType = {
name: inventoryViewSavedObjectName,
hidden: false,
namespaceType: 'single',
management: {
importableAndExportable: true,
},
mappings: {
properties: {
name: {
type: 'keyword',
Expand Down
32 changes: 10 additions & 22 deletions x-pack/plugins/infra/common/saved_objects/metrics_explorer_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,18 @@
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ElasticsearchMappingOf } from '../../server/utils/typed_elasticsearch_mappings';
import {
MetricsExplorerOptions,
MetricsExplorerChartOptions,
MetricsExplorerTimeOptions,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../public/pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { SavedViewSavedObject } from '../../public/hooks/use_saved_view';

interface MetricsExplorerSavedView {
options: MetricsExplorerOptions;
chartOptions: MetricsExplorerChartOptions;
currentTimerange: MetricsExplorerTimeOptions;
}
import { SavedObjectsType } from 'src/core/server';

export const metricsExplorerViewSavedObjectType = 'metrics-explorer-view';
export const metricsExplorerViewSavedObjectName = 'metrics-explorer-view';

export const metricsExplorerViewSavedObjectMappings: {
[metricsExplorerViewSavedObjectType]: ElasticsearchMappingOf<
SavedViewSavedObject<MetricsExplorerSavedView>
>;
} = {
[metricsExplorerViewSavedObjectType]: {
export const metricsExplorerViewSavedObjectType: SavedObjectsType = {
name: metricsExplorerViewSavedObjectName,
hidden: false,
namespaceType: 'single',
management: {
importableAndExportable: true,
},
mappings: {
properties: {
name: {
type: 'keyword',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import React from 'react';
import { SavedViewsToolbarControls } from '../../../../components/saved_views/toolbar_control';
import { inventoryViewSavedObjectType } from '../../../../../common/saved_objects/inventory_view';
import { inventoryViewSavedObjectName } from '../../../../../common/saved_objects/inventory_view';
import { useWaffleViewState } from '../hooks/use_waffle_view_state';

export const SavedViews = () => {
Expand All @@ -15,7 +15,7 @@ export const SavedViews = () => {
defaultViewState={defaultViewState}
viewState={viewState}
onViewChange={onViewChange}
viewType={inventoryViewSavedObjectType}
viewType={inventoryViewSavedObjectName}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { MetricsExplorerAggregationPicker } from './aggregation';
import { MetricsExplorerChartOptions as MetricsExplorerChartOptionsComponent } from './chart_options';
import { SavedViewsToolbarControls } from '../../../../components/saved_views/toolbar_control';
import { MetricExplorerViewState } from '../hooks/use_metric_explorer_state';
import { metricsExplorerViewSavedObjectType } from '../../../../../common/saved_objects/metrics_explorer_view';
import { metricsExplorerViewSavedObjectName } from '../../../../../common/saved_objects/metrics_explorer_view';
import { useKibanaUiSetting } from '../../../../utils/use_kibana_ui_setting';
import { mapKibanaQuickRangesToDatePickerRanges } from '../../../../utils/map_timepicker_quickranges_to_datepicker_ranges';
import { ToolbarPanel } from '../../../../components/toolbar_panel';
Expand Down Expand Up @@ -129,7 +129,7 @@ export const MetricsExplorerToolbar = ({
chartOptions,
currentTimerange: timeRange,
}}
viewType={metricsExplorerViewSavedObjectType}
viewType={metricsExplorerViewSavedObjectName}
onViewChange={onViewStateChange}
/>
</EuiFlexItem>
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/infra/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

import { PluginInitializerContext } from 'src/core/server';
import { config, InfraConfig, InfraServerPlugin, InfraPluginSetup } from './plugin';
import { savedObjectMappings } from './saved_objects';

export { config, InfraConfig, savedObjectMappings, InfraPluginSetup };
export { config, InfraConfig, InfraPluginSetup };

export function plugin(context: PluginInitializerContext) {
return new InfraServerPlugin(context);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/infra/server/lib/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
*/

export * from './defaults';
export * from './saved_object_mappings';
export { infraSourceConfigurationSavedObjectType } from './saved_object_type';
export * from './sources';
export * from '../../../common/http_api/source_api';
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ElasticsearchMappingOf } from '../../utils/typed_elasticsearch_mappings';
import { InfraSavedSourceConfiguration } from '../../../common/http_api/source_api';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { SavedObjectsType } from 'src/core/server';

export const infraSourceConfigurationSavedObjectType = 'infrastructure-ui-source';
export const infraSourceConfigurationSavedObjectName = 'infrastructure-ui-source';

export const infraSourceConfigurationSavedObjectMappings: {
[infraSourceConfigurationSavedObjectType]: ElasticsearchMappingOf<InfraSavedSourceConfiguration>;
} = {
[infraSourceConfigurationSavedObjectType]: {
export const infraSourceConfigurationSavedObjectType: SavedObjectsType = {
name: infraSourceConfigurationSavedObjectName,
hidden: false,
namespaceType: 'single',
management: {
importableAndExportable: true,
},
mappings: {
properties: {
name: {
type: 'text',
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/infra/server/lib/sources/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { map, fold } from 'fp-ts/lib/Either';
import { SavedObjectsClientContract } from 'src/core/server';
import { defaultSourceConfiguration } from './defaults';
import { NotFoundError } from './errors';
import { infraSourceConfigurationSavedObjectType } from './saved_object_mappings';
import { infraSourceConfigurationSavedObjectName } from './saved_object_type';
import {
InfraSavedSourceConfiguration,
InfraSourceConfiguration,
Expand Down Expand Up @@ -108,7 +108,7 @@ export class InfraSources {

const createdSourceConfiguration = convertSavedObjectToSavedSourceConfiguration(
await savedObjectsClient.create(
infraSourceConfigurationSavedObjectType,
infraSourceConfigurationSavedObjectName,
pickSavedSourceConfiguration(newSourceConfiguration) as any,
{ id: sourceId }
)
Expand All @@ -127,7 +127,7 @@ export class InfraSources {
savedObjectsClient: SavedObjectsClientContract,
sourceId: string
) {
await savedObjectsClient.delete(infraSourceConfigurationSavedObjectType, sourceId);
await savedObjectsClient.delete(infraSourceConfigurationSavedObjectName, sourceId);
}

public async updateSourceConfiguration(
Expand All @@ -149,7 +149,7 @@ export class InfraSources {

const updatedSourceConfiguration = convertSavedObjectToSavedSourceConfiguration(
await savedObjectsClient.update(
infraSourceConfigurationSavedObjectType,
infraSourceConfigurationSavedObjectName,
sourceId,
pickSavedSourceConfiguration(updatedSourceConfigurationAttributes) as any,
{
Expand Down Expand Up @@ -207,7 +207,7 @@ export class InfraSources {
sourceId: string
) {
const savedObject = await savedObjectsClient.get(
infraSourceConfigurationSavedObjectType,
infraSourceConfigurationSavedObjectName,
sourceId
);

Expand All @@ -216,7 +216,7 @@ export class InfraSources {

private async getAllSavedSourceConfigurations(savedObjectsClient: SavedObjectsClientContract) {
const savedObjects = await savedObjectsClient.find({
type: infraSourceConfigurationSavedObjectType,
type: infraSourceConfigurationSavedObjectName,
});

return savedObjects.saved_objects.map(convertSavedObjectToSavedSourceConfiguration);
Expand Down
15 changes: 8 additions & 7 deletions x-pack/plugins/infra/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { METRICS_FEATURE, LOGS_FEATURE } from './features';
import { UsageCollector } from './usage/usage_collector';
import { InfraStaticSourceConfiguration } from '../common/http_api/source_api';
import { registerAlertTypes } from './lib/alerting';
import { infraSourceConfigurationSavedObjectType } from './lib/sources';
import { metricsExplorerViewSavedObjectType } from '../common/saved_objects/metrics_explorer_view';
import { inventoryViewSavedObjectType } from '../common/saved_objects/inventory_view';

export const config = {
schema: schema.object({
Expand Down Expand Up @@ -85,13 +88,6 @@ export class InfraServerPlugin {
this.config$ = context.config.create<InfraConfig>();
}

getLibs() {
if (!this.libs) {
throw new Error('libs not set up yet');
}
return this.libs;
}

async setup(core: CoreSetup, plugins: InfraServerPluginDeps) {
await new Promise(resolve => {
this.config$.subscribe(configValue => {
Expand All @@ -113,6 +109,11 @@ export class InfraServerPlugin {
const logEntryCategoriesAnalysis = new LogEntryCategoriesAnalysis({ framework });
const logEntryRateAnalysis = new LogEntryRateAnalysis({ framework });

// register saved object types
core.savedObjects.registerType(infraSourceConfigurationSavedObjectType);
core.savedObjects.registerType(metricsExplorerViewSavedObjectType);
core.savedObjects.registerType(inventoryViewSavedObjectType);

// TODO: separate these out individually and do away with "domains" as a temporary group
const domainLibs: InfraDomainLibs = {
fields: new InfraFieldsDomain(new FrameworkFieldsAdapter(framework), {
Expand Down
15 changes: 0 additions & 15 deletions x-pack/plugins/infra/server/saved_objects.ts

This file was deleted.

0 comments on commit 3d43166

Please sign in to comment.