Files
tasks/client/admin/metric_client.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

82 lines
2.5 KiB
Go

package admin
import (
"context"
"time"
"go.temporal.io/api/serviceerror"
"github.com/hanzoai/tasks/api/adminservice/v1"
"github.com/hanzoai/tasks/common/headers"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/log/tag"
"github.com/hanzoai/tasks/common/metrics"
"google.golang.org/grpc"
)
var _ adminservice.AdminServiceClient = (*metricClient)(nil)
type metricClient struct {
client adminservice.AdminServiceClient
metricsHandler metrics.Handler
throttledLogger log.Logger
}
// NewMetricClient creates a new instance of adminservice.AdminServiceClient that emits metrics
func NewMetricClient(
client adminservice.AdminServiceClient,
metricsHandler metrics.Handler,
throttledLogger log.Logger,
) adminservice.AdminServiceClient {
return &metricClient{
client: client,
metricsHandler: metricsHandler,
throttledLogger: throttledLogger,
}
}
func (c *metricClient) startMetricsRecording(
ctx context.Context,
operation string,
) (metrics.Handler, time.Time) {
caller := headers.GetCallerInfo(ctx).CallerName
metricsHandler := c.metricsHandler.WithTags(metrics.OperationTag(operation), metrics.NamespaceTag(caller), metrics.ServiceRoleTag(metrics.AdminRoleTagValue))
metrics.ClientRequests.With(metricsHandler).Record(1)
return metricsHandler, time.Now().UTC()
}
func (c *metricClient) finishMetricsRecording(
metricsHandler metrics.Handler,
startTime time.Time,
err error,
) {
if err != nil {
switch err.(type) {
case *serviceerror.Canceled,
*serviceerror.DeadlineExceeded,
*serviceerror.NotFound,
*serviceerror.QueryFailed,
*serviceerror.NamespaceNotFound,
*serviceerror.WorkflowNotReady,
*serviceerror.WorkflowExecutionAlreadyStarted:
// noop - not interest and too many logs
default:
c.throttledLogger.Info("admin client encountered error", tag.Error(err), tag.ServiceErrorType(err))
}
metrics.ClientFailures.With(metricsHandler).Record(1, metrics.ServiceErrorTypeTag(err))
}
metrics.ClientLatency.With(metricsHandler).Record(time.Since(startTime))
}
func (c *metricClient) StreamWorkflowReplicationMessages(
ctx context.Context,
opts ...grpc.CallOption,
) (_ adminservice.AdminService_StreamWorkflowReplicationMessagesClient, retError error) {
metricsHandler, startTime := c.startMetricsRecording(ctx, metrics.AdminClientStreamWorkflowReplicationMessagesScope)
defer func() {
c.finishMetricsRecording(metricsHandler, startTime, retError)
}()
return c.client.StreamWorkflowReplicationMessages(ctx, opts...)
}