After the async workflow execution is complete, I want to post metrics to another service. The metrics is a combination of the workflow info (start, close, execution duration) + workflow internal query state.
I’m trying to figure out what the best way to do this. Is there a mechanism that supports that?
One option that I can think of is to create an activity that gets executed at the end of the workflow. This activity can report the workflow’s internal query state. However, with this approach, it’s not clear to me how I would get the (workflow execution start, close, execution duration) other then executing the following call in the activity
DescribeWorkflowExecutionRequest request = DescribeWorkflowExecutionRequest.newBuilder() .setNamespace("default") .setExecution(WorkflowExecution.newBuilder().setWorkflowId(workflowId.toString())) .build(); DescribeWorkflowExecutionResponse response = stub.describeWorkflowExecution(request);
The other option is that I could just get
Workflow.getInfo.getRunStartedTimestampMillis() which I think is the start time and base on that I can get the current time which would be the close out time and subtract the two to get the execution duration.
However, with this approach I feel like the times could be a bit inaccurate since
- it’s using the worker machine time vs. the temporal server’s time
- There is a comment on the getRunStartedTimestampMillis() which states it can diff then the actual started execution time. Curious on why that would be the case?
/** * The time workflow run has started. Note that this time can be different from the time workflow * function started actual execution. */
Is there a way to trigger a callback once the async workflow completes? In the worker service, I could then just trigger a call to get the data and send it to the external service. I’m guessing this is probably not recommended since you want to do everything within the context of a workflow.
I also realize that setting up elastic search could prob solve this problem as well. Let’s say that I need a workaround before that is configured and setup properly.