Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Consolidate rpc client metrics logic #3147

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 47 additions & 5 deletions client/admin/metric_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,63 @@
package admin

import (
"go.temporal.io/api/serviceerror"

"go.temporal.io/server/api/adminservice/v1"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/common/metrics"
)

var _ adminservice.AdminServiceClient = (*metricClient)(nil)

type metricClient struct {
client adminservice.AdminServiceClient
metricsClient metrics.Client
client adminservice.AdminServiceClient
metricsClient metrics.Client
throttledLogger log.Logger
}

// NewMetricClient creates a new instance of adminservice.AdminServiceClient that emits metrics
func NewMetricClient(client adminservice.AdminServiceClient, metricsClient metrics.Client) adminservice.AdminServiceClient {
func NewMetricClient(
client adminservice.AdminServiceClient,
metricsClient metrics.Client,
throttledLogger log.Logger,
) adminservice.AdminServiceClient {
return &metricClient{
client: client,
metricsClient: metricsClient,
client: client,
metricsClient: metricsClient,
throttledLogger: throttledLogger,
}
}

func (c *metricClient) startMetricsRecording(
metricScope int,
) (metrics.Scope, metrics.Stopwatch) {
scope := c.metricsClient.Scope(metricScope)
scope.IncCounter(metrics.ClientRequests)
stopwatch := scope.StartTimer(metrics.ClientLatency)
return scope, stopwatch
}

func (c *metricClient) finishMetricsRecording(
scope metrics.Scope,
stopwatch metrics.Stopwatch,
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.ErrorType(err))
}
scope.Tagged(metrics.ServiceErrorTypeTag(err)).IncCounter(metrics.ClientFailures)
}
stopwatch.Stop()
}
Loading