How to use Metrics method of client Package

Best K6 code snippet using client.Metrics

metric_client_gen.go

Source:metric_client_gen.go Github

copy

Full Screen

1// The MIT License2//3// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.4//5// Copyright (c) 2020 Uber Technologies, Inc.6//7// Permission is hereby granted, free of charge, to any person obtaining a copy8// of this software and associated documentation files (the "Software"), to deal9// in the Software without restriction, including without limitation the rights10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell11// copies of the Software, and to permit persons to whom the Software is12// furnished to do so, subject to the following conditions:13//14// The above copyright notice and this permission notice shall be included in15// all copies or substantial portions of the Software.16//17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN23// THE SOFTWARE.24// Code generated by cmd/tools/rpcwrappers. DO NOT EDIT.25package frontend26import (27 "context"28 "go.temporal.io/api/workflowservice/v1"29 "google.golang.org/grpc"30 "go.temporal.io/server/common/metrics"31)32func (c *metricClient) CountWorkflowExecutions(33 ctx context.Context,34 request *workflowservice.CountWorkflowExecutionsRequest,35 opts ...grpc.CallOption,36) (*workflowservice.CountWorkflowExecutionsResponse, error) {37 c.metricsClient.IncCounter(metrics.FrontendClientCountWorkflowExecutionsScope, metrics.ClientRequests)38 sw := c.metricsClient.StartTimer(metrics.FrontendClientCountWorkflowExecutionsScope, metrics.ClientLatency)39 resp, err := c.client.CountWorkflowExecutions(ctx, request, opts...)40 sw.Stop()41 if err != nil {42 c.metricsClient.IncCounter(metrics.FrontendClientCountWorkflowExecutionsScope, metrics.ClientFailures)43 }44 return resp, err45}46func (c *metricClient) CreateSchedule(47 ctx context.Context,48 request *workflowservice.CreateScheduleRequest,49 opts ...grpc.CallOption,50) (*workflowservice.CreateScheduleResponse, error) {51 c.metricsClient.IncCounter(metrics.FrontendClientCreateScheduleScope, metrics.ClientRequests)52 sw := c.metricsClient.StartTimer(metrics.FrontendClientCreateScheduleScope, metrics.ClientLatency)53 resp, err := c.client.CreateSchedule(ctx, request, opts...)54 sw.Stop()55 if err != nil {56 c.metricsClient.IncCounter(metrics.FrontendClientCreateScheduleScope, metrics.ClientFailures)57 }58 return resp, err59}60func (c *metricClient) DeleteSchedule(61 ctx context.Context,62 request *workflowservice.DeleteScheduleRequest,63 opts ...grpc.CallOption,64) (*workflowservice.DeleteScheduleResponse, error) {65 c.metricsClient.IncCounter(metrics.FrontendClientDeleteScheduleScope, metrics.ClientRequests)66 sw := c.metricsClient.StartTimer(metrics.FrontendClientDeleteScheduleScope, metrics.ClientLatency)67 resp, err := c.client.DeleteSchedule(ctx, request, opts...)68 sw.Stop()69 if err != nil {70 c.metricsClient.IncCounter(metrics.FrontendClientDeleteScheduleScope, metrics.ClientFailures)71 }72 return resp, err73}74func (c *metricClient) DeprecateNamespace(75 ctx context.Context,76 request *workflowservice.DeprecateNamespaceRequest,77 opts ...grpc.CallOption,78) (*workflowservice.DeprecateNamespaceResponse, error) {79 c.metricsClient.IncCounter(metrics.FrontendClientDeprecateNamespaceScope, metrics.ClientRequests)80 sw := c.metricsClient.StartTimer(metrics.FrontendClientDeprecateNamespaceScope, metrics.ClientLatency)81 resp, err := c.client.DeprecateNamespace(ctx, request, opts...)82 sw.Stop()83 if err != nil {84 c.metricsClient.IncCounter(metrics.FrontendClientDeprecateNamespaceScope, metrics.ClientFailures)85 }86 return resp, err87}88func (c *metricClient) DescribeNamespace(89 ctx context.Context,90 request *workflowservice.DescribeNamespaceRequest,91 opts ...grpc.CallOption,92) (*workflowservice.DescribeNamespaceResponse, error) {93 c.metricsClient.IncCounter(metrics.FrontendClientDescribeNamespaceScope, metrics.ClientRequests)94 sw := c.metricsClient.StartTimer(metrics.FrontendClientDescribeNamespaceScope, metrics.ClientLatency)95 resp, err := c.client.DescribeNamespace(ctx, request, opts...)96 sw.Stop()97 if err != nil {98 c.metricsClient.IncCounter(metrics.FrontendClientDescribeNamespaceScope, metrics.ClientFailures)99 }100 return resp, err101}102func (c *metricClient) DescribeSchedule(103 ctx context.Context,104 request *workflowservice.DescribeScheduleRequest,105 opts ...grpc.CallOption,106) (*workflowservice.DescribeScheduleResponse, error) {107 c.metricsClient.IncCounter(metrics.FrontendClientDescribeScheduleScope, metrics.ClientRequests)108 sw := c.metricsClient.StartTimer(metrics.FrontendClientDescribeScheduleScope, metrics.ClientLatency)109 resp, err := c.client.DescribeSchedule(ctx, request, opts...)110 sw.Stop()111 if err != nil {112 c.metricsClient.IncCounter(metrics.FrontendClientDescribeScheduleScope, metrics.ClientFailures)113 }114 return resp, err115}116func (c *metricClient) DescribeTaskQueue(117 ctx context.Context,118 request *workflowservice.DescribeTaskQueueRequest,119 opts ...grpc.CallOption,120) (*workflowservice.DescribeTaskQueueResponse, error) {121 c.metricsClient.IncCounter(metrics.FrontendClientDescribeTaskQueueScope, metrics.ClientRequests)122 sw := c.metricsClient.StartTimer(metrics.FrontendClientDescribeTaskQueueScope, metrics.ClientLatency)123 resp, err := c.client.DescribeTaskQueue(ctx, request, opts...)124 sw.Stop()125 if err != nil {126 c.metricsClient.IncCounter(metrics.FrontendClientDescribeTaskQueueScope, metrics.ClientFailures)127 }128 return resp, err129}130func (c *metricClient) DescribeWorkflowExecution(131 ctx context.Context,132 request *workflowservice.DescribeWorkflowExecutionRequest,133 opts ...grpc.CallOption,134) (*workflowservice.DescribeWorkflowExecutionResponse, error) {135 c.metricsClient.IncCounter(metrics.FrontendClientDescribeWorkflowExecutionScope, metrics.ClientRequests)136 sw := c.metricsClient.StartTimer(metrics.FrontendClientDescribeWorkflowExecutionScope, metrics.ClientLatency)137 resp, err := c.client.DescribeWorkflowExecution(ctx, request, opts...)138 sw.Stop()139 if err != nil {140 c.metricsClient.IncCounter(metrics.FrontendClientDescribeWorkflowExecutionScope, metrics.ClientFailures)141 }142 return resp, err143}144func (c *metricClient) GetClusterInfo(145 ctx context.Context,146 request *workflowservice.GetClusterInfoRequest,147 opts ...grpc.CallOption,148) (*workflowservice.GetClusterInfoResponse, error) {149 c.metricsClient.IncCounter(metrics.FrontendClientGetClusterInfoScope, metrics.ClientRequests)150 sw := c.metricsClient.StartTimer(metrics.FrontendClientGetClusterInfoScope, metrics.ClientLatency)151 resp, err := c.client.GetClusterInfo(ctx, request, opts...)152 sw.Stop()153 if err != nil {154 c.metricsClient.IncCounter(metrics.FrontendClientGetClusterInfoScope, metrics.ClientFailures)155 }156 return resp, err157}158func (c *metricClient) GetSearchAttributes(159 ctx context.Context,160 request *workflowservice.GetSearchAttributesRequest,161 opts ...grpc.CallOption,162) (*workflowservice.GetSearchAttributesResponse, error) {163 c.metricsClient.IncCounter(metrics.FrontendClientGetSearchAttributesScope, metrics.ClientRequests)164 sw := c.metricsClient.StartTimer(metrics.FrontendClientGetSearchAttributesScope, metrics.ClientLatency)165 resp, err := c.client.GetSearchAttributes(ctx, request, opts...)166 sw.Stop()167 if err != nil {168 c.metricsClient.IncCounter(metrics.FrontendClientGetSearchAttributesScope, metrics.ClientFailures)169 }170 return resp, err171}172func (c *metricClient) GetSystemInfo(173 ctx context.Context,174 request *workflowservice.GetSystemInfoRequest,175 opts ...grpc.CallOption,176) (*workflowservice.GetSystemInfoResponse, error) {177 c.metricsClient.IncCounter(metrics.FrontendClientGetSystemInfoScope, metrics.ClientRequests)178 sw := c.metricsClient.StartTimer(metrics.FrontendClientGetSystemInfoScope, metrics.ClientLatency)179 resp, err := c.client.GetSystemInfo(ctx, request, opts...)180 sw.Stop()181 if err != nil {182 c.metricsClient.IncCounter(metrics.FrontendClientGetSystemInfoScope, metrics.ClientFailures)183 }184 return resp, err185}186func (c *metricClient) GetWorkerBuildIdOrdering(187 ctx context.Context,188 request *workflowservice.GetWorkerBuildIdOrderingRequest,189 opts ...grpc.CallOption,190) (*workflowservice.GetWorkerBuildIdOrderingResponse, error) {191 c.metricsClient.IncCounter(metrics.FrontendClientGetWorkerBuildIdOrderingScope, metrics.ClientRequests)192 sw := c.metricsClient.StartTimer(metrics.FrontendClientGetWorkerBuildIdOrderingScope, metrics.ClientLatency)193 resp, err := c.client.GetWorkerBuildIdOrdering(ctx, request, opts...)194 sw.Stop()195 if err != nil {196 c.metricsClient.IncCounter(metrics.FrontendClientGetWorkerBuildIdOrderingScope, metrics.ClientFailures)197 }198 return resp, err199}200func (c *metricClient) GetWorkflowExecutionHistory(201 ctx context.Context,202 request *workflowservice.GetWorkflowExecutionHistoryRequest,203 opts ...grpc.CallOption,204) (*workflowservice.GetWorkflowExecutionHistoryResponse, error) {205 c.metricsClient.IncCounter(metrics.FrontendClientGetWorkflowExecutionHistoryScope, metrics.ClientRequests)206 sw := c.metricsClient.StartTimer(metrics.FrontendClientGetWorkflowExecutionHistoryScope, metrics.ClientLatency)207 resp, err := c.client.GetWorkflowExecutionHistory(ctx, request, opts...)208 sw.Stop()209 if err != nil {210 c.metricsClient.IncCounter(metrics.FrontendClientGetWorkflowExecutionHistoryScope, metrics.ClientFailures)211 }212 return resp, err213}214func (c *metricClient) GetWorkflowExecutionHistoryReverse(215 ctx context.Context,216 request *workflowservice.GetWorkflowExecutionHistoryReverseRequest,217 opts ...grpc.CallOption,218) (*workflowservice.GetWorkflowExecutionHistoryReverseResponse, error) {219 c.metricsClient.IncCounter(metrics.FrontendClientGetWorkflowExecutionHistoryReverseScope, metrics.ClientRequests)220 sw := c.metricsClient.StartTimer(metrics.FrontendClientGetWorkflowExecutionHistoryReverseScope, metrics.ClientLatency)221 resp, err := c.client.GetWorkflowExecutionHistoryReverse(ctx, request, opts...)222 sw.Stop()223 if err != nil {224 c.metricsClient.IncCounter(metrics.FrontendClientGetWorkflowExecutionHistoryReverseScope, metrics.ClientFailures)225 }226 return resp, err227}228func (c *metricClient) ListArchivedWorkflowExecutions(229 ctx context.Context,230 request *workflowservice.ListArchivedWorkflowExecutionsRequest,231 opts ...grpc.CallOption,232) (*workflowservice.ListArchivedWorkflowExecutionsResponse, error) {233 c.metricsClient.IncCounter(metrics.FrontendClientListArchivedWorkflowExecutionsScope, metrics.ClientRequests)234 sw := c.metricsClient.StartTimer(metrics.FrontendClientListArchivedWorkflowExecutionsScope, metrics.ClientLatency)235 resp, err := c.client.ListArchivedWorkflowExecutions(ctx, request, opts...)236 sw.Stop()237 if err != nil {238 c.metricsClient.IncCounter(metrics.FrontendClientListArchivedWorkflowExecutionsScope, metrics.ClientFailures)239 }240 return resp, err241}242func (c *metricClient) ListClosedWorkflowExecutions(243 ctx context.Context,244 request *workflowservice.ListClosedWorkflowExecutionsRequest,245 opts ...grpc.CallOption,246) (*workflowservice.ListClosedWorkflowExecutionsResponse, error) {247 c.metricsClient.IncCounter(metrics.FrontendClientListClosedWorkflowExecutionsScope, metrics.ClientRequests)248 sw := c.metricsClient.StartTimer(metrics.FrontendClientListClosedWorkflowExecutionsScope, metrics.ClientLatency)249 resp, err := c.client.ListClosedWorkflowExecutions(ctx, request, opts...)250 sw.Stop()251 if err != nil {252 c.metricsClient.IncCounter(metrics.FrontendClientListClosedWorkflowExecutionsScope, metrics.ClientFailures)253 }254 return resp, err255}256func (c *metricClient) ListNamespaces(257 ctx context.Context,258 request *workflowservice.ListNamespacesRequest,259 opts ...grpc.CallOption,260) (*workflowservice.ListNamespacesResponse, error) {261 c.metricsClient.IncCounter(metrics.FrontendClientListNamespacesScope, metrics.ClientRequests)262 sw := c.metricsClient.StartTimer(metrics.FrontendClientListNamespacesScope, metrics.ClientLatency)263 resp, err := c.client.ListNamespaces(ctx, request, opts...)264 sw.Stop()265 if err != nil {266 c.metricsClient.IncCounter(metrics.FrontendClientListNamespacesScope, metrics.ClientFailures)267 }268 return resp, err269}270func (c *metricClient) ListOpenWorkflowExecutions(271 ctx context.Context,272 request *workflowservice.ListOpenWorkflowExecutionsRequest,273 opts ...grpc.CallOption,274) (*workflowservice.ListOpenWorkflowExecutionsResponse, error) {275 c.metricsClient.IncCounter(metrics.FrontendClientListOpenWorkflowExecutionsScope, metrics.ClientRequests)276 sw := c.metricsClient.StartTimer(metrics.FrontendClientListOpenWorkflowExecutionsScope, metrics.ClientLatency)277 resp, err := c.client.ListOpenWorkflowExecutions(ctx, request, opts...)278 sw.Stop()279 if err != nil {280 c.metricsClient.IncCounter(metrics.FrontendClientListOpenWorkflowExecutionsScope, metrics.ClientFailures)281 }282 return resp, err283}284func (c *metricClient) ListScheduleMatchingTimes(285 ctx context.Context,286 request *workflowservice.ListScheduleMatchingTimesRequest,287 opts ...grpc.CallOption,288) (*workflowservice.ListScheduleMatchingTimesResponse, error) {289 c.metricsClient.IncCounter(metrics.FrontendClientListScheduleMatchingTimesScope, metrics.ClientRequests)290 sw := c.metricsClient.StartTimer(metrics.FrontendClientListScheduleMatchingTimesScope, metrics.ClientLatency)291 resp, err := c.client.ListScheduleMatchingTimes(ctx, request, opts...)292 sw.Stop()293 if err != nil {294 c.metricsClient.IncCounter(metrics.FrontendClientListScheduleMatchingTimesScope, metrics.ClientFailures)295 }296 return resp, err297}298func (c *metricClient) ListSchedules(299 ctx context.Context,300 request *workflowservice.ListSchedulesRequest,301 opts ...grpc.CallOption,302) (*workflowservice.ListSchedulesResponse, error) {303 c.metricsClient.IncCounter(metrics.FrontendClientListSchedulesScope, metrics.ClientRequests)304 sw := c.metricsClient.StartTimer(metrics.FrontendClientListSchedulesScope, metrics.ClientLatency)305 resp, err := c.client.ListSchedules(ctx, request, opts...)306 sw.Stop()307 if err != nil {308 c.metricsClient.IncCounter(metrics.FrontendClientListSchedulesScope, metrics.ClientFailures)309 }310 return resp, err311}312func (c *metricClient) ListTaskQueuePartitions(313 ctx context.Context,314 request *workflowservice.ListTaskQueuePartitionsRequest,315 opts ...grpc.CallOption,316) (*workflowservice.ListTaskQueuePartitionsResponse, error) {317 c.metricsClient.IncCounter(metrics.FrontendClientListTaskQueuePartitionsScope, metrics.ClientRequests)318 sw := c.metricsClient.StartTimer(metrics.FrontendClientListTaskQueuePartitionsScope, metrics.ClientLatency)319 resp, err := c.client.ListTaskQueuePartitions(ctx, request, opts...)320 sw.Stop()321 if err != nil {322 c.metricsClient.IncCounter(metrics.FrontendClientListTaskQueuePartitionsScope, metrics.ClientFailures)323 }324 return resp, err325}326func (c *metricClient) ListWorkflowExecutions(327 ctx context.Context,328 request *workflowservice.ListWorkflowExecutionsRequest,329 opts ...grpc.CallOption,330) (*workflowservice.ListWorkflowExecutionsResponse, error) {331 c.metricsClient.IncCounter(metrics.FrontendClientListWorkflowExecutionsScope, metrics.ClientRequests)332 sw := c.metricsClient.StartTimer(metrics.FrontendClientListWorkflowExecutionsScope, metrics.ClientLatency)333 resp, err := c.client.ListWorkflowExecutions(ctx, request, opts...)334 sw.Stop()335 if err != nil {336 c.metricsClient.IncCounter(metrics.FrontendClientListWorkflowExecutionsScope, metrics.ClientFailures)337 }338 return resp, err339}340func (c *metricClient) PatchSchedule(341 ctx context.Context,342 request *workflowservice.PatchScheduleRequest,343 opts ...grpc.CallOption,344) (*workflowservice.PatchScheduleResponse, error) {345 c.metricsClient.IncCounter(metrics.FrontendClientPatchScheduleScope, metrics.ClientRequests)346 sw := c.metricsClient.StartTimer(metrics.FrontendClientPatchScheduleScope, metrics.ClientLatency)347 resp, err := c.client.PatchSchedule(ctx, request, opts...)348 sw.Stop()349 if err != nil {350 c.metricsClient.IncCounter(metrics.FrontendClientPatchScheduleScope, metrics.ClientFailures)351 }352 return resp, err353}354func (c *metricClient) PollActivityTaskQueue(355 ctx context.Context,356 request *workflowservice.PollActivityTaskQueueRequest,357 opts ...grpc.CallOption,358) (*workflowservice.PollActivityTaskQueueResponse, error) {359 c.metricsClient.IncCounter(metrics.FrontendClientPollActivityTaskQueueScope, metrics.ClientRequests)360 sw := c.metricsClient.StartTimer(metrics.FrontendClientPollActivityTaskQueueScope, metrics.ClientLatency)361 resp, err := c.client.PollActivityTaskQueue(ctx, request, opts...)362 sw.Stop()363 if err != nil {364 c.metricsClient.IncCounter(metrics.FrontendClientPollActivityTaskQueueScope, metrics.ClientFailures)365 }366 return resp, err367}368func (c *metricClient) PollWorkflowTaskQueue(369 ctx context.Context,370 request *workflowservice.PollWorkflowTaskQueueRequest,371 opts ...grpc.CallOption,372) (*workflowservice.PollWorkflowTaskQueueResponse, error) {373 c.metricsClient.IncCounter(metrics.FrontendClientPollWorkflowTaskQueueScope, metrics.ClientRequests)374 sw := c.metricsClient.StartTimer(metrics.FrontendClientPollWorkflowTaskQueueScope, metrics.ClientLatency)375 resp, err := c.client.PollWorkflowTaskQueue(ctx, request, opts...)376 sw.Stop()377 if err != nil {378 c.metricsClient.IncCounter(metrics.FrontendClientPollWorkflowTaskQueueScope, metrics.ClientFailures)379 }380 return resp, err381}382func (c *metricClient) QueryWorkflow(383 ctx context.Context,384 request *workflowservice.QueryWorkflowRequest,385 opts ...grpc.CallOption,386) (*workflowservice.QueryWorkflowResponse, error) {387 c.metricsClient.IncCounter(metrics.FrontendClientQueryWorkflowScope, metrics.ClientRequests)388 sw := c.metricsClient.StartTimer(metrics.FrontendClientQueryWorkflowScope, metrics.ClientLatency)389 resp, err := c.client.QueryWorkflow(ctx, request, opts...)390 sw.Stop()391 if err != nil {392 c.metricsClient.IncCounter(metrics.FrontendClientQueryWorkflowScope, metrics.ClientFailures)393 }394 return resp, err395}396func (c *metricClient) RecordActivityTaskHeartbeat(397 ctx context.Context,398 request *workflowservice.RecordActivityTaskHeartbeatRequest,399 opts ...grpc.CallOption,400) (*workflowservice.RecordActivityTaskHeartbeatResponse, error) {401 c.metricsClient.IncCounter(metrics.FrontendClientRecordActivityTaskHeartbeatScope, metrics.ClientRequests)402 sw := c.metricsClient.StartTimer(metrics.FrontendClientRecordActivityTaskHeartbeatScope, metrics.ClientLatency)403 resp, err := c.client.RecordActivityTaskHeartbeat(ctx, request, opts...)404 sw.Stop()405 if err != nil {406 c.metricsClient.IncCounter(metrics.FrontendClientRecordActivityTaskHeartbeatScope, metrics.ClientFailures)407 }408 return resp, err409}410func (c *metricClient) RecordActivityTaskHeartbeatById(411 ctx context.Context,412 request *workflowservice.RecordActivityTaskHeartbeatByIdRequest,413 opts ...grpc.CallOption,414) (*workflowservice.RecordActivityTaskHeartbeatByIdResponse, error) {415 c.metricsClient.IncCounter(metrics.FrontendClientRecordActivityTaskHeartbeatByIdScope, metrics.ClientRequests)416 sw := c.metricsClient.StartTimer(metrics.FrontendClientRecordActivityTaskHeartbeatByIdScope, metrics.ClientLatency)417 resp, err := c.client.RecordActivityTaskHeartbeatById(ctx, request, opts...)418 sw.Stop()419 if err != nil {420 c.metricsClient.IncCounter(metrics.FrontendClientRecordActivityTaskHeartbeatByIdScope, metrics.ClientFailures)421 }422 return resp, err423}424func (c *metricClient) RegisterNamespace(425 ctx context.Context,426 request *workflowservice.RegisterNamespaceRequest,427 opts ...grpc.CallOption,428) (*workflowservice.RegisterNamespaceResponse, error) {429 c.metricsClient.IncCounter(metrics.FrontendClientRegisterNamespaceScope, metrics.ClientRequests)430 sw := c.metricsClient.StartTimer(metrics.FrontendClientRegisterNamespaceScope, metrics.ClientLatency)431 resp, err := c.client.RegisterNamespace(ctx, request, opts...)432 sw.Stop()433 if err != nil {434 c.metricsClient.IncCounter(metrics.FrontendClientRegisterNamespaceScope, metrics.ClientFailures)435 }436 return resp, err437}438func (c *metricClient) RequestCancelWorkflowExecution(439 ctx context.Context,440 request *workflowservice.RequestCancelWorkflowExecutionRequest,441 opts ...grpc.CallOption,442) (*workflowservice.RequestCancelWorkflowExecutionResponse, error) {443 c.metricsClient.IncCounter(metrics.FrontendClientRequestCancelWorkflowExecutionScope, metrics.ClientRequests)444 sw := c.metricsClient.StartTimer(metrics.FrontendClientRequestCancelWorkflowExecutionScope, metrics.ClientLatency)445 resp, err := c.client.RequestCancelWorkflowExecution(ctx, request, opts...)446 sw.Stop()447 if err != nil {448 c.metricsClient.IncCounter(metrics.FrontendClientRequestCancelWorkflowExecutionScope, metrics.ClientFailures)449 }450 return resp, err451}452func (c *metricClient) ResetStickyTaskQueue(453 ctx context.Context,454 request *workflowservice.ResetStickyTaskQueueRequest,455 opts ...grpc.CallOption,456) (*workflowservice.ResetStickyTaskQueueResponse, error) {457 c.metricsClient.IncCounter(metrics.FrontendClientResetStickyTaskQueueScope, metrics.ClientRequests)458 sw := c.metricsClient.StartTimer(metrics.FrontendClientResetStickyTaskQueueScope, metrics.ClientLatency)459 resp, err := c.client.ResetStickyTaskQueue(ctx, request, opts...)460 sw.Stop()461 if err != nil {462 c.metricsClient.IncCounter(metrics.FrontendClientResetStickyTaskQueueScope, metrics.ClientFailures)463 }464 return resp, err465}466func (c *metricClient) ResetWorkflowExecution(467 ctx context.Context,468 request *workflowservice.ResetWorkflowExecutionRequest,469 opts ...grpc.CallOption,470) (*workflowservice.ResetWorkflowExecutionResponse, error) {471 c.metricsClient.IncCounter(metrics.FrontendClientResetWorkflowExecutionScope, metrics.ClientRequests)472 sw := c.metricsClient.StartTimer(metrics.FrontendClientResetWorkflowExecutionScope, metrics.ClientLatency)473 resp, err := c.client.ResetWorkflowExecution(ctx, request, opts...)474 sw.Stop()475 if err != nil {476 c.metricsClient.IncCounter(metrics.FrontendClientResetWorkflowExecutionScope, metrics.ClientFailures)477 }478 return resp, err479}480func (c *metricClient) RespondActivityTaskCanceled(481 ctx context.Context,482 request *workflowservice.RespondActivityTaskCanceledRequest,483 opts ...grpc.CallOption,484) (*workflowservice.RespondActivityTaskCanceledResponse, error) {485 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskCanceledScope, metrics.ClientRequests)486 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondActivityTaskCanceledScope, metrics.ClientLatency)487 resp, err := c.client.RespondActivityTaskCanceled(ctx, request, opts...)488 sw.Stop()489 if err != nil {490 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskCanceledScope, metrics.ClientFailures)491 }492 return resp, err493}494func (c *metricClient) RespondActivityTaskCanceledById(495 ctx context.Context,496 request *workflowservice.RespondActivityTaskCanceledByIdRequest,497 opts ...grpc.CallOption,498) (*workflowservice.RespondActivityTaskCanceledByIdResponse, error) {499 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskCanceledByIdScope, metrics.ClientRequests)500 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondActivityTaskCanceledByIdScope, metrics.ClientLatency)501 resp, err := c.client.RespondActivityTaskCanceledById(ctx, request, opts...)502 sw.Stop()503 if err != nil {504 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskCanceledByIdScope, metrics.ClientFailures)505 }506 return resp, err507}508func (c *metricClient) RespondActivityTaskCompleted(509 ctx context.Context,510 request *workflowservice.RespondActivityTaskCompletedRequest,511 opts ...grpc.CallOption,512) (*workflowservice.RespondActivityTaskCompletedResponse, error) {513 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskCompletedScope, metrics.ClientRequests)514 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondActivityTaskCompletedScope, metrics.ClientLatency)515 resp, err := c.client.RespondActivityTaskCompleted(ctx, request, opts...)516 sw.Stop()517 if err != nil {518 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskCompletedScope, metrics.ClientFailures)519 }520 return resp, err521}522func (c *metricClient) RespondActivityTaskCompletedById(523 ctx context.Context,524 request *workflowservice.RespondActivityTaskCompletedByIdRequest,525 opts ...grpc.CallOption,526) (*workflowservice.RespondActivityTaskCompletedByIdResponse, error) {527 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskCompletedByIdScope, metrics.ClientRequests)528 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondActivityTaskCompletedByIdScope, metrics.ClientLatency)529 resp, err := c.client.RespondActivityTaskCompletedById(ctx, request, opts...)530 sw.Stop()531 if err != nil {532 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskCompletedByIdScope, metrics.ClientFailures)533 }534 return resp, err535}536func (c *metricClient) RespondActivityTaskFailed(537 ctx context.Context,538 request *workflowservice.RespondActivityTaskFailedRequest,539 opts ...grpc.CallOption,540) (*workflowservice.RespondActivityTaskFailedResponse, error) {541 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskFailedScope, metrics.ClientRequests)542 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondActivityTaskFailedScope, metrics.ClientLatency)543 resp, err := c.client.RespondActivityTaskFailed(ctx, request, opts...)544 sw.Stop()545 if err != nil {546 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskFailedScope, metrics.ClientFailures)547 }548 return resp, err549}550func (c *metricClient) RespondActivityTaskFailedById(551 ctx context.Context,552 request *workflowservice.RespondActivityTaskFailedByIdRequest,553 opts ...grpc.CallOption,554) (*workflowservice.RespondActivityTaskFailedByIdResponse, error) {555 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskFailedByIdScope, metrics.ClientRequests)556 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondActivityTaskFailedByIdScope, metrics.ClientLatency)557 resp, err := c.client.RespondActivityTaskFailedById(ctx, request, opts...)558 sw.Stop()559 if err != nil {560 c.metricsClient.IncCounter(metrics.FrontendClientRespondActivityTaskFailedByIdScope, metrics.ClientFailures)561 }562 return resp, err563}564func (c *metricClient) RespondQueryTaskCompleted(565 ctx context.Context,566 request *workflowservice.RespondQueryTaskCompletedRequest,567 opts ...grpc.CallOption,568) (*workflowservice.RespondQueryTaskCompletedResponse, error) {569 c.metricsClient.IncCounter(metrics.FrontendClientRespondQueryTaskCompletedScope, metrics.ClientRequests)570 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondQueryTaskCompletedScope, metrics.ClientLatency)571 resp, err := c.client.RespondQueryTaskCompleted(ctx, request, opts...)572 sw.Stop()573 if err != nil {574 c.metricsClient.IncCounter(metrics.FrontendClientRespondQueryTaskCompletedScope, metrics.ClientFailures)575 }576 return resp, err577}578func (c *metricClient) RespondWorkflowTaskCompleted(579 ctx context.Context,580 request *workflowservice.RespondWorkflowTaskCompletedRequest,581 opts ...grpc.CallOption,582) (*workflowservice.RespondWorkflowTaskCompletedResponse, error) {583 c.metricsClient.IncCounter(metrics.FrontendClientRespondWorkflowTaskCompletedScope, metrics.ClientRequests)584 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondWorkflowTaskCompletedScope, metrics.ClientLatency)585 resp, err := c.client.RespondWorkflowTaskCompleted(ctx, request, opts...)586 sw.Stop()587 if err != nil {588 c.metricsClient.IncCounter(metrics.FrontendClientRespondWorkflowTaskCompletedScope, metrics.ClientFailures)589 }590 return resp, err591}592func (c *metricClient) RespondWorkflowTaskFailed(593 ctx context.Context,594 request *workflowservice.RespondWorkflowTaskFailedRequest,595 opts ...grpc.CallOption,596) (*workflowservice.RespondWorkflowTaskFailedResponse, error) {597 c.metricsClient.IncCounter(metrics.FrontendClientRespondWorkflowTaskFailedScope, metrics.ClientRequests)598 sw := c.metricsClient.StartTimer(metrics.FrontendClientRespondWorkflowTaskFailedScope, metrics.ClientLatency)599 resp, err := c.client.RespondWorkflowTaskFailed(ctx, request, opts...)600 sw.Stop()601 if err != nil {602 c.metricsClient.IncCounter(metrics.FrontendClientRespondWorkflowTaskFailedScope, metrics.ClientFailures)603 }604 return resp, err605}606func (c *metricClient) ScanWorkflowExecutions(607 ctx context.Context,608 request *workflowservice.ScanWorkflowExecutionsRequest,609 opts ...grpc.CallOption,610) (*workflowservice.ScanWorkflowExecutionsResponse, error) {611 c.metricsClient.IncCounter(metrics.FrontendClientScanWorkflowExecutionsScope, metrics.ClientRequests)612 sw := c.metricsClient.StartTimer(metrics.FrontendClientScanWorkflowExecutionsScope, metrics.ClientLatency)613 resp, err := c.client.ScanWorkflowExecutions(ctx, request, opts...)614 sw.Stop()615 if err != nil {616 c.metricsClient.IncCounter(metrics.FrontendClientScanWorkflowExecutionsScope, metrics.ClientFailures)617 }618 return resp, err619}620func (c *metricClient) SignalWithStartWorkflowExecution(621 ctx context.Context,622 request *workflowservice.SignalWithStartWorkflowExecutionRequest,623 opts ...grpc.CallOption,624) (*workflowservice.SignalWithStartWorkflowExecutionResponse, error) {625 c.metricsClient.IncCounter(metrics.FrontendClientSignalWithStartWorkflowExecutionScope, metrics.ClientRequests)626 sw := c.metricsClient.StartTimer(metrics.FrontendClientSignalWithStartWorkflowExecutionScope, metrics.ClientLatency)627 resp, err := c.client.SignalWithStartWorkflowExecution(ctx, request, opts...)628 sw.Stop()629 if err != nil {630 c.metricsClient.IncCounter(metrics.FrontendClientSignalWithStartWorkflowExecutionScope, metrics.ClientFailures)631 }632 return resp, err633}634func (c *metricClient) SignalWorkflowExecution(635 ctx context.Context,636 request *workflowservice.SignalWorkflowExecutionRequest,637 opts ...grpc.CallOption,638) (*workflowservice.SignalWorkflowExecutionResponse, error) {639 c.metricsClient.IncCounter(metrics.FrontendClientSignalWorkflowExecutionScope, metrics.ClientRequests)640 sw := c.metricsClient.StartTimer(metrics.FrontendClientSignalWorkflowExecutionScope, metrics.ClientLatency)641 resp, err := c.client.SignalWorkflowExecution(ctx, request, opts...)642 sw.Stop()643 if err != nil {644 c.metricsClient.IncCounter(metrics.FrontendClientSignalWorkflowExecutionScope, metrics.ClientFailures)645 }646 return resp, err647}648func (c *metricClient) StartWorkflowExecution(649 ctx context.Context,650 request *workflowservice.StartWorkflowExecutionRequest,651 opts ...grpc.CallOption,652) (*workflowservice.StartWorkflowExecutionResponse, error) {653 c.metricsClient.IncCounter(metrics.FrontendClientStartWorkflowExecutionScope, metrics.ClientRequests)654 sw := c.metricsClient.StartTimer(metrics.FrontendClientStartWorkflowExecutionScope, metrics.ClientLatency)655 resp, err := c.client.StartWorkflowExecution(ctx, request, opts...)656 sw.Stop()657 if err != nil {658 c.metricsClient.IncCounter(metrics.FrontendClientStartWorkflowExecutionScope, metrics.ClientFailures)659 }660 return resp, err661}662func (c *metricClient) TerminateWorkflowExecution(663 ctx context.Context,664 request *workflowservice.TerminateWorkflowExecutionRequest,665 opts ...grpc.CallOption,666) (*workflowservice.TerminateWorkflowExecutionResponse, error) {667 c.metricsClient.IncCounter(metrics.FrontendClientTerminateWorkflowExecutionScope, metrics.ClientRequests)668 sw := c.metricsClient.StartTimer(metrics.FrontendClientTerminateWorkflowExecutionScope, metrics.ClientLatency)669 resp, err := c.client.TerminateWorkflowExecution(ctx, request, opts...)670 sw.Stop()671 if err != nil {672 c.metricsClient.IncCounter(metrics.FrontendClientTerminateWorkflowExecutionScope, metrics.ClientFailures)673 }674 return resp, err675}676func (c *metricClient) UpdateNamespace(677 ctx context.Context,678 request *workflowservice.UpdateNamespaceRequest,679 opts ...grpc.CallOption,680) (*workflowservice.UpdateNamespaceResponse, error) {681 c.metricsClient.IncCounter(metrics.FrontendClientUpdateNamespaceScope, metrics.ClientRequests)682 sw := c.metricsClient.StartTimer(metrics.FrontendClientUpdateNamespaceScope, metrics.ClientLatency)683 resp, err := c.client.UpdateNamespace(ctx, request, opts...)684 sw.Stop()685 if err != nil {686 c.metricsClient.IncCounter(metrics.FrontendClientUpdateNamespaceScope, metrics.ClientFailures)687 }688 return resp, err689}690func (c *metricClient) UpdateSchedule(691 ctx context.Context,692 request *workflowservice.UpdateScheduleRequest,693 opts ...grpc.CallOption,694) (*workflowservice.UpdateScheduleResponse, error) {695 c.metricsClient.IncCounter(metrics.FrontendClientUpdateScheduleScope, metrics.ClientRequests)696 sw := c.metricsClient.StartTimer(metrics.FrontendClientUpdateScheduleScope, metrics.ClientLatency)697 resp, err := c.client.UpdateSchedule(ctx, request, opts...)698 sw.Stop()699 if err != nil {700 c.metricsClient.IncCounter(metrics.FrontendClientUpdateScheduleScope, metrics.ClientFailures)701 }702 return resp, err703}704func (c *metricClient) UpdateWorkerBuildIdOrdering(705 ctx context.Context,706 request *workflowservice.UpdateWorkerBuildIdOrderingRequest,707 opts ...grpc.CallOption,708) (*workflowservice.UpdateWorkerBuildIdOrderingResponse, error) {709 c.metricsClient.IncCounter(metrics.FrontendClientUpdateWorkerBuildIdOrderingScope, metrics.ClientRequests)710 sw := c.metricsClient.StartTimer(metrics.FrontendClientUpdateWorkerBuildIdOrderingScope, metrics.ClientLatency)711 resp, err := c.client.UpdateWorkerBuildIdOrdering(ctx, request, opts...)712 sw.Stop()713 if err != nil {714 c.metricsClient.IncCounter(metrics.FrontendClientUpdateWorkerBuildIdOrderingScope, metrics.ClientFailures)715 }716 return resp, err717}...

Full Screen

Full Screen

filter_clientmetrics_test.go

Source:filter_clientmetrics_test.go Github

copy

Full Screen

...6 "strconv"7 "sync"8 "testing"9)10type clientMetricsTest struct {11 url string12 realmKeyName string13 clientKeyName string14 clientTrackingPattern *string15 header http.Header16 expectedEndpointMetricPrefix string17 expectedClientMetricPrefix string18 realmsTrackingPattern string19}20var (21 clientTrackingPatternJustSomeUsers = s(`(joe|sabine)`)22 headerUsersJoe = http.Header{23 authorizationHeaderName: {24 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{25 "realm": "users",26 "client": "joe",27 }),28 },29 }30)31func s(str string) *string {32 return &str33}34func Test_Filter_ClientMetrics_ClientTrackingPatternDoesNotCompile(t *testing.T) {35 testClientMetrics(t, clientMetricsTest{36 realmKeyName: "realm",37 clientKeyName: "client",38 realmsTrackingPattern: "service",39 clientTrackingPattern: s("(["),40 header: headerUsersJoe,41 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",42 expectedClientMetricPrefix: "", // expecting no metrics43 })44}45func Test_Filter_ClientMetrics_NoMatchingPath_RealmIsKnown(t *testing.T) {46 testClientMetrics(t, clientMetricsTest{47 realmKeyName: "realm",48 clientKeyName: "client",49 clientTrackingPattern: s(".*"),50 realmsTrackingPattern: "services",51 header: headerUsersJoe,52 url: "https://www.example.com/non/configured/path/template",53 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.{no-tag}.{unknown}.GET.{no-match}.*.*.",54 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.{no-tag}.{unknown}.*.*.users.{all}.",55 })56}57func Test_Filter_ClientMetrics_NoMatchingPath_RealmIsUnknown(t *testing.T) {58 testClientMetrics(t, clientMetricsTest{59 realmKeyName: "will not match",60 clientKeyName: "client",61 clientTrackingPattern: s(".*"),62 header: headerUsersJoe,63 url: "https://www.example.com/non/configured/path/template",64 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.{no-tag}.{unknown}.GET.{no-match}.*.*.",65 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.{no-tag}.{unknown}.*.*.{unknown}.{unknown}.",66 })67}68func Test_Filter_ClientMetrics_MatchAll(t *testing.T) {69 testClientMetrics(t, clientMetricsTest{70 realmKeyName: "realm",71 clientKeyName: "client",72 clientTrackingPattern: s(".*"),73 header: headerUsersJoe,74 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",75 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.users.joe.",76 realmsTrackingPattern: "users",77 })78}79func Test_Filter_ClientMetrics_MatchOneOfClientKeyName(t *testing.T) {80 testClientMetrics(t, clientMetricsTest{81 realmKeyName: "realm",82 clientKeyName: "client,sub",83 clientTrackingPattern: s(".*"),84 header: http.Header{85 authorizationHeaderName: {86 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{87 "realm": "services",88 "sub": "payments",89 }),90 },91 },92 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",93 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.services.payments.",94 realmsTrackingPattern: "services",95 })96}97func Test_Filter_ClientMetrics_MatchOneOfClientKeyName_UseFirstMatching(t *testing.T) {98 testClientMetrics(t, clientMetricsTest{99 realmKeyName: "realm",100 clientKeyName: "client,sub",101 realmsTrackingPattern: "services",102 clientTrackingPattern: s(".*"),103 header: http.Header{104 authorizationHeaderName: {105 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{106 "realm": "services",107 "sub": "payments",108 "client": "but_I_should_come_first",109 }),110 },111 },112 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",113 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.services.but_I_should_come_first.",114 })115}116func Test_Filter_ClientMetrics_Realm1User1(t *testing.T) {117 testClientMetrics(t, clientMetricsTest{118 realmKeyName: "realm",119 clientKeyName: "client",120 realmsTrackingPattern: "users",121 clientTrackingPattern: clientTrackingPatternJustSomeUsers,122 header: headerUsersJoe,123 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",124 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.users.joe.",125 })126}127func Test_Filter_ClientMetrics_Realm1User0(t *testing.T) {128 testClientMetrics(t, clientMetricsTest{129 realmKeyName: "realm",130 clientKeyName: "client",131 realmsTrackingPattern: "users",132 clientTrackingPattern: clientTrackingPatternJustSomeUsers,133 header: http.Header{134 authorizationHeaderName: {135 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{136 "realm": "users",137 "client": "berta",138 }),139 },140 },141 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",142 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.users.{no-match}.",143 })144}145func Test_Filter_ClientMetrics_Realm0User1(t *testing.T) {146 testClientMetrics(t, clientMetricsTest{147 realmKeyName: "realm",148 clientKeyName: "client",149 realmsTrackingPattern: "services",150 clientTrackingPattern: clientTrackingPatternJustSomeUsers,151 header: http.Header{152 authorizationHeaderName: {153 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{154 "realm": "nobodies",155 "client": "sabine",156 }),157 },158 },159 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",160 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.nobodies.{all}.",161 })162}163func Test_Filter_ClientMetrics_Realm0User0(t *testing.T) {164 testClientMetrics(t, clientMetricsTest{165 realmKeyName: "realm",166 clientKeyName: "client",167 realmsTrackingPattern: "services",168 clientTrackingPattern: clientTrackingPatternJustSomeUsers,169 header: http.Header{170 authorizationHeaderName: {171 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{172 "realm": "nobodies",173 "client": "david",174 }),175 },176 },177 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",178 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.nobodies.{all}.",179 })180}181func Test_Filter_ClientMetrics_AuthDoesNotHaveBearerPrefix(t *testing.T) {182 testClientMetrics(t, clientMetricsTest{183 realmKeyName: "realm",184 clientKeyName: "client",185 realmsTrackingPattern: "services",186 clientTrackingPattern: clientTrackingPatternJustSomeUsers,187 header: http.Header{188 authorizationHeaderName: {189 /* no bearer */ buildFakeJwtWithBody(map[string]interface{}{190 "realm": "users",191 "client": "joe",192 }),193 },194 },195 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",196 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.{unknown}.{unknown}.",197 })198}199func Test_Filter_ClientMetrics_NoAuthHeader(t *testing.T) {200 testClientMetrics(t, clientMetricsTest{201 realmKeyName: "realm",202 clientKeyName: "client",203 clientTrackingPattern: clientTrackingPatternJustSomeUsers,204 header: http.Header{205 /* no Authorization header */206 },207 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",208 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.{unknown}.{unknown}.",209 })210}211func Test_Filter_ClientMetrics_JWTIsNot3DotSeparatedString(t *testing.T) {212 testClientMetrics(t, clientMetricsTest{213 realmKeyName: "realm",214 clientKeyName: "client",215 clientTrackingPattern: clientTrackingPatternJustSomeUsers,216 header: http.Header{217 authorizationHeaderName: {218 "Bearer " + "foo",219 },220 },221 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",222 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.{unknown}.{unknown}.",223 })224}225func Test_Filter_ClientMetrics_JWTIsNotBase64Encoded(t *testing.T) {226 testClientMetrics(t, clientMetricsTest{227 realmKeyName: "realm",228 clientKeyName: "client",229 clientTrackingPattern: clientTrackingPatternJustSomeUsers,230 header: http.Header{231 authorizationHeaderName: {232 "Bearer " + "there&is.no&way.this&is&base64",233 },234 },235 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",236 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.{unknown}.{unknown}.",237 })238}239func Test_Filter_ClientMetrics_JWTBodyIsNoJSON(t *testing.T) {240 body := base64.RawURLEncoding.EncodeToString([]byte("I am sadly no JSON :'("))241 testClientMetrics(t, clientMetricsTest{242 realmKeyName: "realm",243 clientKeyName: "client",244 clientTrackingPattern: clientTrackingPatternJustSomeUsers,245 header: http.Header{246 authorizationHeaderName: {247 "Bearer " + "header." + body + ".signature",248 },249 },250 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",251 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.{unknown}.{unknown}.",252 })253}254func Test_Filter_ClientMetrics_JWTBodyHasNoRealm(t *testing.T) {255 testClientMetrics(t, clientMetricsTest{256 realmKeyName: "realm",257 clientKeyName: "client",258 clientTrackingPattern: clientTrackingPatternJustSomeUsers,259 header: http.Header{260 authorizationHeaderName: {261 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{262 // no realm263 "client": "david",264 }),265 },266 },267 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",268 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.{unknown}.{unknown}.",269 })270}271func Test_Filter_ClientMetrics_JWTBodyHasNoClient_ShouldTrackRealm(t *testing.T) {272 testClientMetrics(t, clientMetricsTest{273 realmKeyName: "realm",274 clientKeyName: "client",275 realmsTrackingPattern: "users",276 clientTrackingPattern: clientTrackingPatternJustSomeUsers,277 header: http.Header{278 authorizationHeaderName: {279 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{280 "realm": "users",281 // no client ID282 }),283 },284 },285 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",286 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.users.{unknown}.",287 })288}289func Test_Filter_ClientMetrics_NoFlagRealmKeyName(t *testing.T) {290 testClientMetrics(t, clientMetricsTest{291 realmKeyName: "", // no realm key name CLI flag292 clientKeyName: "client",293 clientTrackingPattern: clientTrackingPatternJustSomeUsers,294 header: headerUsersJoe,295 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",296 expectedClientMetricPrefix: "", // expecting no metrics297 })298}299func Test_Filter_ClientMetrics_NoFlagClientKeyName(t *testing.T) {300 testClientMetrics(t, clientMetricsTest{301 realmKeyName: "realm",302 clientKeyName: "", // no client ID key name CLI flag303 clientTrackingPattern: clientTrackingPatternJustSomeUsers,304 header: headerUsersJoe,305 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",306 expectedClientMetricPrefix: "", // expecting no metrics307 })308}309func Test_Filter_ClientMetrics_DefaultClientTrackingPattern_NoClientTrackingPatternInRouteFilterJSON_User(t *testing.T) {310 testClientMetrics(t, clientMetricsTest{311 realmKeyName: "realm",312 clientKeyName: "client",313 realmsTrackingPattern: "services",314 clientTrackingPattern: nil, // no client tracking in route's filter configuration315 header: http.Header{316 authorizationHeaderName: {317 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{318 "realm": "users",319 "client": "joe",320 }),321 },322 },323 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",324 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.users.{all}.",325 })326}327func Test_Filter_ClientMetrics_DefaultClientTrackingPattern_NoClientTrackingPatternInRouteFilterJSON_Service(t *testing.T) {328 testClientMetrics(t, clientMetricsTest{329 realmKeyName: "realm",330 clientKeyName: "client",331 realmsTrackingPattern: "services",332 clientTrackingPattern: nil, // no client tracking in route's filter configuration333 header: http.Header{334 authorizationHeaderName: {335 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{336 "realm": "services",337 "client": "my_app",338 }),339 },340 },341 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",342 expectedClientMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.*.*.services.my_app.",343 })344}345func Test_Filter_ClientMetrics_EmptyClientTrackingPatternInRouteFilterJSON(t *testing.T) {346 testClientMetrics(t, clientMetricsTest{347 realmKeyName: "realm",348 clientKeyName: "client",349 realmsTrackingPattern: "services",350 clientTrackingPattern: s(""), // no client tracking in route's filter configuration351 header: http.Header{352 authorizationHeaderName: {353 "Bearer " + buildFakeJwtWithBody(map[string]interface{}{354 "realm": "users",355 "client": "joe",356 }),357 },358 },359 expectedEndpointMetricPrefix: "apiUsageMonitoring.custom.my_app.my_tag.my_api.GET.foo/orders.*.*.",360 expectedClientMetricPrefix: "",361 })362}363// may produce false-negatives364func Test_Filter_ClientMetricsCache_ConcurrentAccess(t *testing.T) {365 pathInfo := newPathInfo("application_id", "tag", "api_id", "orders",366 &clientTrackingInfo{RealmsTrackingMatcher: regexp.MustCompile("services"), ClientTrackingMatcher: regexp.MustCompile(`.*`)})367 concurrencyLevel := 500368 var wg sync.WaitGroup369 wg.Add(concurrencyLevel)370 for i := 0; i < concurrencyLevel; i++ {371 go func(i int) {372 getClientMetricsNames("services.service_id_"+strconv.Itoa(i), pathInfo)373 wg.Done()374 }(i)375 }376 wg.Wait()377}...

Full Screen

Full Screen

Metrics

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c, err := client.NewHTTPClient(client.HTTPConfig{4 })5 if err != nil {6 fmt.Println("Error creating InfluxDB Client: ", err.Error())7 }8 defer c.Close()9 bp, err := client.NewBatchPoints(client.BatchPointsConfig{10 })11 if err != nil {12 fmt.Println("Error: ", err.Error())13 }14 tags := map[string]string{"cpu": "cpu-total"}15 fields := map[string]interface{}{16 }17 pt, err := client.NewPoint("cpu", tags, fields, time.Now())18 if err != nil {19 fmt.Println("Error: ", err.Error())20 }21 bp.AddPoint(pt)22 c.Write(bp)23 q := client.Query{24 }25 if response, err := c.Query(q); err == nil && response.Error() == nil {26 fmt.Println(response.Results)27 }28}

Full Screen

Full Screen

Metrics

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client, err := sarama.NewClient([]string{"localhost:9092"}, nil)4 if err != nil {5 fmt.Println("Error creating client")6 }7 defer client.Close()8 metrics := client.Metrics()9 fmt.Printf("Metrics: %v10}

Full Screen

Full Screen

Metrics

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 panic(err)5 }6 health, err := client.ClusterHealth().Do()7 if err != nil {8 panic(err)9 }10 fmt.Printf("Cluster health: %d11}12import (13func main() {14 client, err := elastic.NewClient()15 if err != nil {16 panic(err)17 }18 health, err := client.ClusterHealth().Do()19 if err != nil {20 panic(err)21 }22 fmt.Printf("Cluster health: %d23}

Full Screen

Full Screen

Metrics

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cfg := elasticsearch.Config{4 Addresses: []string{5 },6 }7 es, _ := elasticsearch.NewClient(cfg)8 res, err := es.Metrics()9 if err != nil {10 fmt.Println(err)11 }12 fmt.Println(res)13}14import (15func main() {16 cfg := elasticsearch.Config{17 Addresses: []string{18 },19 }20 es, _ := elasticsearch.NewClient(cfg)21 res, err := es.Metrics()22 if err != nil {23 fmt.Println(err)24 }25 fmt.Println(res)26}27import (28func main() {29 cfg := elasticsearch.Config{30 Addresses: []string{31 },32 }33 es, _ := elasticsearch.NewClient(cfg)34 res, err := es.Metrics()35 if err != nil {36 fmt.Println(err)37 }38 fmt.Println(res)39}40import (41func main() {42 cfg := elasticsearch.Config{43 Addresses: []string{44 },45 }46 es, _ := elasticsearch.NewClient(cfg)47 res, err := es.Metrics()48 if err != nil {49 fmt.Println(err)50 }51 fmt.Println(res)

Full Screen

Full Screen

Metrics

Using AI Code Generation

copy

Full Screen

1import (2type Metrics struct {3 Fields map[string]interface{}4}5func main() {6 c, err := client.NewHTTPClient(client.HTTPConfig{7 })8 if err != nil {9 log.Fatal(err)10 }11 defer c.Close()12 bp, err := client.NewBatchPoints(client.BatchPointsConfig{13 })14 if err != nil {15 log.Fatal(err)16 }17 tags := map[string]string{"host": "server01", "region": "us-west"}18 fields := map[string]interface{}{19 }20 pt, err := client.NewPoint("cpu_usage", tags, fields, time.Now())21 if err != nil {22 log.Fatal(err)23 }24 bp.AddPoint(pt)25 c.Write(bp)26 metrics := []Metrics{27 {28 Tags: map[string]string{"host": "server01", "region": "us-west"},29 Fields: map[string]interface{}{30 },31 Time: time.Now(),32 },33 {34 Tags: map[string]string{"host": "server02", "region": "us-west"},35 Fields: map[string]interface{}{36 },37 Time: time.Now(),38 },39 {40 Tags: map[string]string{"host": "server03", "region": "us-west"},41 Fields: map[string]interface{}{42 },43 Time: time.Now(),44 },45 {46 Tags: map[string]string{"host": "server04", "region": "us-west"},47 Fields: map[string]interface{}{48 },49 Time: time.Now(),50 },51 }

Full Screen

Full Screen

Metrics

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c, err := client.NewHTTPClient(client.HTTPConfig{4 })5 if err != nil {6 log.Fatal(err)7 }8 bp, err := client.NewBatchPoints(client.BatchPointsConfig{9 })10 if err != nil {11 log.Fatal(err)12 }13 tags := map[string]string{"cpu": "cpu-total"}14 fields := map[string]interface{}{15 }16 pt, err := client.NewPoint("cpu_usage", tags, fields, time.Now())17 if err != nil {18 log.Fatal(err)19 }20 bp.AddPoint(pt)21 c.Write(bp)22 q := client.Query{23 }24 if response, err := c.Query(q); err == nil && response.Error() == nil {25 fmt.Println(response.Results)26 }27}28Write(): This method is used to write data

Full Screen

Full Screen

Metrics

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 scope := tally.NewTestScope("test", nil)4 counter := scope.Counter("counter1")5 counter.Inc(1)6 metrics := scope.Snapshot().Metrics()7 fmt.Println(metrics)8}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful