Skip to content

Commit

Permalink
[8.x] Delete connector usage reporting task in on-prem and cloud (#19…
Browse files Browse the repository at this point in the history
…9650) (#201741)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Delete connector usage reporting task in on-prem and cloud
(#199650)](#199650)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Ersin
Erdal","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-26T10:12:23Z","message":"Delete
connector usage reporting task in on-prem and cloud
(#199650)\n\nTowards:
https://github.com/elastic/response-ops-team/issues/209\r\n\r\n`connector_usage_reporting`
task is supposed to work only in serverless.\r\nAs there is no check for
that, even though it reports nothing, It was\r\nworking for on-prem and
cloud as well.\r\nThis PR deletes the `connector_usage_reporting` task
after the first run\r\nby checking if
`plugins.cloud.serverless.projectId` is missing.\r\n\r\n### To
verify:\r\nRun Kibana on this branch, then check the reporting task in
the console\r\nby running the below query.\r\nThere shouldn't be any
task.\r\n\r\n```\r\nGET .kibana_task_manager_*/_search\r\n{\r\n
\"query\": {\r\n \"prefix\": {\r\n \"task.taskType\": {\r\n \"value\":
\"actions:\"\r\n }\r\n }\r\n }\r\n}\r\n```\r\n\r\nThen remove or comment
out the line (`shouldDeleteTask: true`) added by\r\nthis PR and save the
file, Kibana will restart and register the task\r\nagain. You can use
the above query again to see that the task is
still\r\nregistered.","sha":"a1e97b1a43f2971dbf528201b3b82fb4b178b6bb","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","ci:project-deploy-observability"],"title":"Delete
connector usage reporting task in on-prem and
cloud","number":199650,"url":"https://github.com/elastic/kibana/pull/199650","mergeCommit":{"message":"Delete
connector usage reporting task in on-prem and cloud
(#199650)\n\nTowards:
https://github.com/elastic/response-ops-team/issues/209\r\n\r\n`connector_usage_reporting`
task is supposed to work only in serverless.\r\nAs there is no check for
that, even though it reports nothing, It was\r\nworking for on-prem and
cloud as well.\r\nThis PR deletes the `connector_usage_reporting` task
after the first run\r\nby checking if
`plugins.cloud.serverless.projectId` is missing.\r\n\r\n### To
verify:\r\nRun Kibana on this branch, then check the reporting task in
the console\r\nby running the below query.\r\nThere shouldn't be any
task.\r\n\r\n```\r\nGET .kibana_task_manager_*/_search\r\n{\r\n
\"query\": {\r\n \"prefix\": {\r\n \"task.taskType\": {\r\n \"value\":
\"actions:\"\r\n }\r\n }\r\n }\r\n}\r\n```\r\n\r\nThen remove or comment
out the line (`shouldDeleteTask: true`) added by\r\nthis PR and save the
file, Kibana will restart and register the task\r\nagain. You can use
the above query again to see that the task is
still\r\nregistered.","sha":"a1e97b1a43f2971dbf528201b3b82fb4b178b6bb"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199650","number":199650,"mergeCommit":{"message":"Delete
connector usage reporting task in on-prem and cloud
(#199650)\n\nTowards:
https://github.com/elastic/response-ops-team/issues/209\r\n\r\n`connector_usage_reporting`
task is supposed to work only in serverless.\r\nAs there is no check for
that, even though it reports nothing, It was\r\nworking for on-prem and
cloud as well.\r\nThis PR deletes the `connector_usage_reporting` task
after the first run\r\nby checking if
`plugins.cloud.serverless.projectId` is missing.\r\n\r\n### To
verify:\r\nRun Kibana on this branch, then check the reporting task in
the console\r\nby running the below query.\r\nThere shouldn't be any
task.\r\n\r\n```\r\nGET .kibana_task_manager_*/_search\r\n{\r\n
\"query\": {\r\n \"prefix\": {\r\n \"task.taskType\": {\r\n \"value\":
\"actions:\"\r\n }\r\n }\r\n }\r\n}\r\n```\r\n\r\nThen remove or comment
out the line (`shouldDeleteTask: true`) added by\r\nthis PR and save the
file, Kibana will restart and register the task\r\nagain. You can use
the above query again to see that the task is
still\r\nregistered.","sha":"a1e97b1a43f2971dbf528201b3b82fb4b178b6bb"}}]}]
BACKPORT-->

Co-authored-by: Ersin Erdal <[email protected]>
  • Loading branch information
kibanamachine and ersin-erdal authored Nov 26, 2024
1 parent 5ebf435 commit 678feac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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 @@ -144,6 +144,7 @@ export interface PluginSetupContract {
getActionsHealth: () => { hasPermanentEncryptionKey: boolean };
getActionsConfigurationUtilities: () => ActionsConfigurationUtilities;
setEnabledConnectorTypes: (connectorTypes: EnabledConnectorTypes) => void;

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

Expand Down Expand Up @@ -172,6 +173,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

0 comments on commit 678feac

Please sign in to comment.