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

[Backend] Enhance retention policy deletion performances / speed (#4864) #8569

Merged
merged 3 commits into from
Oct 4, 2024

Conversation

richard-julien
Copy link
Member

See #4864

@github-actions github-actions bot added the filigran team use to identify PR from the Filigran team label Oct 1, 2024
@richard-julien richard-julien self-assigned this Oct 1, 2024
@richard-julien richard-julien linked an issue Oct 1, 2024 that may be closed by this pull request
@richard-julien richard-julien removed their assignment Oct 1, 2024
Copy link

codecov bot commented Oct 1, 2024

Codecov Report

Attention: Patch coverage is 28.88889% with 32 lines in your changes missing coverage. Please review.

Project coverage is 66.24%. Comparing base (cec4c9e) to head (1dce179).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...rm/opencti-graphql/src/manager/retentionManager.ts 37.93% 18 Missing ⚠️
...tform/opencti-graphql/src/manager/managerModule.ts 10.00% 9 Missing ⚠️
...atform/opencti-graphql/src/domain/retentionRule.js 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8569      +/-   ##
==========================================
+ Coverage   66.22%   66.24%   +0.02%     
==========================================
  Files         597      597              
  Lines       60433    60428       -5     
  Branches     6202     6212      +10     
==========================================
+ Hits        40022    40032      +10     
+ Misses      20411    20396      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

logApp.error(e, { id: node.id, manager: 'RETENTION_MANAGER' });
}
};
await BluePromise.map(elements, deleteFn, { concurrency: RETENTION_MAX_CONCURRENCY });
Copy link
Member

@labo-flg labo-flg Oct 2, 2024

Choose a reason for hiding this comment

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

Just for my understanding: if we batch elements that are interdependent, the first one might take a lock on another one in the concurrent batch, and when release, the second element to delete might already be deleted (for instance if it's a relationship). Am I right ?

If so, not harmful but we'll end up with a bunch of error logs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Add code to prevent logging for an already deleted error

labo-flg
labo-flg previously approved these changes Oct 2, 2024
Copy link
Member

@labo-flg labo-flg left a comment

Choose a reason for hiding this comment

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

Beside my comment on error logs, code seems ok to me !

@Archidoit
Copy link
Member

Archidoit commented Oct 2, 2024

I created a retention policy with no filters and with retention = 1 day. It should delete all the entities of my platform.
I have this error in backend every few seconds:
image

And if I restart my platform :
image

I think it's due to this modification :
image

@@ -42,7 +45,7 @@ export const getElementsToDelete = async (context: AuthContext, scope: string, b
if (scope === 'knowledge') {
const jsonFilters = filters ? JSON.parse(filters) : null;
const queryOptions = await convertFiltersToQueryOptions(jsonFilters, { before });
result = await elPaginate(context, RETENTION_MANAGER_USER, READ_STIX_INDICES, { ...queryOptions, first: RETENTION_BATCH_SIZE });
result = await elPaginate(context, RETENTION_MANAGER_USER, READ_ENTITIES_INDICES_WITHOUT_INFERRED, { ...queryOptions, first: RETENTION_BATCH_SIZE });
Copy link
Member

@Archidoit Archidoit Oct 2, 2024

Choose a reason for hiding this comment

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

why this modification?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch, it was a test. Will rollback

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@Archidoit Archidoit dismissed labo-flg’s stale review October 2, 2024 10:01

retention rule also deletes internal objects

@Archidoit
Copy link
Member

Archidoit commented Oct 3, 2024

I created a retention policy on everything (Knowledge). It's indicating 512 elements will be deleting.
image

The retention rules is launched every 30s.
After 2 minutes nothing has been deleted. And when we 'test' the retention rule, the number of entities to be deleted is still the same :
image
-->entities have not been deleted
image

This didn't happen for a retention policy with a filter, and so targeting less elements (exemple done with 2 reports to delete: the reports where deleted).

@Archidoit
Copy link
Member

Archidoit commented Oct 3, 2024

The 'remaining' attribute seems not correct.
With this retention rule indicating 25 entities are 'remaining' while I only see 1 left :
image

@Archidoit
Copy link
Member

Archidoit commented Oct 3, 2024

Behavior ok 👍

Small question: With a retention rule on Knowledge with no filters, organizations are also deleted (because they are stix domain objects)... Is it a problem?

Archidoit
Archidoit previously approved these changes Oct 3, 2024
@Archidoit
Copy link
Member

Archidoit commented Oct 4, 2024

I don't really agree with the last commit that prevents empty filters for several reasons :

  • we avoid empty filters in UI but not in the API
  • there is no messages in the UI informing the Create button is disabled because filters are now mandatory
  • the problem is not really solved because if we add the filter: 'label different from label1' we will still delete the organization that haven't label1

--> I think that if we don't want to delete organizations we should think about it a bit more, maybe add a warning if a retention rule may delete organizations...

@Archidoit
Copy link
Member

I don't really agree with the last commit that prevents empty filters for several reasons :

  • we avoid empty filters in UI but not in the API
  • there is no messages in the UI informing the Create button is disabled because filters are now mandatory
  • the problem is not really solved because if we add the filter: 'label different from label1' we will still delete the organization that haven't label1

--> I think that if we don't want to delete organizations we should think about it a bit more, maybe add a warning if a retention rule may delete organizations...

Since it is not the scope, I reverted the last commit and created an issue for the organization deletion issue : #8606

@labo-flg labo-flg merged commit 649af4f into master Oct 4, 2024
7 checks passed
@labo-flg labo-flg deleted the issue/4864 branch October 4, 2024 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filigran team use to identify PR from the Filigran team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance retention policy deletion performances / speed
3 participants