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] add executionTrace table #2296

Open
wants to merge 11 commits into
base: release/current
Choose a base branch
from
Open

Conversation

MarineLeM
Copy link
Contributor

@MarineLeM MarineLeM commented Jan 24, 2025

Proposed changes

  • Extract the status_executions field from InjectStatus and create a new table called ExecutionTrace.
  • Replace the status_executions field across the entire project with references to the new ExecutionTrace table.
  • Remove any unused fields from the InjectStatus entity.
  • Refactor the compute Status function

Related issues

@MarineLeM MarineLeM self-assigned this Jan 27, 2025
Copy link

codecov bot commented Jan 27, 2025

Codecov Report

Attention: Patch coverage is 18.30601% with 299 lines in your changes missing coverage. Please review.

Project coverage is 36.33%. Comparing base (3854057) to head (72e1416).
Report is 2 commits behind head on release/current.

Files with missing lines Patch % Lines
...enbas/rest/inject/service/InjectStatusService.java 28.33% 79 Missing and 7 partials ⚠️
...caldera/service/CalderaResultCollectorService.java 4.25% 45 Missing ⚠️
...as/migration/V3_62__Add_ExecutionTraces_table.java 24.13% 43 Missing and 1 partial ⚠️
.../io/openbas/injectors/caldera/CalderaExecutor.java 0.00% 27 Missing ⚠️
...io/openbas/execution/ExecutionExecutorService.java 0.00% 19 Missing ⚠️
...io/openbas/scheduler/jobs/InjectsExecutionJob.java 0.00% 18 Missing ⚠️
.../openbas/injectors/email/service/EmailService.java 33.33% 9 Missing and 1 partial ⚠️
.../io/openbas/injectors/channel/ChannelExecutor.java 0.00% 6 Missing ⚠️
...nbas/injectors/opencti/service/OpenCTIService.java 0.00% 6 Missing ⚠️
...n/java/io/openbas/injectors/lade/LadeExecutor.java 0.00% 5 Missing ⚠️
... and 14 more
Additional details and impacted files
@@                  Coverage Diff                  @@
##             release/current    #2296      +/-   ##
=====================================================
+ Coverage              36.16%   36.33%   +0.16%     
- Complexity              1653     1659       +6     
=====================================================
  Files                    589      593       +4     
  Lines                  18066    18122      +56     
  Branches                1176     1193      +17     
=====================================================
+ Hits                    6533     6584      +51     
+ Misses                 11207    11205       -2     
- Partials                 326      333       +7     

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

@MarineLeM MarineLeM marked this pull request as ready for review January 27, 2025 15:41
@MarineLeM MarineLeM requested a review from damgouj January 27, 2025 15:41
Signed-off-by: Marine LM <[email protected]>
Copy link
Member

@damgouj damgouj left a comment

Choose a reason for hiding this comment

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

Tests OK for me : Caldera agent, OBAS agent, mail, sms.
Just few comments and maybe "Payload completed" for this one ?
image
Good work, thanks !
PS : be careful, you have got some tests issues in the CI.

this.injectRepository,
this.injectStatusRepository,
this.calderaService,
this.injectStatusService);
Copy link
Member

Choose a reason for hiding this comment

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

You pass injectStatusService + injectStatusRepository ? You can't pass the service only ? Because injectStatusService uses injectStatusRepository

}
}

if (successCount > 0 && errorCount == 0 && maybePreventedCount == 0 & partialCount == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

& alone in your if, is it normal ? Same below

}

injectStatus.addTrace(
ExecutionTraceStatus.INFO, "Process finish", ExecutionTraceAction.PROCESS_FINISH, null);
Copy link
Member

Choose a reason for hiding this comment

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

Process finished ?

@@ -32,56 +29,20 @@ public abstract class BaseInjectStatus implements Base {
@NotNull
private ExecutionStatus name;

// region dates tracking
@Column(name = "status_executions")
Copy link
Member

Choose a reason for hiding this comment

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

question: Do we need a migration for old execution ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why we shouldn't ? Because status_executions in the inject_statuses table would only be used for old executed injects while also having a relation to ExecutionTrace. This is confusing since both represent the same thing, leading to redundancy and unclear data relationships.

@@ -32,26 +32,11 @@ public String getName() {

@Builder.Default
@JsonProperty("status_traces")
private List<InjectStatusExecution> traces = new ArrayList<>();
private List<ExecutionTraces> traces = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

question: Do we need an ExecutionTracesOutput ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be done in the next chunk since you'll be working on what to send to the frontend. But if you prefer I can clean it now ?

import lombok.Getter;

@Getter
public class DetailedException extends RuntimeException {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: I am not a big fan of this nomenclature.
But, I don't have any other idea.

@@ -34,6 +38,7 @@ public class ExecutionExecutorService {
private final OpenBASExecutorContextService openBASExecutorContextService;
private final InjectStatusRepository injectStatusRepository;

@Transactional
Copy link
Member

Choose a reason for hiding this comment

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

issue: Why we have a transactional here ? If we have any error not handle in the try catch, we will loop on error for a specific inject.

@@ -96,7 +96,7 @@ public List<DataAttachment> resolveAttachments(
doc.getName(), doc.getOriginalFilename(), content, doc.getContentType()));
} catch (Exception e) {
String message = "Error getting direct attachment " + doc.getName();
execution.addTrace(traceError(message));
execution.addTrace(getNewErrorTrace(message, ExecutionTraceAction.EXECUTION));
Copy link
Member

Choose a reason for hiding this comment

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

question: Why having an EXECUTION here ?
It's an internal process, we don't do anything on the inject itself.

Comment on lines 45 to 48
@Column(name = "status_executions")
@Convert(converter = InjectStatusExecutionConverter.class)
@JsonProperty("status_traces")
private List<InjectStatusExecution> traces = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

question: Why we don't have the same bahavior as for InjectStatus ?

@@ -12,9 +12,6 @@
@Setter
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: I am not sure it's a good idea to have two model: one for test and one for real action.

@savacano28
Copy link
Contributor

savacano28 commented Jan 29, 2025

It's great to have this level of granularity in the traces :). 🎉

Tests : ✅

  • Email, sms, caldera, challenge, channel, obas
  • Asset group, asset (active, inactive), atomic testing and exercise
  • Traces complete, finished | info, asset_inactive | maybe prevented, success, error, partial


CLEANUP_EXECUTION,
COMPLETE, // when inject of one asset is finish, or of one user
PROCESS_FINISH // inject is completely done
Copy link
Member

Choose a reason for hiding this comment

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

Should be removed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants