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

Clean up empty IOC indices created by failed source configs #1267

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

jowg-amazon
Copy link
Collaborator

Description

Deletes and cleans up any ioc indices that were created by failed source configs. Also manually deletes the job scheduler lock for source configs that have the job disabled. When a source config job is enabled and then the source config is deleted, the lock is automatically deleted. However, the lock is not cleaned up if the job is disabled. This PR adds a change to check whether or not the job is enabled, if not then it will manually delete the associated lock when source config is deleted.

Related Issues

Resolves #1255

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Joanne Wang <[email protected]>
return;
}

String id = SecurityAnalyticsPlugin.JOB_INDEX_NAME + "-" + saTifSourceConfig.getId();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to clarify, we don't need to convert this string to lowercase because this ID of the document in the JOB_INDEX_NAME is literally SecurityAnalyticsPlugin.JOB_INDEX_NAME + "-" + saTifSourceConfig.getId(), right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, here's an example of what the id in the job scheduler lock index looks like .opensearch-sap--job-Q3l1dpEBFBLkuvfJmI5a

AWSHurneyt
AWSHurneyt previously approved these changes Aug 22, 2024
engechas
engechas previously approved these changes Aug 22, 2024

// check to make sure the job scheduler lock index exists
if (clusterService.state().metadata().hasIndex(LOCK_INDEX_NAME) == false) {
actionListener.onFailure(SecurityAnalyticsException.wrap(new OpenSearchStatusException("Threat intel job scheduler lock index does not exist", RestStatus.BAD_REQUEST)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've seen this done both ways and I think either can make sense based on the situation. We can either

  1. Treat the index missing as a failure since we intended to delete something and could not (current approach)
  2. Treat the index missing as success since we intended to delete something but it did not exist so we have fulfilled the request to delete it

It would be worth considering when this API would be invoked to decide whether 1 or 2 is the correct behavior. I could see things like operator intervention resulting in the lock index being deleted and we should be sure that would not cause permanent failures/further issues if we go with approach 1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, this is only called when we want to clean up and delete everything related to the source config that's being deleted so i think the second option makes more sense in this case. Updated the code to not fail when the index doesn't exist or if the document is not found.

Comment on lines 403 to 414
if (deleteResponse.status().equals(RestStatus.OK)) {
log.info("Deleted threat intel job scheduler lock [{}] successfully", id);
actionListener.onResponse(deleteResponse);
} else if (deleteResponse.status().equals(RestStatus.NOT_FOUND)) {
actionListener.onFailure(SecurityAnalyticsException.wrap(new OpenSearchStatusException(String.format(Locale.getDefault(), "Threat intel job scheduler lock with id [{%s}] not found", id), RestStatus.NOT_FOUND)));
} else {
actionListener.onFailure(SecurityAnalyticsException.wrap(new OpenSearchStatusException(String.format(Locale.getDefault(), "Failed to delete threat intel job scheduler lock with id [{%s}]", id), deleteResponse.status())));
}
}, e -> {
log.error("Failed to delete threat intel job scheduler lock with id [{}]", id);
actionListener.onFailure(e);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make sure we have unit tests for all of these scenarios

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, will do in a follow up PR and added a github issue to increase our code cov and integ testing overall: #1268

@jowg-amazon jowg-amazon merged commit 0920e47 into opensearch-project:main Aug 23, 2024
16 of 19 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 23, 2024
* cleanup empty iocs and lock

Signed-off-by: Joanne Wang <[email protected]>

* change action listener response

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit 0920e47)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 23, 2024
* cleanup empty iocs and lock

Signed-off-by: Joanne Wang <[email protected]>

* change action listener response

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit 0920e47)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 23, 2024
* cleanup empty iocs and lock

Signed-off-by: Joanne Wang <[email protected]>

* change action listener response

Signed-off-by: Joanne Wang <[email protected]>

---------

Signed-off-by: Joanne Wang <[email protected]>
(cherry picked from commit 0920e47)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
jowg-amazon pushed a commit that referenced this pull request Aug 23, 2024
…1269)

* cleanup empty iocs and lock



* change action listener response



---------


(cherry picked from commit 0920e47)

Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
jowg-amazon pushed a commit that referenced this pull request Aug 23, 2024
…1270)

* cleanup empty iocs and lock



* change action listener response



---------


(cherry picked from commit 0920e47)

Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
jowg-amazon pushed a commit that referenced this pull request Aug 24, 2024
…1271)

* cleanup empty iocs and lock



* change action listener response



---------


(cherry picked from commit 0920e47)

Signed-off-by: Joanne Wang <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Empty IOC indices created even when source config index creation fails
3 participants