go.temporal.io/server/components/nexusoperations/metrics.go
116 LOC · 48 covered · 68 uncovered · 18 ranges · 54 concepts · 11 introducers · 22 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package nexusoperations
import (
"strings"
"time"
chasmnexus "go.temporal.io/server/chasm/lib/nexusoperation"
nexusoperationpb "go.temporal.io/server/chasm/lib/nexusoperation/gen/nexusoperationpb/v1"
"go.temporal.io/server/common/metrics"
)
// metricTagConfig returns the configured metric tag config (nil-safe).
return e.Config.ResolvedMetricTagConfig()
}
// operationMetricsHandler returns a metrics handler enriched with caller-side Nexus operation
// tags. It mirrors chasm/lib/nexusoperation Operation.metricsHandler so the HSM and CHASM
// implementations emit identical metric names and labels (see the HSM->CHASM migration). Unlike
// CHASM, HSM Nexus operations are always in-workflow, so workflowType is always the real parent
// workflow type (there is no standalone placeholder case).
func operationMetricsHandler(
base metrics.Handler,
tagConfig chasmnexus.NexusMetricTagConfig,
op Operation,
namespaceName, workflowType string,
tags := []metrics.Tag{
metrics.NamespaceTag(namespaceName),
metrics.NexusEndpointTag(op.Endpoint),
metrics.WorkflowTypeTag(workflowType),
}
if tagConfig.IncludeServiceTag {
}
}
}
// emitOperationSucceeded emits the success counter and latency metrics for an operation that
// completed successfully.
func emitOperationSucceeded(base metrics.Handler, tagConfig chasmnexus.NexusMetricTagConfig, op Operation, namespaceName, workflowType string, closeTime time.Time) {
completion.go ×2
emitOperationOutcome(base, tagConfig, op, namespaceName, workflowType, nexusoperationpb.OPERATION_STATUS_SUCCEEDED, closeTime, chasmnexus.NexusOperationSuccessCount.With)
}
// emitOperationFailed emits the failure counter and latency metrics for an operation that
// failed non-retryably.
func emitOperationFailed(base metrics.Handler, tagConfig chasmnexus.NexusMetricTagConfig, op Operation, namespaceName, workflowType string, closeTime time.Time) {
metrics.go ×1
emitOperationOutcome(base, tagConfig, op, namespaceName, workflowType, nexusoperationpb.OPERATION_STATUS_FAILED, closeTime, chasmnexus.NexusOperationFailedCount.With)
}
// emitOperationCanceled emits the cancel counter and latency metrics for an operation that
// completed as canceled.
func emitOperationCanceled(base metrics.Handler, tagConfig chasmnexus.NexusMetricTagConfig, op Operation, namespaceName, workflowType string, closeTime time.Time) {
completion.go ×3
emitOperationOutcome(base, tagConfig, op, namespaceName, workflowType, nexusoperationpb.OPERATION_STATUS_CANCELED, closeTime, chasmnexus.NexusOperationCancelCount.With)
}
// emitOperationTimedOut emits the timeout counter (tagged with the timeout type) and latency
// metrics for an operation that timed out.
func emitOperationTimedOut(base metrics.Handler, tagConfig chasmnexus.NexusMetricTagConfig, op Operation, namespaceName, workflowType, timeoutType string, closeTime time.Time) {
executors.go ×3
emitOperationOutcome(base, tagConfig, op, namespaceName, workflowType, nexusoperationpb.OPERATION_STATUS_TIMED_OUT, closeTime, chasmnexus.NexusOperationTimeoutCount.With, metrics.TimeoutTypeTag(timeoutType))
}
// emitOperationOutcome records the terminal outcome counter and the shared latency metrics for a
// closed operation. The outcome-specific counter is supplied as a metric definition's With method
// (e.g. NexusOperationSuccessCount.With), so each per-outcome recorder differs only by its counter
// and any extra counter tags (the timeout type, for timeouts).
func emitOperationOutcome(
base metrics.Handler,
tagConfig chasmnexus.NexusMetricTagConfig,
op Operation,
namespaceName, workflowType string,
status nexusoperationpb.OperationStatus,
closeTime time.Time,
withCounter func(metrics.Handler) metrics.CounterIface,
counterTags ...metrics.Tag,
handler := operationMetricsHandler(base, tagConfig, op, namespaceName, workflowType)
withCounter(handler).Record(1, counterTags...)
emitCompletionLatencies(handler, op, closeTime, metrics.OutcomeTag(strings.ToLower(status.String())))
}
// emitCompletionLatencies emits schedule-to-close plus either start-to-close (operations that
// started) or schedule-to-start (sync / never-started), mirroring chasm/lib/nexusoperation's
// emitLatencyMetrics. It is shared by the per-outcome recorders above.
func emitCompletionLatencies(handler metrics.Handler, op Operation, closeTime time.Time, outcomeTag metrics.Tag) {
metrics.go ×4
if op.ScheduledTime == nil {
return
}
chasmnexus.NexusOperationScheduleToCloseLatency.With(handler).Record(closeTime.Sub(scheduledTime), outcomeTag)
if op.StartedTime != nil {
// Async operation that was started; schedule-to-start latency was emitted at start time.
metrics.go ×1
chasmnexus.NexusOperationStartToCloseLatency.With(handler).Record(closeTime.Sub(op.StartedTime.AsTime()), outcomeTag)
chasmnexus.NexusOperationScheduleToStartLatency.With(handler).Record(closeTime.Sub(scheduledTime))
}
}
// emitScheduleToStartLatency emits the schedule-to-start latency when an async operation starts.
func emitScheduleToStartLatency(
base metrics.Handler,
tagConfig chasmnexus.NexusMetricTagConfig,
op Operation,
namespaceName, workflowType string,
startedTime time.Time,
if op.ScheduledTime == nil {
return
}
handler := operationMetricsHandler(base, tagConfig, op, namespaceName, workflowType)
metrics.go ×2
chasmnexus.NexusOperationScheduleToStartLatency.With(handler).Record(startedTime.Sub(op.ScheduledTime.AsTime()))
}