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

Enriches slack message and upgrades workflow processor #44

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion executor/crud/playbooks_update_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def update_playbook(elem: PlayBook, update_op: UpdatePlaybookOp.UpdatePlaybook)
task.is_active = False
task.save(update_fields=['is_active'])
elem.is_active = False
elem.save(update_fields=['is_active'])
random_generated_str = str(uuid.uuid4())
elem.name = f"{elem.name}###(inactive)###{random_generated_str}"
elem.save(update_fields=['is_active', 'name'])
updated_playbook = update_op.playbook
updated_elem, err = create_db_playbook(elem.account, elem.created_by, updated_playbook)
if err:
Expand Down
23 changes: 16 additions & 7 deletions executor/workflows/action/notify_action_executor/slack_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@ def notify(self, config: WorkflowActionNotificationConfigProto, execution_output
blocks = []
for i, interpretation in enumerate(execution_output):
if interpretation.type == InterpretationProto.Type.SUMMARY:
blocks.append({
"type": "section",
"text": {
"type": "mrkdwn",
"text": f'Step {i + 1}: {interpretation.title.value}'
}
})
if interpretation.title.value.startswith('Hello team'):
blocks.append({
"type": "section",
"text": {
"type": "mrkdwn",
"text": interpretation.title.value
}
})
else:
blocks.append({
"type": "section",
"text": {
"type": "mrkdwn",
"text": f'Step {i + 1}: {interpretation.title.value}'
}
})
elif interpretation.type == InterpretationProto.Type.IMAGE:
blocks.append({
"type": "section",
Expand Down
5 changes: 3 additions & 2 deletions executor/workflows/crud/workflows_update_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ def update_workflow(elem: Workflow, update_op: UpdateWorkflowOp.UpdateWorkflow)
for action_mapping in all_workflow_actions_mapping:
action_mapping.is_active = False
action_mapping.save(update_fields=['is_active'])
elem.is_active = False
elem.save(update_fields=['is_active'])
random_generated_str = str(uuid.uuid4())
elem.name = f"{elem.name}###(inactive)###{random_generated_str}"
elem.save(update_fields=['is_active', 'name'])
updated_workflow = update_op.workflow
updated_elem, err = create_db_workflow(elem.account, elem.created_by, updated_workflow)
if err:
Expand Down
4 changes: 3 additions & 1 deletion executor/workflows/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ def workflow_action_execution(account_id, workflow_id, workflow_execution_id, pl
playbook_execution = playbook_executions.first()
pe_proto: PlaybookExecutionProto = playbook_execution.proto
pe_logs = pe_proto.logs
execution_output: [InterpretationProto] = playbook_execution_result_interpret(InterpreterType.BASIC_I, pe_logs)
p_proto = pe_proto.playbook
execution_output: [InterpretationProto] = playbook_execution_result_interpret(InterpreterType.BASIC_I, p_proto,
pe_logs)
workflow = workflows.first()
w_proto: WorkflowProto = workflow.proto
w_actions = w_proto.actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging

from google.protobuf.wrappers_pb2 import StringValue

from intelligence_layer.task_result_interpreters.metric_task_result_interpreters.basic_metric_task_interpreter import \
basic_metric_task_result_interpreter
from protos.playbooks.intelligence_layer.interpreter_pb2 import InterpreterType, Interpretation as InterpretationProto
from protos.playbooks.playbook_pb2 import PlaybookMetricTaskExecutionResult as PlaybookMetricTaskExecutionResultProto, \
PlaybookTaskDefinition as PlaybookTaskDefinitionProto, \
PlaybookTaskExecutionResult as PlaybookTaskExecutionResultProto, PlaybookExecutionLog
PlaybookTaskExecutionResult as PlaybookTaskExecutionResultProto, PlaybookExecutionLog, Playbook as PlaybookProto

logger = logging.getLogger(__name__)

Expand All @@ -19,9 +21,12 @@ def task_result_interpret(interpreter_type: InterpreterType, task: PlaybookTaskD
return basic_metric_task_result_interpreter(task, metric_task_result)


def playbook_execution_result_interpret(interpreter_type: InterpreterType,
def playbook_execution_result_interpret(interpreter_type: InterpreterType, playbook: PlaybookProto,
playbook_execution_logs: [PlaybookExecutionLog]) -> [InterpretationProto]:
interpretations: [InterpretationProto] = []
base_title = f'Hello team, here is snapshot of `{playbook.name.value}` that is configured for this alert'
interpretations: [InterpretationProto] = [
InterpretationProto(type=InterpretationProto.Type.SUMMARY, title=StringValue(value=base_title))
]
for log in playbook_execution_logs:
try:
interpretation_result = task_result_interpret(interpreter_type, log.task, log.task_execution_result)
Expand Down
Loading