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

feat: add audit for succesfull imports #192

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

johanseto
Copy link
Collaborator

@johanseto johanseto commented Jul 8, 2024

Description

add audit to pipelines

Testing instructions

Before

After

image

Additional information

Include anything else that will help reviewers and consumers understand the change.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.
  • Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions.

Checklist for Merge

  • Tested in a remote environment
  • Updated documentation
  • Rebased master/main
  • Squashed commits

Copy link
Collaborator

@andrey-canon andrey-canon left a comment

Choose a reason for hiding this comment

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

why you modified current pipeline steps instead of adding a general pipeline step that allows to audit the whole process ?

@johanseto
Copy link
Collaborator Author

why you modified current pipeline steps instead of adding a general pipeline step that allows to audit the whole process ?

I think the scope was only for the successful import, do you think I would audit all the pipeline execution?

@johanseto johanseto force-pushed the jlc/audit-successfull-import branch from 95f0023 to abbc564 Compare July 9, 2024 22:10
@github-actions github-actions bot added size/m m lines label and removed size/s labels Jul 9, 2024
@johanseto johanseto force-pushed the jlc/audit-successfull-import branch from b364213 to 8505e35 Compare July 10, 2024 13:03
@@ -613,3 +614,43 @@ def get_enrollment_from_id(enrollment_id, enrollment=None, **kwargs): # pylint:
pass

return {}


def save_audit_pipeline(pipeline_backend, last_step, cdd_import=None, ead_import=None, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

As you mentioned this is not a pipeline step, so I don't understand why you included this in the pipeline file, anyway I wondering why you split the logic into this method and audit pipeline decorator

Comment on lines 626 to 627
cdd_import (dict, optional): Defaults to None.
ead_import (dict, optional): Defaults to None.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why ? this implementation is too specific, you are assuming in advanced that the backend will implement cdd and ead pipelines steps and that is not true, probably your answer will include that there are some default values but again this code was written to work with something specific instead of a general solution

Comment on lines 632 to 637
def executed_pipeline(
pipeline_backend,
last_step,
cdd_import,
ead_import,
**kwargs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def executed_pipeline(
pipeline_backend,
last_step,
cdd_import,
ead_import,
**kwargs
def executed_pipeline(
backend_name,
last_pipeline_step,
backend_data,

Comment on lines 644 to 648
logger.info(
"Succesfull imports. cdd_import: %s. ead_import: %s",
cdd_import,
ead_import,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
logger.info(
"Succesfull imports. cdd_import: %s. ead_import: %s",
cdd_import,
ead_import,
)

Since this is not a general implementation

return func(self, *args, **kwargs)
finally:
if self.use_audit_pipeline and not self.backend_data.get("catched_pearson_error"):
save_audit_pipeline(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just a simple log, why you didn't include the logic here ?

save_audit_pipeline(
pipeline_backend=self.__class__.__name__,
last_step=self.get_pipeline()[self.backend_data.get("pipeline_index", 0)].__name__,
**self.backend_data
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
**self.backend_data
backend_data=self.backend_data

@@ -53,15 +78,17 @@ class AbstractBackend(ABC):
handle_error(exception: Exception, failed_step_pipeline: str): Handles errors during pipeline execution.
"""

def __init__(self, **kwargs):
def __init__(self, use_audit_pipeline=True, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The advantage of this is that you can change the backend behavior based on the initialization, but do we need that?, it's not better stable backends whose execution or behavior is always the same ?

Suggested change
def __init__(self, use_audit_pipeline=True, **kwargs):
use_audit_pipeline=True
def __init__(self, **kwargs):

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, but then I must apply the decorator to the specific pipeline backend. Otherwise I would get something like this.
https://edunext.stage.nelp.gov.sa/admin/eox_audit_model/auditmodel/32026/change/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can see the error pipeline is also audited.

Copy link
Collaborator

Choose a reason for hiding this comment

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

what happen if you override that in the subclass ?

validate_cdd_request,
validate_ead_request,
)


def audit_pipeline(func):
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you please move this to a decorators.py file ?

@johanseto johanseto force-pushed the jlc/audit-successfull-import branch from 8505e35 to ef9a5b4 Compare July 12, 2024 01:01
@github-actions github-actions bot added size/s and removed test size/m m lines label labels Jul 12, 2024
Copy link
Collaborator

@andrey-canon andrey-canon left a comment

Choose a reason for hiding this comment

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

why did you remove some things like the use_audit_pipeline and the catched_pearson_error?

@@ -227,7 +227,7 @@ def import_candidate_demographics(cdd_request, **kwargs): # pylint: disable=unu
response = api_client.import_candidate_demographics(payload)

if response.get("status", "error") == "accepted":
return response
return {"cdd_import": response}
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you think we will need this ?

@@ -276,7 +276,7 @@ def import_exam_authorization(ead_request, **kwargs): # pylint: disable=unused-
response = api_client.import_exam_authorization(payload)

if response.get("status", "error") == "accepted":
return response
return {"ead_import": response}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comments as above

@johanseto
Copy link
Collaborator Author

why did you remove some things like the use_audit_pipeline and the catched_pearson_error?

The use audit because don't you recommend using the override in the run_pipeline method?

@andrey-canon
Copy link
Collaborator

why did you remove some things like the use_audit_pipeline and the catched_pearson_error?

The use audit because don't you recommend using the override in the run_pipeline method?

Nop, there was a misunderstanding, my previous recommendation was to test use_audit_pipeline as attribute class and then override that in the subclass

class AbstractBackend(ABC):
    use_audit_pipeline=True

class ErrorRealTimeImportHandler(AbstractBackend):
    use_audit_pipeline=False

@github-actions github-actions bot added the test label Jul 12, 2024
@johanseto johanseto marked this pull request as ready for review July 12, 2024 21:32
@johanseto johanseto merged commit a640038 into master Jul 12, 2024
7 checks passed
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.

2 participants