Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] Remove EventLog Dependency #124762

Merged
merged 18 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions x-pack/plugins/reporting/server/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
import type { PluginStart as DataPluginStart } from 'src/plugins/data/server';
import type { FieldFormatsStart } from 'src/plugins/field_formats/server';
import { KibanaRequest, ServiceStatusLevels } from '../../../../src/core/server';
import type { IEventLogService } from '../../event_log/server';
import type { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';
import type { LicensingPluginStart } from '../../licensing/server';
import type { ScreenshotResult, ScreenshottingStart } from '../../screenshotting/server';
Expand All @@ -40,7 +39,6 @@ import { ExecuteReportTask, MonitorReportsTask, ReportTaskParams } from './lib/t
import type { ReportingPluginRouter, ScreenshotOptions } from './types';

export interface ReportingInternalSetup {
eventLog: IEventLogService;
basePath: Pick<BasePath, 'set'>;
router: ReportingPluginRouter;
features: FeaturesPluginSetup;
Expand Down Expand Up @@ -390,7 +388,7 @@ export class ReportingCore {
}

public getEventLogger(report: IReport, task?: { id: string }) {
const ReportingEventLogger = reportingEventLoggerFactory(this.pluginSetupDeps!.eventLog);
const ReportingEventLogger = reportingEventLoggerFactory(this.logger);
return new ReportingEventLogger(report, task);
}
}
7 changes: 1 addition & 6 deletions x-pack/plugins/reporting/server/lib/event_logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* 2.0.
*/

import { IEventLogService } from '../../../../event_log/server';
import { PLUGIN_ID } from '../../../common/constants';

export enum ActionType {
SCHEDULE_TASK = 'schedule-task',
CLAIM_TASK = 'claim-task',
Expand All @@ -16,7 +13,5 @@ export enum ActionType {
SAVE_REPORT = 'save-report',
RETRY = 'retry',
FAIL_REPORT = 'fail-report',
}
export function registerEventLogProviderActions(eventLog: IEventLogService) {
eventLog.registerProviderActions(PLUGIN_ID, Object.values(ActionType));
EXECUTE_ERROR = 'execute-error',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not related to this PR. It's a discovered oversight that should have gone into the first Event Log PR for Reporting.

}
51 changes: 14 additions & 37 deletions x-pack/plugins/reporting/server/lib/event_logger/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ConcreteTaskInstance } from '../../../../task_manager/server';
import { eventLogServiceMock } from '../../../../event_log/server/mocks';
import { createMockLevelLogger } from '../../test_helpers';
import { BasePayload } from '../../types';
import { Report } from '../store';
import { ReportingEventLogger, reportingEventLoggerFactory } from './logger';
Expand All @@ -21,15 +21,14 @@ describe('Event Logger', () => {
let factory: ReportingEventLogger;

beforeEach(() => {
factory = reportingEventLoggerFactory(eventLogServiceMock.create());
factory = reportingEventLoggerFactory(createMockLevelLogger());
});

it(`should construct with an internal seed object`, () => {
const logger = new factory(mockReport);
expect(logger.eventObj).toMatchInlineSnapshot(`
Object {
"event": Object {
"provider": "reporting",
"timezone": "UTC",
},
"kibana": Object {
Expand All @@ -38,9 +37,6 @@ describe('Event Logger', () => {
"jobType": "csv",
},
},
"log": Object {
"logger": "reporting",
},
"user": undefined,
}
`);
Expand All @@ -51,7 +47,6 @@ describe('Event Logger', () => {
expect(logger.eventObj).toMatchInlineSnapshot(`
Object {
"event": Object {
"provider": "reporting",
"timezone": "UTC",
},
"kibana": Object {
Expand All @@ -60,9 +55,6 @@ describe('Event Logger', () => {
"jobType": "csv",
},
},
"log": Object {
"logger": "reporting",
},
"user": Object {
"name": "thundercat",
},
Expand All @@ -77,7 +69,6 @@ describe('Event Logger', () => {
expect(logger.eventObj).toMatchInlineSnapshot(`
Object {
"event": Object {
"provider": "reporting",
"timezone": "UTC",
},
"kibana": Object {
Expand All @@ -89,9 +80,6 @@ describe('Event Logger', () => {
"id": "some-task-id-123",
},
},
"log": Object {
"logger": "reporting",
},
"user": Object {
"name": "thundercat",
},
Expand All @@ -101,16 +89,16 @@ describe('Event Logger', () => {

it(`logExecutionStart`, () => {
const logger = new factory(mockReport);
jest.spyOn(logger.completionLogger, 'startTiming');
jest.spyOn(logger.completionLogger, 'stopTiming');
const result = logger.logExecutionStart();
expect([result.event, result.kibana.reporting, result.message]).toMatchInlineSnapshot(`
Array [
Object {
"action": "execute-start",
"kind": "event",
"provider": "reporting",
"timezone": "UTC",
},
Object {
"actionType": "execute-start",
"id": "12348",
"jobType": "csv",
},
Expand All @@ -119,23 +107,23 @@ describe('Event Logger', () => {
`);
expect(result.message).toMatchInlineSnapshot(`"starting csv execution"`);
expect(logger.completionLogger.startTiming).toBeCalled();
expect(logger.completionLogger.stopTiming).not.toBeCalled();
});

it(`logExecutionComplete`, () => {
const logger = new factory(mockReport);
jest.spyOn(logger.completionLogger, 'startTiming');
jest.spyOn(logger.completionLogger, 'stopTiming');
logger.logExecutionStart();

const result = logger.logExecutionComplete({ byteSize: 444 });
expect([result.event, result.kibana.reporting, result.message]).toMatchInlineSnapshot(`
Array [
Object {
"action": "execute-complete",
"kind": "metrics",
"outcome": "success",
"provider": "reporting",
"timezone": "UTC",
},
Object {
"actionType": "execute-complete",
"byteSize": 444,
"id": "12348",
"jobType": "csv",
Expand All @@ -154,13 +142,10 @@ describe('Event Logger', () => {
expect([result.event, result.kibana.reporting, result.message]).toMatchInlineSnapshot(`
Array [
Object {
"action": "execute-complete",
"kind": "error",
"outcome": "failure",
"provider": "reporting",
"timezone": "UTC",
},
Object {
"actionType": "execute-error",
"id": "12348",
"jobType": "csv",
},
Expand All @@ -176,12 +161,10 @@ describe('Event Logger', () => {
expect([result.event, result.kibana.reporting, result.message]).toMatchInlineSnapshot(`
Array [
Object {
"action": "claim-task",
"kind": "event",
"provider": "reporting",
"timezone": "UTC",
},
Object {
"actionType": "claim-task",
"id": "12348",
"jobType": "csv",
},
Expand All @@ -196,12 +179,10 @@ describe('Event Logger', () => {
expect([result.event, result.kibana.reporting, result.message]).toMatchInlineSnapshot(`
Array [
Object {
"action": "fail-report",
"kind": "event",
"provider": "reporting",
"timezone": "UTC",
},
Object {
"actionType": "fail-report",
"id": "12348",
"jobType": "csv",
},
Expand All @@ -215,12 +196,10 @@ describe('Event Logger', () => {
expect([result.event, result.kibana.reporting, result.message]).toMatchInlineSnapshot(`
Array [
Object {
"action": "save-report",
"kind": "event",
"provider": "reporting",
"timezone": "UTC",
},
Object {
"actionType": "save-report",
"id": "12348",
"jobType": "csv",
},
Expand All @@ -234,12 +213,10 @@ describe('Event Logger', () => {
expect([result.event, result.kibana.reporting, result.message]).toMatchInlineSnapshot(`
Array [
Object {
"action": "retry",
"kind": "event",
"provider": "reporting",
"timezone": "UTC",
},
Object {
"actionType": "retry",
"id": "12348",
"jobType": "csv",
},
Expand Down
Loading