Skip to content

Commit

Permalink
[Rename] Refactored src/legacy directory (#142)
Browse files Browse the repository at this point in the history
* [Rename] Refactored src/legacy directory

* [Rename] addressed review feedbacks

Signed-off-by: Mihir Soni <mihirsoni.123@gmail.com>
  • Loading branch information
mihirsoni authored and kavilla committed Mar 20, 2021
1 parent 23df0d4 commit 226c446
Show file tree
Hide file tree
Showing 34 changed files with 146 additions and 146 deletions.
4 changes: 2 additions & 2 deletions src/legacy/server/config/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

export default function (kbnServer, server) {
export default function (osdServer, server) {
server.decorate('server', 'config', function () {
return kbnServer.config;
return osdServer.config;
});
}
4 changes: 2 additions & 2 deletions src/legacy/server/config/complete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('server/config completeMixin()', function () {
get: sinon.stub().returns(configValues),
};

const kbnServer = {
const osdServer = {
newPlatform: {},
settings,
server,
Expand All @@ -44,7 +44,7 @@ describe('server/config completeMixin()', function () {
plugins,
};

const callCompleteMixin = () => completeMixin(kbnServer, server, config);
const callCompleteMixin = () => completeMixin(osdServer, server, config);

return { config, callCompleteMixin, server };
};
Expand Down
10 changes: 5 additions & 5 deletions src/legacy/server/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { set } from '@elastic/safer-lodash-set';
import _ from 'lodash';
import { override } from './override';
import createDefaultSchema from './schema';
import { unset, deepCloneWithBuffers as clone, IS_KIBANA_DISTRIBUTABLE } from '../../utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { unset, deepCloneWithBuffers as clone, IS_OPENSEARCH_DASHBOARDS_DISTRIBUTABLE } from '../../utils';
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { pkg } from '../../../core/server/utils';
const schema = Symbol('Joi Schema');
const schemaExts = Symbol('Schema Extensions');
Expand Down Expand Up @@ -109,11 +109,11 @@ export class Config {
notDev: !dev,
version: _.get(pkg, 'version'),
branch: _.get(pkg, 'branch'),
buildNum: IS_KIBANA_DISTRIBUTABLE ? pkg.build.number : Number.MAX_SAFE_INTEGER,
buildSha: IS_KIBANA_DISTRIBUTABLE
buildNum: IS_OPENSEARCH_DASHBOARDS_DISTRIBUTABLE ? pkg.build.number : Number.MAX_SAFE_INTEGER,
buildSha: IS_OPENSEARCH_DASHBOARDS_DISTRIBUTABLE
? pkg.build.sha
: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
dist: IS_KIBANA_DISTRIBUTABLE,
dist: IS_OPENSEARCH_DASHBOARDS_DISTRIBUTABLE,
};

if (!context.dev && !context.prod) {
Expand Down
8 changes: 4 additions & 4 deletions src/legacy/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ export default () =>
locale: Joi.string().default('en'),
}).default(),

// temporarily moved here from the (now deleted) kibana legacy plugin
kibana: Joi.object({
// temporarily moved here from the (now deleted) opensearch-dashboards legacy plugin
opensearchDashboards: Joi.object({
enabled: Joi.boolean().default(true),
index: Joi.string().default('.kibana'),
index: Joi.string().default('.opensearch-dashboards'),
autocompleteTerminateAfter: Joi.number().integer().min(1).default(100000),
// TODO Also allow units here like in elasticsearch config once this is moved to the new platform
// TODO Also allow units here like in opensearch config once this is moved to the new platform
autocompleteTimeout: Joi.number().integer().min(1).default(1000),
}).default(),

Expand Down
10 changes: 5 additions & 5 deletions src/legacy/server/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/

import { Server } from 'hapi';
import KbnServer from '../kbn_server';
import OsdServer from '../osd_server';

/**
* Exposes `kbnServer.newPlatform` through Hapi API.
* @param kbnServer KbnServer singleton instance.
* Exposes `osdServer.newPlatform` through Hapi API.
* @param osdServer OsdServer singleton instance.
* @param server Hapi server instance to expose `core` on.
*/
export function coreMixin(kbnServer: KbnServer, server: Server) {
export function coreMixin(osdServer: OsdServer, server: Server) {
// we suppress type error because hapi expect a function here not an object
server.decorate('server', 'newPlatform', kbnServer.newPlatform as any);
server.decorate('server', 'newPlatform', osdServer.newPlatform as any);
}
6 changes: 3 additions & 3 deletions src/legacy/server/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import Boom from 'boom';
import { registerHapiPlugins } from './register_hapi_plugins';
import { setupBasePathProvider } from './setup_base_path_provider';

export default async function (kbnServer, server) {
server = kbnServer.server;
export default async function (osdServer, server) {
server = osdServer.server;

setupBasePathProvider(kbnServer);
setupBasePathProvider(osdServer);

await registerHapiPlugins(server);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

import * as kbnTestServer from '../../../../core/test_helpers/kbn_server';
import * as osdTestServer from '../../../../core/test_helpers/osd_server';

let root;
beforeAll(async () => {
root = kbnTestServer.createRoot({
root = osdTestServer.createRoot({
server: { maxPayloadBytes: 100 },
migrations: { skip: true },
plugins: { initialize: false },
Expand All @@ -30,7 +30,7 @@ beforeAll(async () => {
await root.setup();
await root.start();

kbnTestServer.getKbnServer(root).server.route({
osdTestServer.getOsdServer(root).server.route({
path: '/payload_size_check/test/route',
method: 'POST',
config: { payload: { maxBytes: 200 } },
Expand All @@ -41,7 +41,7 @@ beforeAll(async () => {
afterAll(async () => await root.shutdown());

test('accepts payload with a size larger than default but smaller than route config allows', async () => {
await kbnTestServer.request
await osdTestServer.request
.post(root, '/payload_size_check/test/route')
.send({
data: Array(150).fill('+').join(''),
Expand All @@ -50,7 +50,7 @@ test('accepts payload with a size larger than default but smaller than route con
});

test('fails with 413 if payload size is larger than default and route config allows', async () => {
await kbnTestServer.request
await osdTestServer.request
.post(root, '/payload_size_check/test/route')
.send({
data: Array(250).fill('+').join(''),
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/server/http/setup_base_path_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

export function setupBasePathProvider(kbnServer) {
kbnServer.server.decorate('request', 'getBasePath', function () {
export function setupBasePathProvider(osdServer) {
osdServer.server.decorate('request', 'getBasePath', function () {
const request = this;
return kbnServer.newPlatform.setup.core.http.basePath.get(request);
return osdServer.newPlatform.setup.core.http.basePath.get(request);
});
}
2 changes: 1 addition & 1 deletion src/legacy/server/i18n/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export const I18N_RC = '.i18nrc.json';
/**
* The type name used within the Monitoring index to publish localization stats.
*/
export const KIBANA_LOCALIZATION_STATS_TYPE = 'localization';
export const OPENSEARCH_DASHBOARDS_LOCALIZATION_STATS_TYPE = 'localization';
12 changes: 6 additions & 6 deletions src/legacy/server/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
* under the License.
*/

import { i18n, i18nLoader } from '@kbn/i18n';
import { i18n, i18nLoader } from '@osd/i18n';
import { basename } from 'path';
import { Server } from 'hapi';
import { fromRoot } from '../../../core/server/utils';
import type { UsageCollectionSetup } from '../../../plugins/usage_collection/server';
import { getTranslationPaths } from './get_translations_path';
import { I18N_RC } from './constants';
import KbnServer, { KibanaConfig } from '../kbn_server';
import OsdServer, { OpenSearchDashboardsConfig } from '../osd_server';
import { registerLocalizationUsageCollector } from './localization';

export async function i18nMixin(kbnServer: KbnServer, server: Server, config: KibanaConfig) {
export async function i18nMixin(osdServer: OsdServer, server: Server, config: OpenSearchDashboardsConfig) {
const locale = config.get('i18n.locale') as string;

const translationPaths = await Promise.all([
Expand All @@ -42,7 +42,7 @@ export async function i18nMixin(kbnServer: KbnServer, server: Server, config: Ki
getTranslationPaths({ cwd, glob: `*/${I18N_RC}` })
),
getTranslationPaths({
cwd: fromRoot('../kibana-extra'),
cwd: fromRoot('../opensearch-dashboards-extra'),
glob: `*/${I18N_RC}`,
}),
]);
Expand All @@ -64,8 +64,8 @@ export async function i18nMixin(kbnServer: KbnServer, server: Server, config: Ki

server.decorate('server', 'getTranslationsFilePaths', getTranslationsFilePaths);

if (kbnServer.newPlatform.setup.plugins.usageCollection) {
const { usageCollection } = kbnServer.newPlatform.setup.plugins as {
if (osdServer.newPlatform.setup.plugins.usageCollection) {
const { usageCollection } = osdServer.newPlatform.setup.plugins as {
usageCollection: UsageCollectionSetup;
};
registerLocalizationUsageCollector(usageCollection, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createI18nLoaderMock = (translations: TranslationsMock) => {
};

import { getTranslationCount } from './telemetry_localization_collector';
import { i18nLoader } from '@kbn/i18n';
import { i18nLoader } from '@osd/i18n';

describe('getTranslationCount', () => {
it('returns 0 if no translations registered', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

import { i18nLoader } from '@kbn/i18n';
import { i18nLoader } from '@osd/i18n';
import { size } from 'lodash';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { getIntegrityHashes, Integrities } from './file_integrity';
import { KIBANA_LOCALIZATION_STATS_TYPE } from '../constants';
import { OPENSEARCH_DASHBOARDS_LOCALIZATION_STATS_TYPE } from '../constants';

export interface UsageStats {
locale: string;
Expand Down Expand Up @@ -68,7 +68,7 @@ export function registerLocalizationUsageCollector(
helpers: LocalizationUsageCollectorHelpers
) {
const collector = usageCollection.makeUsageCollector({
type: KIBANA_LOCALIZATION_STATS_TYPE,
type: OPENSEARCH_DASHBOARDS_LOCALIZATION_STATS_TYPE,
isReady: () => true,
fetch: createCollectorFetch(helpers),
});
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/logging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function setupLogging(server, config) {
});
}

export async function loggingMixin(kbnServer, server, config) {
export async function loggingMixin(osdServer, server, config) {
logWithMetadata.decorateServer(server);

await setupLogging(server, config);
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/logging/log_format_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const stripColors = function (string) {
return string.replace(/\u001b[^m]+m/g, '');
};

export default class KbnLoggerJsonFormat extends LogFormat {
export default class OsdLoggerJsonFormat extends LogFormat {
format(data) {
data.message = stripColors(data.message);
data['@timestamp'] = this.extractAndFormatTimestamp(data);
Expand Down
12 changes: 6 additions & 6 deletions src/legacy/server/logging/log_format_json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

import moment from 'moment';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { attachMetaData } from '../../../../src/core/server/legacy/logging/legacy_logging_server';
import { createListStream, createPromiseFromStreams } from '../../../core/server/utils';

import KbnLoggerJsonFormat from './log_format_json';
import OsdLoggerJsonFormat from './log_format_json';

const time = +moment('2010-01-01T05:15:59Z', moment.ISO_8601);

Expand All @@ -32,13 +32,13 @@ const makeEvent = (eventType) => ({
timestamp: time,
});

describe('KbnLoggerJsonFormat', () => {
describe('OsdLoggerJsonFormat', () => {
const config = {};

describe('event types and messages', () => {
let format;
beforeEach(() => {
format = new KbnLoggerJsonFormat(config);
format = new OsdLoggerJsonFormat(config);
});

it('log', async () => {
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('KbnLoggerJsonFormat', () => {

describe('timezone', () => {
it('logs in UTC', async () => {
const format = new KbnLoggerJsonFormat({
const format = new OsdLoggerJsonFormat({
timezone: 'UTC',
});

Expand All @@ -259,7 +259,7 @@ describe('KbnLoggerJsonFormat', () => {
});

it('logs in local timezone timezone is undefined', async () => {
const format = new KbnLoggerJsonFormat({});
const format = new OsdLoggerJsonFormat({});

const result = await createPromiseFromStreams([createListStream([makeEvent('log')]), format]);

Expand Down
4 changes: 2 additions & 2 deletions src/legacy/server/logging/log_format_string.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const type = _.memoize(function (t) {
return color(t)(_.pad(t, 7).slice(0, 7));
});

const workerType = process.env.kbnWorkerType ? `${type(process.env.kbnWorkerType)} ` : '';
const workerType = process.env.osdWorkerType ? `${type(process.env.osdWorkerType)} ` : '';

export default class KbnLoggerStringFormat extends LogFormat {
export default class OsdLoggerStringFormat extends LogFormat {
format(data) {
const time = color('time')(this.extractAndFormatTimestamp(data, 'HH:mm:ss.SSS'));
const msg = data.error ? color('error')(data.error.stack) : color('message')(data.message);
Expand Down
12 changes: 6 additions & 6 deletions src/legacy/server/logging/log_format_string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

import moment from 'moment';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { attachMetaData } from '../../../../src/core/server/legacy/logging/legacy_logging_server';

import { createListStream, createPromiseFromStreams } from '../../../core/server/utils';

import KbnLoggerStringFormat from './log_format_string';
import OsdLoggerStringFormat from './log_format_string';

const time = +moment('2010-01-01T05:15:59Z', moment.ISO_8601);

Expand All @@ -35,9 +35,9 @@ const makeEvent = () => ({
data: 'my log message',
});

describe('KbnLoggerStringFormat', () => {
describe('OsdLoggerStringFormat', () => {
it('logs in UTC', async () => {
const format = new KbnLoggerStringFormat({
const format = new OsdLoggerStringFormat({
timezone: 'UTC',
});

Expand All @@ -47,15 +47,15 @@ describe('KbnLoggerStringFormat', () => {
});

it('logs in local timezone when timezone is undefined', async () => {
const format = new KbnLoggerStringFormat({});
const format = new OsdLoggerStringFormat({});

const result = await createPromiseFromStreams([createListStream([makeEvent()]), format]);

expect(String(result)).toContain(moment(time).format('HH:mm:ss.SSS'));
});
describe('with metadata', () => {
it('does not log meta data', async () => {
const format = new KbnLoggerStringFormat({});
const format = new OsdLoggerStringFormat({});
const event = {
data: attachMetaData('message for event', {
prop1: 'value1',
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/logging/log_with_metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { isPlainObject } from 'lodash';
import {
metadataSymbol,
attachMetaData,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @osd/eslint/no-restricted-paths
} from '../../../../src/core/server/legacy/logging/legacy_logging_server';

export const logWithMetadata = {
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/server/logging/rotate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
import { isMaster, isWorker } from 'cluster';
import { Server } from 'hapi';
import { LogRotator } from './log_rotator';
import { KibanaConfig } from '../../kbn_server';
import { OpenSearchDashboardsConfig } from '../../osd_server';

let logRotator: LogRotator;

export async function setupLoggingRotate(server: Server, config: KibanaConfig) {
export async function setupLoggingRotate(server: Server, config: OpenSearchDashboardsConfig) {
// If log rotate is not enabled we skip
if (!config.get('logging.rotate.enabled')) {
return;
}

// We just want to start the logging rotate service once
// and we choose to use the master (prod) or the worker server (dev)
if (!isMaster && isWorker && process.env.kbnWorkerType !== 'server') {
if (!isMaster && isWorker && process.env.osdWorkerType !== 'server') {
return;
}

Expand Down
Loading

0 comments on commit 226c446

Please sign in to comment.