Skip to content

Commit

Permalink
use snake_case in config
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Dec 13, 2019
1 parent ad130b4 commit 211844e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
14 changes: 9 additions & 5 deletions x-pack/plugins/licensing/server/licensing_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
import { schema, TypeOf } from '@kbn/config-schema';
import { PluginConfigDescriptor } from 'kibana/server';

export const config: PluginConfigDescriptor = {
const configSchema = schema.object({
api_polling_frequency: schema.duration({ defaultValue: '30s' }),
});

export type LicenseConfigType = TypeOf<typeof configSchema>;

export const config: PluginConfigDescriptor<LicenseConfigType> = {
schema: schema.object({
pollingFrequency: schema.duration({ defaultValue: '30s' }),
api_polling_frequency: schema.duration({ defaultValue: '30s' }),
}),
deprecations: ({ renameFromRoot }) => [
renameFromRoot(
'xpack.xpack_main.xpack_api_polling_frequency_millis',
'xpack.licensing.pollingFrequency'
'xpack.licensing.api_polling_frequency'
),
],
};

export type LicenseConfigType = TypeOf<typeof config.schema>;
19 changes: 10 additions & 9 deletions x-pack/plugins/licensing/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function buildRawLicense(options: Partial<RawLicense> = {}): RawLicense {
};
return Object.assign(defaultRawLicense, options);
}
const pollingFrequency = moment.duration(100);

const flushPromises = (ms = 50) => new Promise(res => setTimeout(res, ms));

Expand All @@ -38,7 +37,7 @@ describe('licensing plugin', () => {

beforeEach(() => {
pluginInitContextMock = coreMock.createPluginInitializerContext({
pollingFrequency,
api_polling_frequency: moment.duration(100),
});
plugin = new LicensingPlugin(pluginInitContextMock);
});
Expand Down Expand Up @@ -201,7 +200,7 @@ describe('licensing plugin', () => {
plugin = new LicensingPlugin(
coreMock.createPluginInitializerContext({
// disable polling mechanism
pollingFrequency: moment.duration(50000),
api_polling_frequency: moment.duration(50000),
})
);
const dataClient = elasticsearchServiceMock.createClusterClient();
Expand Down Expand Up @@ -230,10 +229,10 @@ describe('licensing plugin', () => {
await plugin.stop();
});

it(`creates a poller fetching license from passed 'clusterClient' every 'pollingFrequency' ms`, async () => {
it(`creates a poller fetching license from passed 'clusterClient' every 'api_polling_frequency' ms`, async () => {
plugin = new LicensingPlugin(
coreMock.createPluginInitializerContext({
pollingFrequency: moment.duration(50000),
api_polling_frequency: moment.duration(50000),
})
);

Expand Down Expand Up @@ -274,7 +273,7 @@ describe('licensing plugin', () => {
it('creates a poller with a manual refresh control', async () => {
plugin = new LicensingPlugin(
coreMock.createPluginInitializerContext({
pollingFrequency,
api_polling_frequency: moment.duration(100),
})
);

Expand Down Expand Up @@ -304,7 +303,7 @@ describe('licensing plugin', () => {
beforeEach(() => {
plugin = new LicensingPlugin(
coreMock.createPluginInitializerContext({
pollingFrequency,
api_polling_frequency: moment.duration(100),
})
);
});
Expand Down Expand Up @@ -333,7 +332,9 @@ describe('licensing plugin', () => {
let plugin: LicensingPlugin;

beforeEach(() => {
plugin = new LicensingPlugin(coreMock.createPluginInitializerContext({ pollingFrequency }));
plugin = new LicensingPlugin(
coreMock.createPluginInitializerContext({ api_polling_frequency: moment.duration(100) })
);
});

afterEach(async () => {
Expand All @@ -354,7 +355,7 @@ describe('licensing plugin', () => {
it('stops polling', async () => {
const plugin = new LicensingPlugin(
coreMock.createPluginInitializerContext({
pollingFrequency,
api_polling_frequency: moment.duration(100),
})
);
const coreSetup = coreMock.createSetup();
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/licensing/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ export class LicensingPlugin implements Plugin<LicensingPluginSetup> {
public async setup(core: CoreSetup) {
this.logger.debug('Setting up Licensing plugin');
const config = await this.config$.pipe(take(1)).toPromise();
const pollingFrequency = config.api_polling_frequency;
const dataClient = await core.elasticsearch.dataClient$.pipe(take(1)).toPromise();

const { refresh, license$ } = this.createLicensePoller(
dataClient,
config.pollingFrequency.asMilliseconds()
pollingFrequency.asMilliseconds()
);

core.http.registerRouteHandlerContext('licensing', createRouteHandlerContext(license$));
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/licensing_plugin/apis/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function({ getService, getPageObjects }: FtrProviderContext) {
},

async getLicense(): Promise<PublicLicenseJSON> {
// > --xpack.licensing.pollingFrequency set in test config
// > --xpack.licensing.api_polling_frequency set in test config
// to wait for Kibana server to re-fetch the license from Elasticsearch
await delay(1000);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/licensing_plugin/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) {
...functionalTestsConfig.get('kbnTestServer'),
serverArgs: [
...functionalTestsConfig.get('kbnTestServer.serverArgs'),
'--xpack.licensing.pollingFrequency=300',
'--xpack.licensing.api_polling_frequency=300',
],
},

Expand Down

0 comments on commit 211844e

Please sign in to comment.