mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Reporting] Implement a round of server code cleanup of types, unused files, and test mocks (#108480)
* rewrite createMockLevelLogger * Remove redundant BaseParams references that were inlined * remove unused files related to the 7.x compatibility shim * remove unused legacy mock
This commit is contained in:
parent
2fb785de64
commit
8ea29b6c5a
7 changed files with 35 additions and 109 deletions
|
@ -57,6 +57,21 @@ export interface ReportOutput {
|
|||
|
||||
export type TaskRunResult = Omit<ReportOutput, 'content'>;
|
||||
|
||||
export interface BaseParams {
|
||||
layout?: LayoutParams;
|
||||
objectType: string;
|
||||
title: string;
|
||||
browserTimezone: string; // to format dates in the user's time zone
|
||||
version: string; // to handle any state migrations
|
||||
}
|
||||
|
||||
// base params decorated with encrypted headers that come into runJob functions
|
||||
export interface BasePayload extends BaseParams {
|
||||
headers: string;
|
||||
spaceId?: string;
|
||||
isDeprecated?: boolean;
|
||||
}
|
||||
|
||||
export interface ReportSource {
|
||||
/*
|
||||
* Required fields: populated in enqueue_job when the request comes in to
|
||||
|
@ -64,15 +79,7 @@ export interface ReportSource {
|
|||
*/
|
||||
jobtype: string; // refers to `ExportTypeDefinition.jobType`
|
||||
created_by: string | false; // username or `false` if security is disabled. Used for ensuring users can only access the reports they've created.
|
||||
payload: {
|
||||
headers: string; // encrypted headers
|
||||
/**
|
||||
* PDF V2 reports will contain locators parameters (see {@link LocatorPublic}) that will be converted to {@link KibanaLocation}s when
|
||||
* generating a report
|
||||
*/
|
||||
locatorParams?: LocatorParams[];
|
||||
isDeprecated?: boolean; // set to true when the export type is being phased out
|
||||
} & BaseParams;
|
||||
payload: BasePayload;
|
||||
meta: { objectType: string; layout?: string }; // for telemetry
|
||||
migration_version: string; // for reminding the user to update their POST URL
|
||||
attempts: number; // initially populated as 0
|
||||
|
@ -105,14 +112,6 @@ export interface ReportDocument extends ReportDocumentHead {
|
|||
_source: ReportSource;
|
||||
}
|
||||
|
||||
export interface BaseParams {
|
||||
layout?: LayoutParams;
|
||||
objectType: string;
|
||||
title: string;
|
||||
browserTimezone: string; // to format dates in the user's time zone
|
||||
version: string; // to handle any state migrations
|
||||
}
|
||||
|
||||
export type JobId = string;
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { forEach, isArray } from 'lodash';
|
||||
import { url } from '../../../../../../../src/plugins/kibana_utils/server';
|
||||
|
||||
function toKeyValue(obj) {
|
||||
const parts = [];
|
||||
forEach(obj, function (value, key) {
|
||||
if (isArray(value)) {
|
||||
forEach(value, function (arrayValue) {
|
||||
const keyStr = url.encodeUriQuery(key, true);
|
||||
const valStr = arrayValue === true ? '' : '=' + url.encodeUriQuery(arrayValue, true);
|
||||
parts.push(keyStr + valStr);
|
||||
});
|
||||
} else {
|
||||
const keyStr = url.encodeUriQuery(key, true);
|
||||
const valStr = value === true ? '' : '=' + url.encodeUriQuery(value, true);
|
||||
parts.push(keyStr + valStr);
|
||||
}
|
||||
});
|
||||
return parts.length ? parts.join('&') : '';
|
||||
}
|
||||
|
||||
export const uriEncode = {
|
||||
stringify: toKeyValue,
|
||||
string: url.encodeUriQuery,
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { forEach, isArray } from 'lodash';
|
||||
import { url } from '../../../../../../../src/plugins/kibana_utils/server';
|
||||
|
||||
function toKeyValue(obj) {
|
||||
const parts = [];
|
||||
forEach(obj, function (value, key) {
|
||||
if (isArray(value)) {
|
||||
forEach(value, function (arrayValue) {
|
||||
const keyStr = url.encodeUriQuery(key, true);
|
||||
const valStr = arrayValue === true ? '' : '=' + url.encodeUriQuery(arrayValue, true);
|
||||
parts.push(keyStr + valStr);
|
||||
});
|
||||
} else {
|
||||
const keyStr = url.encodeUriQuery(key, true);
|
||||
const valStr = value === true ? '' : '=' + url.encodeUriQuery(value, true);
|
||||
parts.push(keyStr + valStr);
|
||||
}
|
||||
});
|
||||
return parts.length ? parts.join('&') : '';
|
||||
}
|
||||
|
||||
export const uriEncode = {
|
||||
stringify: toKeyValue,
|
||||
string: url.encodeUriQuery,
|
||||
};
|
|
@ -53,9 +53,6 @@ describe('POST /diagnose/browser', () => {
|
|||
);
|
||||
|
||||
const mockSetupDeps = createMockPluginSetup({
|
||||
elasticsearch: {
|
||||
legacy: { client: { callAsInternalUser: jest.fn() } },
|
||||
},
|
||||
router: httpSetup.createRouter(''),
|
||||
});
|
||||
|
||||
|
|
|
@ -51,9 +51,6 @@ describe('POST /diagnose/screenshot', () => {
|
|||
);
|
||||
|
||||
const mockSetupDeps = createMockPluginSetup({
|
||||
elasticsearch: {
|
||||
legacy: { client: { callAsInternalUser: jest.fn() } },
|
||||
},
|
||||
router: httpSetup.createRouter(''),
|
||||
});
|
||||
|
||||
|
|
|
@ -5,20 +5,24 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { LevelLogger } from '../lib';
|
||||
jest.mock('../lib/level_logger');
|
||||
|
||||
import { loggingSystemMock } from 'src/core/server/mocks';
|
||||
import { LevelLogger } from '../lib/level_logger';
|
||||
|
||||
export function createMockLevelLogger() {
|
||||
// eslint-disable-next-line no-console
|
||||
const consoleLogger = (tag: string) => (message: unknown) => console.log(tag, message);
|
||||
const innerLogger = {
|
||||
get: () => innerLogger,
|
||||
debug: consoleLogger('debug'),
|
||||
info: consoleLogger('info'),
|
||||
warn: consoleLogger('warn'),
|
||||
trace: consoleLogger('trace'),
|
||||
error: consoleLogger('error'),
|
||||
fatal: consoleLogger('fatal'),
|
||||
log: consoleLogger('log'),
|
||||
};
|
||||
return new LevelLogger(innerLogger);
|
||||
|
||||
const logger = new LevelLogger(loggingSystemMock.create()) as jest.Mocked<LevelLogger>;
|
||||
|
||||
logger.clone.mockImplementation(createMockLevelLogger);
|
||||
logger.debug.mockImplementation(consoleLogger('debug'));
|
||||
logger.info.mockImplementation(consoleLogger('info'));
|
||||
logger.warn.mockImplementation(consoleLogger('warn'));
|
||||
logger.warning = jest.fn().mockImplementation(consoleLogger('warn'));
|
||||
logger.error.mockImplementation(consoleLogger('error'));
|
||||
logger.trace.mockImplementation(consoleLogger('trace'));
|
||||
|
||||
return logger;
|
||||
}
|
||||
|
|
|
@ -5,19 +5,19 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { Writable } from 'stream';
|
||||
import type { IRouter, KibanaRequest, RequestHandlerContext } from 'src/core/server';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { DataPluginStart } from 'src/plugins/data/server/plugin';
|
||||
import { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/server';
|
||||
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
|
||||
import { Writable } from 'stream';
|
||||
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';
|
||||
import { LicensingPluginSetup } from '../../licensing/server';
|
||||
import { AuthenticatedUser, SecurityPluginSetup } from '../../security/server';
|
||||
import { SpacesPluginSetup } from '../../spaces/server';
|
||||
import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server';
|
||||
import { CancellationToken } from '../common';
|
||||
import { BaseParams, TaskRunResult } from '../common/types';
|
||||
import { BaseParams, BasePayload, TaskRunResult } from '../common/types';
|
||||
import { ReportingConfigType } from './config';
|
||||
import { ReportingCore } from './core';
|
||||
import { LevelLogger } from './lib';
|
||||
|
@ -57,14 +57,7 @@ export type ReportingUser = { username: AuthenticatedUser['username'] } | false;
|
|||
export type CaptureConfig = ReportingConfigType['capture'];
|
||||
export type ScrollConfig = ReportingConfigType['csv']['scroll'];
|
||||
|
||||
export { BaseParams };
|
||||
|
||||
// base params decorated with encrypted headers that come into runJob functions
|
||||
export interface BasePayload extends BaseParams {
|
||||
headers: string;
|
||||
spaceId?: string;
|
||||
isDeprecated?: boolean;
|
||||
}
|
||||
export { BaseParams, BasePayload };
|
||||
|
||||
// default fn type for CreateJobFnFactory
|
||||
export type CreateJobFn<JobParamsType = BaseParams, JobPayloadType = BasePayload> = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue