Skip to content

Commit

Permalink
Removes the configuration adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Sep 11, 2019
1 parent a6540f5 commit 8159a7d
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 202 deletions.
5 changes: 4 additions & 1 deletion x-pack/legacy/plugins/infra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export function infra(kibana: any) {

const getConfig$ = <T>() =>
new Observable<T>(observer => {
observer.next(server.config().get('xpack.infra'));
server
.config()
.get('xpack.infra')
.then((value: T) => observer.next(value));
});

const initContext = {
Expand Down
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/infra/server/kibana.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import { initInfraServer } from './infra_server';
import { compose } from './lib/compose/kibana';
import { UsageCollector } from './usage/usage_collector';
import { InternalCoreSetup } from '../../../../../src/core/server';
import { InfraConfig } from './new_platform_config.schema';

export interface KbnServer extends Server {
usage: any;
}

export const initServerWithKibana = (core: InternalCoreSetup) => {
const libs = compose(kbnServer);
export const initServerWithKibana = (core: InternalCoreSetup, config: InfraConfig) => {
const libs = compose(
core,
config
);
initInfraServer(libs);

// NP_TODO how do we replace this?
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 6 additions & 9 deletions x-pack/legacy/plugins/infra/server/lib/compose/kibana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { Server } from 'hapi';

import { InfraKibanaConfigurationAdapter } from '../adapters/configuration/kibana_configuration_adapter';
import { FrameworkFieldsAdapter } from '../adapters/fields/framework_fields_adapter';
import { InfraKibanaBackendFrameworkAdapter } from '../adapters/framework/kibana_framework_adapter';
import { InfraKibanaLogEntriesAdapter } from '../adapters/log_entries/kibana_log_entries_adapter';
Expand All @@ -20,12 +16,13 @@ import { InfraLogAnalysis } from '../log_analysis';
import { InfraSnapshot } from '../snapshot';
import { InfraSourceStatus } from '../source_status';
import { InfraSources } from '../sources';
import { InfraConfig } from '../../new_platform_config.schema';
import { InternalCoreSetup } from '../../../../../../../src/core/server';

export function compose(server: Server): InfraBackendLibs {
const configuration = new InfraKibanaConfigurationAdapter(server);
const framework = new InfraKibanaBackendFrameworkAdapter(server);
export function compose(core: InternalCoreSetup, config: InfraConfig) {
const framework = new InfraKibanaBackendFrameworkAdapter(core);
const sources = new InfraSources({
configuration,
config,
savedObjects: framework.getSavedObjectsService(),
});
const sourceStatus = new InfraSourceStatus(new InfraElasticsearchSourceStatusAdapter(framework), {
Expand All @@ -46,7 +43,7 @@ export function compose(server: Server): InfraBackendLibs {
};

const libs: InfraBackendLibs = {
configuration,
configuration: config, // NP_TODO: Do we ever use this anywhere?
framework,
logAnalysis,
snapshot,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/infra/server/lib/infra_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { InfraSourceConfiguration } from '../../public/graphql/types';
import { InfraConfigurationAdapter } from './adapters/configuration';
import { InfraBackendFrameworkAdapter, InfraFrameworkRequest } from './adapters/framework';
import { InfraFieldsDomain } from './domains/fields_domain';
import { InfraLogEntriesDomain } from './domains/log_entries_domain';
Expand All @@ -14,6 +13,7 @@ import { InfraLogAnalysis } from './log_analysis/log_analysis';
import { InfraSnapshot } from './snapshot';
import { InfraSources } from './sources';
import { InfraSourceStatus } from './source_status';
import { InfraConfig } from '../new_platform_config.schema';

export interface InfraDomainLibs {
fields: InfraFieldsDomain;
Expand All @@ -22,7 +22,7 @@ export interface InfraDomainLibs {
}

export interface InfraBackendLibs extends InfraDomainLibs {
configuration: InfraConfigurationAdapter;
configuration: InfraConfig;
framework: InfraBackendFrameworkAdapter;
logAnalysis: InfraLogAnalysis;
snapshot: InfraSnapshot;
Expand Down
25 changes: 11 additions & 14 deletions x-pack/legacy/plugins/infra/server/lib/sources/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { InfraInmemoryConfigurationAdapter } from '../adapters/configuration/inmemory_configuration_adapter';
import { InfraSources } from './sources';

describe('the InfraSources lib', () => {
describe('getSourceConfiguration method', () => {
test('returns a source configuration if it exists', async () => {
const sourcesLib = new InfraSources({
configuration: createMockStaticConfiguration({}),
config: createMockStaticConfiguration({}),
savedObjects: createMockSavedObjectsService({
id: 'TEST_ID',
version: 'foo',
Expand Down Expand Up @@ -52,7 +50,7 @@ describe('the InfraSources lib', () => {

test('adds missing attributes from the static configuration to a source configuration', async () => {
const sourcesLib = new InfraSources({
configuration: createMockStaticConfiguration({
config: createMockStaticConfiguration({
default: {
metricAlias: 'METRIC_ALIAS',
logAlias: 'LOG_ALIAS',
Expand Down Expand Up @@ -98,7 +96,7 @@ describe('the InfraSources lib', () => {

test('adds missing attributes from the default configuration to a source configuration', async () => {
const sourcesLib = new InfraSources({
configuration: createMockStaticConfiguration({}),
config: createMockStaticConfiguration({}),
savedObjects: createMockSavedObjectsService({
id: 'TEST_ID',
version: 'foo',
Expand Down Expand Up @@ -129,15 +127,14 @@ describe('the InfraSources lib', () => {
});
});

const createMockStaticConfiguration = (sources: any) =>
new InfraInmemoryConfigurationAdapter({
enabled: true,
query: {
partitionSize: 1,
partitionFactor: 1,
},
sources,
});
const createMockStaticConfiguration = (sources: any) => ({
enabled: true,
query: {
partitionSize: 1,
partitionFactor: 1,
},
sources,
});

const createMockSavedObjectsService = (savedObject?: any) => ({
getScopedSavedObjectsClient() {
Expand Down
7 changes: 3 additions & 4 deletions x-pack/legacy/plugins/infra/server/lib/sources/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { identity, constant } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import { map, fold } from 'fp-ts/lib/Either';
import { Pick3 } from '../../../common/utility_types';
import { InfraConfigurationAdapter } from '../adapters/configuration';
import { InfraFrameworkRequest, internalInfraFrameworkRequest } from '../adapters/framework';
import { defaultSourceConfiguration } from './defaults';
import { NotFoundError } from './errors';
Expand All @@ -25,9 +24,10 @@ import {
SourceConfigurationSavedObjectRuntimeType,
StaticSourceConfigurationRuntimeType,
} from './types';
import { InfraConfig } from '../../new_platform_config.schema';

interface Libs {
configuration: InfraConfigurationAdapter;
config: InfraConfig;
savedObjects: Pick<Legacy.SavedObjectsService, 'getScopedSavedObjectsClient'> &
Pick3<Legacy.SavedObjectsService, 'SavedObjectsClient', 'errors', 'isNotFoundError'>;
}
Expand Down Expand Up @@ -187,15 +187,14 @@ export class InfraSources {
}

private async getStaticDefaultSourceConfiguration() {
const staticConfiguration = await this.libs.configuration.get();
const staticSourceConfiguration = pipe(
runtimeTypes
.type({
sources: runtimeTypes.type({
default: StaticSourceConfigurationRuntimeType,
}),
})
.decode(staticConfiguration),
.decode(this.libs.config),
map(({ sources: { default: defaultConfiguration } }) => defaultConfiguration),
fold(constant({}), identity)
);
Expand Down
18 changes: 18 additions & 0 deletions x-pack/legacy/plugins/infra/server/new_platform_config.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { schema, TypeOf } from '@kbn/config-schema';

export const config = {
schema: schema.object({
enabled: schema.boolean(),
query: schema.object({
partitionSize: schema.maybe(schema.number()),
partitionFactor: schema.maybe(schema.number()),
}),
}),
};

export type InfraConfig = TypeOf<typeof config.schema>;
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/infra/server/new_platform_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

import { PluginInitializerContext } from 'src/core/server';
import { InfraServerPlugin, config, InfraConfig } from './new_platform_plugin';
import { InfraServerPlugin } from './new_platform_plugin';
import { config, InfraConfig } from './new_platform_config.schema';

// NP_TODO: kibana NP needs "config" to be exported from here, I think?
export { config, InfraConfig };
Expand Down
Loading

0 comments on commit 8159a7d

Please sign in to comment.