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

Delete connector usage reporting task in on-prem and cloud #199650

Merged
Merged
2 changes: 2 additions & 0 deletions x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface PluginSetupContract {
getActionsHealth: () => { hasPermanentEncryptionKey: boolean };
getActionsConfigurationUtilities: () => ActionsConfigurationUtilities;
setEnabledConnectorTypes: (connectorTypes: EnabledConnectorTypes) => void;

isActionTypeEnabled(id: string, options?: { notifyUsage: boolean }): boolean;
}

Expand Down Expand Up @@ -168,6 +169,7 @@ export interface PluginStartContract {
params: Params,
variables: Record<string, unknown>
): Params;

isSystemActionConnector: (connectorId: string) => boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ describe('ConnectorUsageReportingTask', () => {
const response = await taskRunner.run();

expect(logger.warn).toHaveBeenCalledWith(
'Missing required project id while running actions:connector_usage_reporting'
'Missing required project id while running actions:connector_usage_reporting, reporting task will be deleted'
);

expect(response).toEqual({
shouldDeleteTask: true,
state: {
attempts: 0,
lastReportedUsageDate,
Expand Down Expand Up @@ -391,4 +392,27 @@ describe('ConnectorUsageReportingTask', () => {
'Usage data could not be pushed to usage-api. Stopped retrying after 5 attempts. Error:test-error'
);
});

it('does not schedule the task when the project id is missing', async () => {
const core = createSetup();
const taskManagerStart = taskManagerStartMock();

const task = new ConnectorUsageReportingTask({
eventLogIndex: 'test-index',
projectId: undefined,
logger,
core,
taskManager: mockTaskManagerSetup,
config: {
url: 'usage-api',
ca: {
path: './ca.crt',
},
},
});

await task.start(taskManagerStart);

expect(taskManagerStart.ensureScheduled).not.toBeCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export class ConnectorUsageReportingTask {
}

public start = async (taskManager?: TaskManagerStartContract) => {
if (!this.projectId) {
return;
}
if (!taskManager) {
this.logger.error(
`Missing required task manager service during start of ${CONNECTOR_USAGE_REPORTING_TASK_TYPE}`
Expand Down Expand Up @@ -111,10 +114,11 @@ export class ConnectorUsageReportingTask {

if (!this.projectId) {
this.logger.warn(
`Missing required project id while running ${CONNECTOR_USAGE_REPORTING_TASK_TYPE}`
`Missing required project id while running ${CONNECTOR_USAGE_REPORTING_TASK_TYPE}, reporting task will be deleted`
);
return {
state,
shouldDeleteTask: true,
};
}

Expand Down