Skip to content

Commit

Permalink
Removes legacy infra plugin and moves saved objects to NP
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Apr 29, 2020
1 parent 1106482 commit bdd1951
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 96 deletions.
2 changes: 0 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { apm } from './legacy/plugins/apm';
import { maps } from './legacy/plugins/maps';
import { spaces } from './legacy/plugins/spaces';
import { canvas } from './legacy/plugins/canvas';
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 @@ -31,7 +30,6 @@ module.exports = function(kibana) {
apm(kibana),
maps(kibana),
canvas(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: 'agnostic',
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: 'agnostic',
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { mapValues } from 'lodash';
import { i18n } from '@kbn/i18n';
import { convertSavedObjectToSavedSourceConfiguration } from '../../sources/sources';
import { infraSourceConfigurationSavedObjectType } from '../../sources/saved_object_mappings';
import { infraSourceConfigurationSavedObjectName } from '../../sources/saved_object_type';
import { InfraDatabaseSearchResponse } from '../../adapters/framework/adapter_types';
import { createAfterKeyHandler } from '../../../utils/create_afterkey_handler';
import { getAllCompositeData } from '../../../utils/get_all_composite_data';
Expand Down Expand Up @@ -180,7 +180,7 @@ const getIndexPattern: (
) => Promise<string> = async function({ savedObjectsClient }, sourceId = 'default') {
try {
const sourceConfiguration = await savedObjectsClient.get(
infraSourceConfigurationSavedObjectType,
infraSourceConfigurationSavedObjectName,
sourceId
);
const { metricAlias } = convertSavedObjectToSavedSourceConfiguration(
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: 'agnostic',
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 { RequestHandlerContext, 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 @@ -107,7 +107,7 @@ export class InfraSources {

const createdSourceConfiguration = convertSavedObjectToSavedSourceConfiguration(
await requestContext.core.savedObjects.client.create(
infraSourceConfigurationSavedObjectType,
infraSourceConfigurationSavedObjectName,
pickSavedSourceConfiguration(newSourceConfiguration) as any,
{ id: sourceId }
)
Expand All @@ -124,7 +124,7 @@ export class InfraSources {

public async deleteSourceConfiguration(requestContext: RequestHandlerContext, sourceId: string) {
await requestContext.core.savedObjects.client.delete(
infraSourceConfigurationSavedObjectType,
infraSourceConfigurationSavedObjectName,
sourceId
);
}
Expand All @@ -148,7 +148,7 @@ export class InfraSources {

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

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

private async getAllSavedSourceConfigurations(requestContext: RequestHandlerContext) {
const savedObjects = await requestContext.core.savedObjects.client.find({
type: infraSourceConfigurationSavedObjectType,
type: infraSourceConfigurationSavedObjectName,
});

return savedObjects.saved_objects.map(convertSavedObjectToSavedSourceConfiguration);
Expand Down
8 changes: 8 additions & 0 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 @@ -113,6 +116,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 bdd1951

Please sign in to comment.