我想在 Prometheus 中监控当前运行的 cadence 工作流数量。
我检查了不同节奏服务导出的指标(例如 cadence_history
、 cadence_worker
、 cadence_frontend
等),我能找到的唯一与工作流程相关的指标是:
-
activity_end_to_end_latency histogram
(workflowType
是标签之一) -
workflow_success counter
/workflow_terminate counter
/workflow_failed counter
因此,似乎有一些指标可以分析已经完成的工作流程,但没有有关当前工作流程的信息。我是对的还是我错过了什么?
这意味着我必须自己导出所需的指标,并且我看到了两种可能的解决方案:
- 创建一个仪表并在工作流程开始和停止时递增/递减它,例如:
func MyWorkflow(ctx workflow.Context) error {
mymetrics.gauge.Inc()
if err := workflow.ExecuteActivity(ctx, someActivity).Get(ctx, nil); err != nil {
mymetrics.gauge.Dec()
return err
}
// ...
mymetrics.gauge.Dec()
return nil
}
这种方法的缺点是无法正确测量由用户手动终止的工作流程。
- 创建一个 prometheus 导出器并使用
cadence.client.ListOpenWorkflow
函数收集正在运行的工作流程的数量。然而,cadence 文档说“大量使用这个 API 可能会导致巨大的持久性压力”,所以我认为在 prometheus 导出器中调用它是一个非常糟糕的主意。
您认为还有其他可能的解决方案吗?
最佳答案
So it seems that there are metrics to analyze already completed workflows, but no information about current ones. Am I right or I missed something?
没错。没有发出类似的指标。
However, the cadence docs says that "heavy usage of this API may cause huge persistence pressure"
如果您使用Advanced Visibility,则事实并非如此。使用 ElasticSearch。
但如果使用高级可见性,您应该使用“CountWorkflowExecution”API。这将更有效地计算打开的工作流程。
如果使用基本可见性,如果数量非常大,则可能会出现持久性性能问题。因为您必须迭代页面才能获取数字。
关于cadence-workflow - 如何测量节奏中正在运行的工作流程数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72637962/