Class BaseObservabilityFlowMetrics
java.lang.Object
cloud.opencode.base.flow.observability.BaseObservabilityFlowMetrics
- All Implemented Interfaces:
FlowMetrics
FlowMetrics adapter that forwards every event into a
MetricRegistry from opencode-base-observability.
Used implicitly when that module is present on the runtime classpath; see
FlowMetricsFactory.create().
FlowMetrics 适配器,把每次事件转发到 opencode-base-observability
的 MetricRegistry;当该模块在运行时类路径出现时由 FlowMetricsFactory.create()
隐式启用。
Emitted metrics:
flow.instance.started— counter, tagflow_keyflow.instance.completed— counter, tagsflow_key,statusflow.task.created— counter, tagsflow_key,step_idflow.task.completed— counter, tagsflow_key,step_id,outcomeflow.operation.duration— timer, tagtypeflow.todo.size— gauge (no tags); driven byupdateTodoSize(int)
- Since:
- JDK 25, opencode-base-flow V1.0.5
- Author:
- Leon Soo
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHard ceiling on the distinctflow_keytag-values this adapter will ever emit.static final StringSentinel tag value used when the per-tag cardinality cap is exceeded. -
Constructor Summary
ConstructorsConstructorDescriptionBaseObservabilityFlowMetrics(MetricRegistry registry) Constructs an adapter around the given registry. -
Method Summary
Modifier and TypeMethodDescriptionvoidrecordInstanceCompleted(String flowKey, InstanceStatus finalStatus) Records that a flow instance has reached a terminal state.voidrecordInstanceStarted(String flowKey) Records that a new flow instance has started.voidrecordOperationDuration(String type, Duration elapsed) Records the wall-clock elapsed time of a single operation.voidrecordTaskCompleted(String flowKey, String stepId, TaskOutcome outcome) Records that a task has been completed (approved / rejected / canceled).voidrecordTaskCreated(String flowKey, String stepId) Records that a PENDING task has been created.registry()Returns the underlying registry (visible for tests and host introspection).static MetricIdReturns the metric id used for theflow.todo.sizegauge.voidupdateTodoSize(int size) Updates the gauge for the current todo-queue size of an observed user (or aggregate, depending on the host application).
-
Field Details
-
MAX_TAG_CARDINALITY
public static final int MAX_TAG_CARDINALITYHard ceiling on the distinctflow_keytag-values this adapter will ever emit. Above this cap the tag is replaced withOVERFLOW_TAGto deny metric-cardinality DoS via attacker- controlled flowKeys / stepIds. 单个指标允许出现的 flow_key(或 step_id)唯一值上限;超过转入 _overflow_ 桶。- See Also:
-
OVERFLOW_TAG
Sentinel tag value used when the per-tag cardinality cap is exceeded.- See Also:
-
-
Constructor Details
-
BaseObservabilityFlowMetrics
Constructs an adapter around the given registry. 围绕给定 registry 构造适配器。- Parameters:
registry- the registry — 指标注册表- Since:
- JDK 25, opencode-base-flow V1.0.5
-
-
Method Details
-
registry
Returns the underlying registry (visible for tests and host introspection). 返回底层 registry(用于测试 / 宿主探测)。- Returns:
- the registry — 指标注册表
- Since:
- JDK 25, opencode-base-flow V1.0.5
-
recordInstanceStarted
Description copied from interface:FlowMetricsRecords that a new flow instance has started. 记录一次流程实例启动。- Specified by:
recordInstanceStartedin interfaceFlowMetrics- Parameters:
flowKey- business flow key — 业务 key
-
recordInstanceCompleted
Description copied from interface:FlowMetricsRecords that a flow instance has reached a terminal state. 记录一次流程实例达到终态。- Specified by:
recordInstanceCompletedin interfaceFlowMetrics- Parameters:
flowKey- business flow key — 业务 keyfinalStatus- the terminal status — 终态状态
-
recordTaskCreated
Description copied from interface:FlowMetricsRecords that a PENDING task has been created. 记录一次 PENDING 任务创建。- Specified by:
recordTaskCreatedin interfaceFlowMetrics- Parameters:
flowKey- business flow key — 业务 keystepId- step id — 节点 ID
-
recordTaskCompleted
Description copied from interface:FlowMetricsRecords that a task has been completed (approved / rejected / canceled). 记录一次任务完成(同意 / 驳回 / 取消)。- Specified by:
recordTaskCompletedin interfaceFlowMetrics- Parameters:
flowKey- business flow key — 业务 keystepId- step id — 节点 IDoutcome- final outcome (nullable when canceled) — 最终结果(取消时为 null)
-
recordOperationDuration
Description copied from interface:FlowMetricsRecords the wall-clock elapsed time of a single operation. 记录一次操作的墙钟耗时。- Specified by:
recordOperationDurationin interfaceFlowMetrics- Parameters:
type- operation type (start / approve / reject / vote / addSign / withdraw / transfer / circulate / terminate) — 操作类型elapsed- elapsed duration — 耗时
-
updateTodoSize
public void updateTodoSize(int size) Description copied from interface:FlowMetricsUpdates the gauge for the current todo-queue size of an observed user (or aggregate, depending on the host application). A negative value is a sentinel meaning "clear / reset to zero". 更新某用户(或聚合)的当前待办队列大小 gauge。传 -1 表示"清零"。- Specified by:
updateTodoSizein interfaceFlowMetrics- Parameters:
size- current size (or-1to clear) — 当前大小(-1表示清零)
-
todoSizeMetricId
Returns the metric id used for theflow.todo.sizegauge. Exposed so callers can locate the gauge in the registry snapshot. 返回flow.todo.sizegauge 的 MetricId,供调用方在 snapshot 中定位。- Returns:
- the metric id — 指标 ID
- Since:
- JDK 25, opencode-base-flow V1.0.5
-