-
Notifications
You must be signed in to change notification settings - Fork 32
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
Jobflow engine - Findings and recommendations #5044
Labels
Comments
We will discuss this in the daily meeting of 2024/03/11 or 2024/03/13 -> Blocked internal |
rauldpm
changed the title
DTT1 iteration 3 - Workflow engine. Braimstorming, review and Call to Action.
DTT1 - Iteration 3 - Workflow engine. Braimstorming, review and Call to Action.
Mar 18, 2024
Move this issue to #4495 as epic |
fcaffieri
changed the title
DTT1 - Iteration 3 - Workflow engine. Braimstorming, review and Call to Action.
DTT2 - Iteration 1 - Workflow engine. Braimstorming, review and Call to Action.
Mar 18, 2024
This issue will be include in DTT Tier 2 |
fcaffieri
changed the title
DTT2 - Iteration 1 - Workflow engine. Braimstorming, review and Call to Action.
DTT2 - Iteration 1 - Workflow engine best practice
Mar 18, 2024
3 tasks
mhamra
changed the title
DTT2 - Iteration 1 - Workflow engine best practice
DTT2 - Iteration 1 - Workflow engine - Findings and recommendations
Mar 19, 2024
rauldpm
changed the title
DTT2 - Iteration 1 - Workflow engine - Findings and recommendations
DTT2 - Workflow engine - Findings and recommendations
Mar 21, 2024
6 tasks
6 tasks
12 tasks
juliamagan
changed the title
DTT2 - Workflow engine - Findings and recommendations
Jobflow engine - Findings and recommendations
Aug 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
While developing the unit tests for DTT1 iteration 3 - Workflow engine, I had the opportunity to review the workflow engine source code thoroughly. I list the findings in this issue for discussion and triage of several requests that the team will assess to improve the code quality, endurance, and maintainability.
Code Style Remarks and Best Practices:
Exception handling Best Practices
raise xxx from e
Exception
class. It is preferred that the original exception be bubbled.graphlib.is used.TopologicalSorter
is instantiated. The add method of this class generates a ValueError exception, and the prepare method raises a CycleError. Those errors should be handled so they can be logged as errors in the workflow log file. The user should receive the original exception (using chaining) and a more informative message whenever possible.Import statements
import
statements with unused Classes, functions, etc.Suggestions and Ideas
Click
library instead of the standardargparse
to handle command line arguments. It is more powerful and more straightforward to use. The parameters are implemented with decorators. I leave the link: https://click.palletsprojects.com/en/8.1.x/Requested fixes - cosmetics and bugs
pass
statements in abstract methods; they are marked bypylint
as unnecessary.Design and Architecture
Check the parallel libraries used to execute tasks. Threads are being used in the
WorkflowProcessor
class. Multithread programming is not 100% "parallel" due to a limitation of Python, the Global Interpreter Lock (GIL). It will always run only one thread at a time, never in true parallel. GIL switches execution to another thread when a thread is blocked waiting for an Input/Output operation. We must consider whether this covers our requirements. If the only thing the workflow will do is to spawn processes like theProcessTask.execute
function (that calls thesubprocess.run
function to run a script with parameters and catches thestd output
andstderr
), the Threading libraries may be enough.WorkflowProcessor
constructorwazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 268 to 283 in 39e5f11
WorkflowProcessor.dry_run
instance variable and changing theWorkflowProcessor.run
function signature to accept adry_run
optional parameter.wazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 353 to 356 in 39e5f11
I recommend changing the name of the
WorkflowProcessor.threads
instance variable toWorkflowProcessor.max_threads_count
to clarify its purpose.WorkflowProcessor.log_level
instance variable and moving the log configuration outside the class. This will reduce the responsibilities of this class. Indeed, if manyWorkflowProcessor
instances will be created, each new instance will redefine the log level. The log level is global to the program; it is not particular to each instance.WorkflowProcessor
constructor creates a WorkflowFile instance, creating a dependency. Options:WorkflowProcessor
instances.task_collection
.WorkflowProcessor.run
function to use this instance variable.wazuh-qa/deployability/modules/workflow_engine/__main__.py
Lines 31 to 32 in 39e5f11
I propose creating a global configuration object from a
yaml
config file. In the current design, theworflow_engine.main.py
entry point parses the command arguments and converts them to a dictionary passed directly to theWorkflowProcessor
constructor. If a new parameter is defined in the future, the class constructor must be changed. The global configuration can be accessed for any class that should be globally parameterized in the future.logger.py
file tologging.py
. Theimport from workflow_engine.logger.logger import logger
is lengthy and repetitive. The logger can also be imported in the subpackage__nit__.py
file. This way, the import is reduced tofrom workflow_engine.logging import logger
.ProcessTask.task_parameters
fromProcessTask.execute
to theProcessTask
constructor.wazuh-qa/deployability/modules/workflow_engine/task.py
Lines 36 to 41 in 39e5f11
ProcessTask.execute
has a bug that needs to be fixed. The statementif "KeyboardInterrupt" in error_msg:
generates an exception because the error_msg variable isNone
. Thestderr
parameter must be defined when theCalledProcessError
is raised.wazuh-qa/deployability/modules/workflow_engine/task.py
Lines 67 to 73 in 39e5f11
DAG.set_status
function. Thetask_name
must be in thetask_collection,
the status must be one of these values: failed, canceled, or successful.wazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 181 to 184 in 39e5f11
task status
,cancel_policies
, etc. One example is in this constructor:wazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 154 to 167 in 39e5f11
cancel_policy
parameter of theDAG.cancel_dependant_task
cancel from thefor
loop to the beginning of the function.wazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 209 to 232 in 39e5f11
WorflowProcessor.execute_task
function logs the elapsed time only for the normal flow. I recommend logging the elapsed time on exceptions, too.wazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 295 to 307 in 39e5f11
WorflowProcessor.execute_tasks_parallel
exception handler. The exception handler calls the same function recursively with the parameterreverse=True.
The call could lead to an infinite loop if the KeyboardInterrupt is raised again. I consider that this function should be called only if thereverse
parameter isFalse
wazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 323 to 332 in 39e5f11
WorkflowProcessor.abort_execution
method because it is not referred to by any other file in theworflow_engine
module.element
parameter type of the functionWorfkowFile.__replace_placeholders
. It is defined asstr,
but it should be of typeAny.
wazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 77 to 87 in 39e5f11
I suggest reviewing the usage of the
parent_key
parameter of the functionWorfkowFile.__replace_placeholders
. The parameter doesn't influence the function's output value. If it is maintained, I suggest defining it asparent_key: Optional[String] = None.
WorkflowFile.__static_workflow_validation.check_not_existing_tasks
. The function raises theValueError
when a task is not found in a task'sdepends-on
key in the task_collection. It would be better to raise the ValueError after checking all the tasks.wazuh-qa/deployability/modules/workflow_engine/workflow_processor.py
Lines 140 to 147 in 39e5f11
SchemaValidator.preprocess_data
function validates that the 'path' entry exists for theprocess
tasks types but doesn't validate if thepath
entry is an empty string. I suggest adding this validation.wazuh-qa/deployability/modules/workflow_engine/schema_validator.py
Lines 55 to 75 in 39e5f11
SchemaValidator.validaSchema
function logs the ValidationError and Exception exceptions to the log but does not re-raise the exception to the caller. I suggest re-raising the exception.wazuh-qa/deployability/modules/workflow_engine/schema_validator.py
Lines 85 to 90 in 39e5f11
The text was updated successfully, but these errors were encountered: