From 76c76395da13e49569ac59025362c35149838993 Mon Sep 17 00:00:00 2001 From: ensiouel <ensiouel@gmail.com> Date: Tue, 19 Dec 2023 20:04:28 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=B8=D0=BA=20=D0=B8=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D1=8B=20middleware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/templates/middleware/metrics | 16 +- images/middleware/metrics_middleware.go | 16 +- .../middleware/metrics_middleware.go | 80 ++--- .../middleware/metrics_middleware.go | 112 +++---- .../middleware/metrics_middleware.go | 128 ++++---- .../middleware/metrics_middleware.go | 80 ++--- pkg/items/middleware/metrics_middleware.go | 288 +++++++++--------- pkg/locales/middleware/metrics_middleware.go | 48 +-- pkg/members/middleware/metrics_middleware.go | 96 +++--- .../middleware/metrics_middleware.go | 80 ++--- .../middleware/metrics_middleware.go | 58 ++++ pkg/roles/middleware/metrics_middleware.go | 80 ++--- pkg/spaces/middleware/metrics_middleware.go | 160 +++++----- pkg/users/middleware/metrics_middleware.go | 96 +++--- 14 files changed, 698 insertions(+), 640 deletions(-) create mode 100644 pkg/references/middleware/metrics_middleware.go diff --git a/assets/templates/middleware/metrics b/assets/templates/middleware/metrics index 9e140628..9dd4047d 100644 --- a/assets/templates/middleware/metrics +++ b/assets/templates/middleware/metrics @@ -26,14 +26,14 @@ func {{ $funcName }} (requestMetrics *metrics.RequestMetrics) Middleware { {{ range $method := .Interface.Methods }} // {{ $method.Name }} implements {{ $.Interface.Type }} func (m {{ $decorator }}) {{ $method.Declaration }} { - m.requestMetrics.Total.WithLabelValues("{{ $method.Name }}").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("{{ $method.Name }}")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("{{ $method.Name }}").Inc() - } - }() - {{ $method.Pass "m.next." }} + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("{{ $method.Name }}").Inc() + {{ $method.ResultsNames }} = m.next.{{ $method.Call }} + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("{{ $method.Name }}").Inc() + return + } + return } {{ end }} \ No newline at end of file diff --git a/images/middleware/metrics_middleware.go b/images/middleware/metrics_middleware.go index 2ed5e6ad..f583718d 100644 --- a/images/middleware/metrics_middleware.go +++ b/images/middleware/metrics_middleware.go @@ -33,13 +33,13 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Get implements images.Images func (m metricsMiddleware) Get(ctx context.Context, source *files.File, opts *images.GetOptions) (result *files.File, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, source, opts) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + result, err = m.next.Get(ctx, source, opts) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } diff --git a/pkg/collaborators/middleware/metrics_middleware.go b/pkg/collaborators/middleware/metrics_middleware.go index 00eb495f..0e4dcc98 100644 --- a/pkg/collaborators/middleware/metrics_middleware.go +++ b/pkg/collaborators/middleware/metrics_middleware.go @@ -32,65 +32,65 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Get implements collaborators.Collaborators func (m metricsMiddleware) Get(ctx context.Context, spaceId string, subject string) (role string, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, spaceId, subject) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + role, err = m.next.Get(ctx, spaceId, subject) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // ListCollaborators implements collaborators.Collaborators func (m metricsMiddleware) ListCollaborators(ctx context.Context, spaceId string) (collaborators []*collaborators.Collaborator, err error) { - m.requestMetrics.Total.WithLabelValues("ListCollaborators").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListCollaborators")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("ListCollaborators").Inc() - } - }() - return m.next.ListCollaborators(ctx, spaceId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("ListCollaborators").Inc() + collaborators, err = m.next.ListCollaborators(ctx, spaceId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("ListCollaborators").Inc() + return + } + return } // ListSpaces implements collaborators.Collaborators func (m metricsMiddleware) ListSpaces(ctx context.Context, subject string) (spaces []*collaborators.Collaborator, err error) { - m.requestMetrics.Total.WithLabelValues("ListSpaces").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListSpaces")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("ListSpaces").Inc() - } - }() - return m.next.ListSpaces(ctx, subject) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("ListSpaces").Inc() + spaces, err = m.next.ListSpaces(ctx, subject) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("ListSpaces").Inc() + return + } + return } // Remove implements collaborators.Collaborators func (m metricsMiddleware) Remove(ctx context.Context, spaceId string, subject string) (err error) { - m.requestMetrics.Total.WithLabelValues("Remove").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Remove")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Remove").Inc() - } - }() - return m.next.Remove(ctx, spaceId, subject) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Remove").Inc() + err = m.next.Remove(ctx, spaceId, subject) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Remove").Inc() + return + } + return } // Set implements collaborators.Collaborators func (m metricsMiddleware) Set(ctx context.Context, spaceId string, subject string, role string) (err error) { - m.requestMetrics.Total.WithLabelValues("Set").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Set")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Set").Inc() - } - }() - return m.next.Set(ctx, spaceId, subject, role) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Set").Inc() + err = m.next.Set(ctx, spaceId, subject, role) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Set").Inc() + return + } + return } diff --git a/pkg/collections/middleware/metrics_middleware.go b/pkg/collections/middleware/metrics_middleware.go index b98b6266..012e1127 100644 --- a/pkg/collections/middleware/metrics_middleware.go +++ b/pkg/collections/middleware/metrics_middleware.go @@ -33,91 +33,91 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Create implements collections.Collections func (m metricsMiddleware) Create(ctx context.Context, collection *collections.Collection) (created *collections.Collection, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, collection) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + created, err = m.next.Create(ctx, collection) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements collections.Collections func (m metricsMiddleware) Delete(ctx context.Context, spaceId string, envId string, collectionId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, spaceId, envId, collectionId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, spaceId, envId, collectionId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // Get implements collections.Collections func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, options ...*collections.GetOptions) (collection *collections.Collection, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, spaceId, envId, collectionId, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + collection, err = m.next.Get(ctx, spaceId, envId, collectionId, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // List implements collections.Collections func (m metricsMiddleware) List(ctx context.Context, spaceId string, envId string, filter *collections.Filter) (collections []*collections.Collection, err error) { - m.requestMetrics.Total.WithLabelValues("List").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() - } - }() - return m.next.List(ctx, spaceId, envId, filter) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("List").Inc() + collections, err = m.next.List(ctx, spaceId, envId, filter) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() + return + } + return } // SetSchema implements collections.Collections func (m metricsMiddleware) SetSchema(ctx context.Context, spaceId string, envId string, collectionId string, schema *schema.Schema) (err error) { - m.requestMetrics.Total.WithLabelValues("SetSchema").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("SetSchema")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("SetSchema").Inc() - } - }() - return m.next.SetSchema(ctx, spaceId, envId, collectionId, schema) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("SetSchema").Inc() + err = m.next.SetSchema(ctx, spaceId, envId, collectionId, schema) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("SetSchema").Inc() + return + } + return } // SetState implements collections.Collections func (m metricsMiddleware) SetState(ctx context.Context, spaceId string, envId string, collectionId string, state *collections.StateInfo) (err error) { - m.requestMetrics.Total.WithLabelValues("SetState").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("SetState")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("SetState").Inc() - } - }() - return m.next.SetState(ctx, spaceId, envId, collectionId, state) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("SetState").Inc() + err = m.next.SetState(ctx, spaceId, envId, collectionId, state) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("SetState").Inc() + return + } + return } // Update implements collections.Collections func (m metricsMiddleware) Update(ctx context.Context, coll *collections.Collection) (err error) { - m.requestMetrics.Total.WithLabelValues("Update").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() - } - }() - return m.next.Update(ctx, coll) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Update").Inc() + err = m.next.Update(ctx, coll) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() + return + } + return } diff --git a/pkg/environments/middleware/metrics_middleware.go b/pkg/environments/middleware/metrics_middleware.go index da593edc..3f4723b6 100644 --- a/pkg/environments/middleware/metrics_middleware.go +++ b/pkg/environments/middleware/metrics_middleware.go @@ -32,104 +32,104 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Create implements environments.Environments func (m metricsMiddleware) Create(ctx context.Context, env *environments.Environment) (created *environments.Environment, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, env) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + created, err = m.next.Create(ctx, env) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements environments.Environments func (m metricsMiddleware) Delete(ctx context.Context, spaceId string, envId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, spaceId, envId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, spaceId, envId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // Get implements environments.Environments func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string) (env *environments.Environment, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, spaceId, envId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + env, err = m.next.Get(ctx, spaceId, envId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // List implements environments.Environments func (m metricsMiddleware) List(ctx context.Context, spaceId string) (envs []*environments.Environment, err error) { - m.requestMetrics.Total.WithLabelValues("List").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() - } - }() - return m.next.List(ctx, spaceId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("List").Inc() + envs, err = m.next.List(ctx, spaceId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() + return + } + return } // Migrate implements environments.Environments func (m metricsMiddleware) Migrate(ctx context.Context, spaceId string, envId string, options ...*environments.MigrateOptions) (err error) { - m.requestMetrics.Total.WithLabelValues("Migrate").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Migrate")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Migrate").Inc() - } - }() - return m.next.Migrate(ctx, spaceId, envId, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Migrate").Inc() + err = m.next.Migrate(ctx, spaceId, envId, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Migrate").Inc() + return + } + return } // RemoveAlias implements environments.Environments func (m metricsMiddleware) RemoveAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { - m.requestMetrics.Total.WithLabelValues("RemoveAlias").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("RemoveAlias")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("RemoveAlias").Inc() - } - }() - return m.next.RemoveAlias(ctx, spaceId, envId, alias) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("RemoveAlias").Inc() + err = m.next.RemoveAlias(ctx, spaceId, envId, alias) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("RemoveAlias").Inc() + return + } + return } // SetAlias implements environments.Environments func (m metricsMiddleware) SetAlias(ctx context.Context, spaceId string, envId string, alias string) (err error) { - m.requestMetrics.Total.WithLabelValues("SetAlias").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("SetAlias")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("SetAlias").Inc() - } - }() - return m.next.SetAlias(ctx, spaceId, envId, alias) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("SetAlias").Inc() + err = m.next.SetAlias(ctx, spaceId, envId, alias) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("SetAlias").Inc() + return + } + return } // Update implements environments.Environments func (m metricsMiddleware) Update(ctx context.Context, env *environments.Environment) (err error) { - m.requestMetrics.Total.WithLabelValues("Update").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() - } - }() - return m.next.Update(ctx, env) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Update").Inc() + err = m.next.Update(ctx, env) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() + return + } + return } diff --git a/pkg/invitations/middleware/metrics_middleware.go b/pkg/invitations/middleware/metrics_middleware.go index 8ce2d3b7..ac82571e 100644 --- a/pkg/invitations/middleware/metrics_middleware.go +++ b/pkg/invitations/middleware/metrics_middleware.go @@ -33,65 +33,65 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Accept implements invitations.Invitations func (m metricsMiddleware) Accept(ctx context.Context, invitationId string, userId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Accept").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Accept")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Accept").Inc() - } - }() - return m.next.Accept(ctx, invitationId, userId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Accept").Inc() + err = m.next.Accept(ctx, invitationId, userId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Accept").Inc() + return + } + return } // Create implements invitations.Invitations func (m metricsMiddleware) Create(ctx context.Context, invitation *invitations.Invitation) (created *invitations.Invitation, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, invitation) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + created, err = m.next.Create(ctx, invitation) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements invitations.Invitations func (m metricsMiddleware) Delete(ctx context.Context, invitationId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, invitationId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, invitationId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // Find implements invitations.Invitations func (m metricsMiddleware) Find(ctx context.Context, filter *invitations.Filter, opts *options.FindOptions) (invitations []*invitations.Invitation, total int, err error) { - m.requestMetrics.Total.WithLabelValues("Find").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Find")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc() - } - }() - return m.next.Find(ctx, filter, opts) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Find").Inc() + invitations, total, err = m.next.Find(ctx, filter, opts) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc() + return + } + return } // Get implements invitations.Invitations func (m metricsMiddleware) Get(ctx context.Context, invitationId string) (invitation *invitations.Invitation, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, invitationId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + invitation, err = m.next.Get(ctx, invitationId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } diff --git a/pkg/items/middleware/metrics_middleware.go b/pkg/items/middleware/metrics_middleware.go index 72fb917b..a9f7b8f9 100644 --- a/pkg/items/middleware/metrics_middleware.go +++ b/pkg/items/middleware/metrics_middleware.go @@ -33,234 +33,234 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Aggregate implements items.Items func (m metricsMiddleware) Aggregate(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.AggregateOptions) (result map[string]interface{}, err error) { - m.requestMetrics.Total.WithLabelValues("Aggregate").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Aggregate")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Aggregate").Inc() - } - }() - return m.next.Aggregate(ctx, spaceId, envId, collectionId, filter, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Aggregate").Inc() + result, err = m.next.Aggregate(ctx, spaceId, envId, collectionId, filter, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Aggregate").Inc() + return + } + return } // AggregatePublished implements items.Items func (m metricsMiddleware) AggregatePublished(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.AggregatePublishedOptions) (result map[string]interface{}, err error) { - m.requestMetrics.Total.WithLabelValues("AggregatePublished").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("AggregatePublished")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("AggregatePublished").Inc() - } - }() - return m.next.AggregatePublished(ctx, spaceId, envId, collectionId, filter, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("AggregatePublished").Inc() + result, err = m.next.AggregatePublished(ctx, spaceId, envId, collectionId, filter, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("AggregatePublished").Inc() + return + } + return } // Archive implements items.Items func (m metricsMiddleware) Archive(ctx context.Context, item *items.Item, options ...*items.ArchiveOptions) (err error) { - m.requestMetrics.Total.WithLabelValues("Archive").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Archive")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Archive").Inc() - } - }() - return m.next.Archive(ctx, item, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Archive").Inc() + err = m.next.Archive(ctx, item, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Archive").Inc() + return + } + return } // Create implements items.Items func (m metricsMiddleware) Create(ctx context.Context, item *items.Item, opts ...*items.CreateOptions) (created *items.Item, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, item, opts...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + created, err = m.next.Create(ctx, item, opts...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements items.Items func (m metricsMiddleware) Delete(ctx context.Context, item *items.Item, options ...*items.DeleteOptions) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, item, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, item, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // Find implements items.Items func (m metricsMiddleware) Find(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindOptions) (items []*items.Item, total int, err error) { - m.requestMetrics.Total.WithLabelValues("Find").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Find")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc() - } - }() - return m.next.Find(ctx, spaceId, envId, collectionId, filter, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Find").Inc() + items, total, err = m.next.Find(ctx, spaceId, envId, collectionId, filter, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc() + return + } + return } // FindArchived implements items.Items func (m metricsMiddleware) FindArchived(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindArchivedOptions) (items []*items.Item, total int, err error) { - m.requestMetrics.Total.WithLabelValues("FindArchived").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("FindArchived")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("FindArchived").Inc() - } - }() - return m.next.FindArchived(ctx, spaceId, envId, collectionId, filter, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("FindArchived").Inc() + items, total, err = m.next.FindArchived(ctx, spaceId, envId, collectionId, filter, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("FindArchived").Inc() + return + } + return } // FindPublished implements items.Items func (m metricsMiddleware) FindPublished(ctx context.Context, spaceId string, envId string, collectionId string, filter *items.Filter, options ...*items.FindPublishedOptions) (items []*items.Item, total int, err error) { - m.requestMetrics.Total.WithLabelValues("FindPublished").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("FindPublished")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("FindPublished").Inc() - } - }() - return m.next.FindPublished(ctx, spaceId, envId, collectionId, filter, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("FindPublished").Inc() + items, total, err = m.next.FindPublished(ctx, spaceId, envId, collectionId, filter, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("FindPublished").Inc() + return + } + return } // Get implements items.Items func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetOptions) (item *items.Item, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, spaceId, envId, collectionId, itemId, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + item, err = m.next.Get(ctx, spaceId, envId, collectionId, itemId, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // GetPublished implements items.Items func (m metricsMiddleware) GetPublished(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.GetPublishedOptions) (item *items.Item, err error) { - m.requestMetrics.Total.WithLabelValues("GetPublished").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("GetPublished")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("GetPublished").Inc() - } - }() - return m.next.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("GetPublished").Inc() + item, err = m.next.GetPublished(ctx, spaceId, envId, collectionId, itemId, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("GetPublished").Inc() + return + } + return } // GetRevision implements items.Items func (m metricsMiddleware) GetRevision(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, revisionId string, options ...*items.GetRevisionOptions) (item *items.Item, err error) { - m.requestMetrics.Total.WithLabelValues("GetRevision").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("GetRevision")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("GetRevision").Inc() - } - }() - return m.next.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("GetRevision").Inc() + item, err = m.next.GetRevision(ctx, spaceId, envId, collectionId, itemId, revisionId, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("GetRevision").Inc() + return + } + return } // Introspect implements items.Items func (m metricsMiddleware) Introspect(ctx context.Context, item *items.Item, opts ...*items.IntrospectOptions) (itm *items.Item, sch *schema.Schema, err error) { - m.requestMetrics.Total.WithLabelValues("Introspect").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Introspect")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Introspect").Inc() - } - }() - return m.next.Introspect(ctx, item, opts...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Introspect").Inc() + itm, sch, err = m.next.Introspect(ctx, item, opts...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Introspect").Inc() + return + } + return } // ListRevisions implements items.Items func (m metricsMiddleware) ListRevisions(ctx context.Context, spaceId string, envId string, collectionId string, itemId string, options ...*items.ListRevisionsOptions) (items []*items.Item, err error) { - m.requestMetrics.Total.WithLabelValues("ListRevisions").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListRevisions")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("ListRevisions").Inc() - } - }() - return m.next.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("ListRevisions").Inc() + items, err = m.next.ListRevisions(ctx, spaceId, envId, collectionId, itemId, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("ListRevisions").Inc() + return + } + return } // Publish implements items.Items func (m metricsMiddleware) Publish(ctx context.Context, item *items.Item, options ...*items.PublishOptions) (err error) { - m.requestMetrics.Total.WithLabelValues("Publish").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Publish")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Publish").Inc() - } - }() - return m.next.Publish(ctx, item, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Publish").Inc() + err = m.next.Publish(ctx, item, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Publish").Inc() + return + } + return } // Unarchive implements items.Items func (m metricsMiddleware) Unarchive(ctx context.Context, item *items.Item, options ...*items.UnarchiveOptions) (err error) { - m.requestMetrics.Total.WithLabelValues("Unarchive").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Unarchive")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Unarchive").Inc() - } - }() - return m.next.Unarchive(ctx, item, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Unarchive").Inc() + err = m.next.Unarchive(ctx, item, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Unarchive").Inc() + return + } + return } // Undelete implements items.Items func (m metricsMiddleware) Undelete(ctx context.Context, item *items.Item, options ...*items.UndeleteOptions) (err error) { - m.requestMetrics.Total.WithLabelValues("Undelete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Undelete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Undelete").Inc() - } - }() - return m.next.Undelete(ctx, item, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Undelete").Inc() + err = m.next.Undelete(ctx, item, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Undelete").Inc() + return + } + return } // Unpublish implements items.Items func (m metricsMiddleware) Unpublish(ctx context.Context, item *items.Item, options ...*items.UnpublishOptions) (err error) { - m.requestMetrics.Total.WithLabelValues("Unpublish").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Unpublish")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Unpublish").Inc() - } - }() - return m.next.Unpublish(ctx, item, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Unpublish").Inc() + err = m.next.Unpublish(ctx, item, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Unpublish").Inc() + return + } + return } // Update implements items.Items func (m metricsMiddleware) Update(ctx context.Context, item *items.Item, options ...*items.UpdateOptions) (err error) { - m.requestMetrics.Total.WithLabelValues("Update").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() - } - }() - return m.next.Update(ctx, item, options...) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Update").Inc() + err = m.next.Update(ctx, item, options...) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() + return + } + return } diff --git a/pkg/locales/middleware/metrics_middleware.go b/pkg/locales/middleware/metrics_middleware.go index cdd45c97..a8296a4c 100644 --- a/pkg/locales/middleware/metrics_middleware.go +++ b/pkg/locales/middleware/metrics_middleware.go @@ -32,39 +32,39 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Create implements locales.Locales func (m metricsMiddleware) Create(ctx context.Context, locale *locales.Locale) (created *locales.Locale, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, locale) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + created, err = m.next.Create(ctx, locale) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements locales.Locales func (m metricsMiddleware) Delete(ctx context.Context, spaceId string, localeId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, spaceId, localeId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, spaceId, localeId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // List implements locales.Locales func (m metricsMiddleware) List(ctx context.Context, spaceId string) (locales []*locales.Locale, err error) { - m.requestMetrics.Total.WithLabelValues("List").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() - } - }() - return m.next.List(ctx, spaceId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("List").Inc() + locales, err = m.next.List(ctx, spaceId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() + return + } + return } diff --git a/pkg/members/middleware/metrics_middleware.go b/pkg/members/middleware/metrics_middleware.go index 27b28e64..8e947287 100644 --- a/pkg/members/middleware/metrics_middleware.go +++ b/pkg/members/middleware/metrics_middleware.go @@ -32,78 +32,78 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Get implements members.Members func (m metricsMiddleware) Get(ctx context.Context, orgId string, userId string) (role members.Role, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, orgId, userId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + role, err = m.next.Get(ctx, orgId, userId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // ListMembers implements members.Members func (m metricsMiddleware) ListMembers(ctx context.Context, orgId string) (members []*members.Member, err error) { - m.requestMetrics.Total.WithLabelValues("ListMembers").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListMembers")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("ListMembers").Inc() - } - }() - return m.next.ListMembers(ctx, orgId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("ListMembers").Inc() + members, err = m.next.ListMembers(ctx, orgId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("ListMembers").Inc() + return + } + return } // ListOrganizations implements members.Members func (m metricsMiddleware) ListOrganizations(ctx context.Context, userId string) (organizations []*members.Member, err error) { - m.requestMetrics.Total.WithLabelValues("ListOrganizations").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListOrganizations")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("ListOrganizations").Inc() - } - }() - return m.next.ListOrganizations(ctx, userId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("ListOrganizations").Inc() + organizations, err = m.next.ListOrganizations(ctx, userId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("ListOrganizations").Inc() + return + } + return } // Remove implements members.Members func (m metricsMiddleware) Remove(ctx context.Context, orgId string, userId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Remove").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Remove")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Remove").Inc() - } - }() - return m.next.Remove(ctx, orgId, userId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Remove").Inc() + err = m.next.Remove(ctx, orgId, userId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Remove").Inc() + return + } + return } // RemoveAll implements members.Members func (m metricsMiddleware) RemoveAll(ctx context.Context, orgId string) (err error) { - m.requestMetrics.Total.WithLabelValues("RemoveAll").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("RemoveAll")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("RemoveAll").Inc() - } - }() - return m.next.RemoveAll(ctx, orgId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("RemoveAll").Inc() + err = m.next.RemoveAll(ctx, orgId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("RemoveAll").Inc() + return + } + return } // Set implements members.Members func (m metricsMiddleware) Set(ctx context.Context, orgId string, userId string, role members.Role) (err error) { - m.requestMetrics.Total.WithLabelValues("Set").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Set")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Set").Inc() - } - }() - return m.next.Set(ctx, orgId, userId, role) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Set").Inc() + err = m.next.Set(ctx, orgId, userId, role) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Set").Inc() + return + } + return } diff --git a/pkg/organizations/middleware/metrics_middleware.go b/pkg/organizations/middleware/metrics_middleware.go index c7cbccc6..dc111073 100644 --- a/pkg/organizations/middleware/metrics_middleware.go +++ b/pkg/organizations/middleware/metrics_middleware.go @@ -33,65 +33,65 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Create implements organizations.Organizations func (m metricsMiddleware) Create(ctx context.Context, org *organizations.Organization) (created *organizations.Organization, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, org) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + created, err = m.next.Create(ctx, org) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements organizations.Organizations func (m metricsMiddleware) Delete(ctx context.Context, orgId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, orgId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, orgId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // Find implements organizations.Organizations func (m metricsMiddleware) Find(ctx context.Context, filter *organizations.Filter, opts *options.FindOptions) (orgs []*organizations.Organization, total int, err error) { - m.requestMetrics.Total.WithLabelValues("Find").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Find")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc() - } - }() - return m.next.Find(ctx, filter, opts) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Find").Inc() + orgs, total, err = m.next.Find(ctx, filter, opts) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc() + return + } + return } // Get implements organizations.Organizations func (m metricsMiddleware) Get(ctx context.Context, orgId string) (org *organizations.Organization, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, orgId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + org, err = m.next.Get(ctx, orgId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // Update implements organizations.Organizations func (m metricsMiddleware) Update(ctx context.Context, org *organizations.Organization) (err error) { - m.requestMetrics.Total.WithLabelValues("Update").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() - } - }() - return m.next.Update(ctx, org) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Update").Inc() + err = m.next.Update(ctx, org) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() + return + } + return } diff --git a/pkg/references/middleware/metrics_middleware.go b/pkg/references/middleware/metrics_middleware.go new file mode 100644 index 00000000..520dd768 --- /dev/null +++ b/pkg/references/middleware/metrics_middleware.go @@ -0,0 +1,58 @@ +// Code generated by gowrap. DO NOT EDIT. +// template: ../../../assets/templates/middleware/metrics +// gowrap: http://github.com/hexdigest/gowrap + +package middleware + +//go:generate gowrap gen -p git.perx.ru/perxis/perxis-go/pkg/references -i References -t ../../../assets/templates/middleware/metrics -o metrics_middleware.go -l "" + +import ( + "context" + + "git.perx.ru/perxis/perxis-go/pkg/items" + "git.perx.ru/perxis/perxis-go/pkg/metrics" + "git.perx.ru/perxis/perxis-go/pkg/references" + "github.com/prometheus/client_golang/prometheus" +) + +// metricsMiddleware implements references.References that is instrumented with metrics +type metricsMiddleware struct { + requestMetrics *metrics.RequestMetrics + next references.References +} + +// MetricsMiddleware instruments an implementation of the metricsMiddleware with metrics +func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { + return func(next references.References) references.References { + return &metricsMiddleware{ + requestMetrics: requestMetrics, + next: next, + } + } +} + +// Get implements references.References +func (m metricsMiddleware) Get(ctx context.Context, spaceId string, envId string, references []*references.Reference) (items []*items.Item, notfound []*references.Reference, err error) { + timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + items, notfound, err = m.next.Get(ctx, spaceId, envId, references) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return +} + +// Publish implements references.References +func (m metricsMiddleware) Publish(ctx context.Context, spaceId string, envId string, references []*references.Reference, recursive bool, force bool) (published []*references.Reference, notfound []*references.Reference, unpublished []*references.Reference, err error) { + timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Publish")) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Publish").Inc() + published, notfound, unpublished, err = m.next.Publish(ctx, spaceId, envId, references, recursive, force) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Publish").Inc() + return + } + return +} diff --git a/pkg/roles/middleware/metrics_middleware.go b/pkg/roles/middleware/metrics_middleware.go index 1df246c1..75e242ef 100644 --- a/pkg/roles/middleware/metrics_middleware.go +++ b/pkg/roles/middleware/metrics_middleware.go @@ -32,65 +32,65 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Create implements roles.Roles func (m metricsMiddleware) Create(ctx context.Context, role *roles.Role) (created *roles.Role, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, role) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + created, err = m.next.Create(ctx, role) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements roles.Roles func (m metricsMiddleware) Delete(ctx context.Context, spaceId string, roleId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, spaceId, roleId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, spaceId, roleId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // Get implements roles.Roles func (m metricsMiddleware) Get(ctx context.Context, spaceId string, roleId string) (role *roles.Role, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, spaceId, roleId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + role, err = m.next.Get(ctx, spaceId, roleId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // List implements roles.Roles func (m metricsMiddleware) List(ctx context.Context, spaceId string) (roles []*roles.Role, err error) { - m.requestMetrics.Total.WithLabelValues("List").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() - } - }() - return m.next.List(ctx, spaceId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("List").Inc() + roles, err = m.next.List(ctx, spaceId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() + return + } + return } // Update implements roles.Roles func (m metricsMiddleware) Update(ctx context.Context, role *roles.Role) (err error) { - m.requestMetrics.Total.WithLabelValues("Update").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() - } - }() - return m.next.Update(ctx, role) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Update").Inc() + err = m.next.Update(ctx, role) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() + return + } + return } diff --git a/pkg/spaces/middleware/metrics_middleware.go b/pkg/spaces/middleware/metrics_middleware.go index ba8d95a6..df81e592 100644 --- a/pkg/spaces/middleware/metrics_middleware.go +++ b/pkg/spaces/middleware/metrics_middleware.go @@ -32,130 +32,130 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // AbortTransfer implements spaces.Spaces func (m metricsMiddleware) AbortTransfer(ctx context.Context, spaceID string) (err error) { - m.requestMetrics.Total.WithLabelValues("AbortTransfer").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("AbortTransfer")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("AbortTransfer").Inc() - } - }() - return m.next.AbortTransfer(ctx, spaceID) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("AbortTransfer").Inc() + err = m.next.AbortTransfer(ctx, spaceID) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("AbortTransfer").Inc() + return + } + return } // Create implements spaces.Spaces func (m metricsMiddleware) Create(ctx context.Context, space *spaces.Space) (created *spaces.Space, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, space) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + created, err = m.next.Create(ctx, space) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements spaces.Spaces func (m metricsMiddleware) Delete(ctx context.Context, spaceId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, spaceId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, spaceId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // Get implements spaces.Spaces func (m metricsMiddleware) Get(ctx context.Context, spaceId string) (space *spaces.Space, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, spaceId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + space, err = m.next.Get(ctx, spaceId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // List implements spaces.Spaces func (m metricsMiddleware) List(ctx context.Context, orgId string) (spaces []*spaces.Space, err error) { - m.requestMetrics.Total.WithLabelValues("List").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("List")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() - } - }() - return m.next.List(ctx, orgId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("List").Inc() + spaces, err = m.next.List(ctx, orgId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("List").Inc() + return + } + return } // ListTransfers implements spaces.Spaces func (m metricsMiddleware) ListTransfers(ctx context.Context, orgID string) (spaces []*spaces.Space, err error) { - m.requestMetrics.Total.WithLabelValues("ListTransfers").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("ListTransfers")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("ListTransfers").Inc() - } - }() - return m.next.ListTransfers(ctx, orgID) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("ListTransfers").Inc() + spaces, err = m.next.ListTransfers(ctx, orgID) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("ListTransfers").Inc() + return + } + return } // Move implements spaces.Spaces func (m metricsMiddleware) Move(ctx context.Context, spaceID string, orgID string) (err error) { - m.requestMetrics.Total.WithLabelValues("Move").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Move")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Move").Inc() - } - }() - return m.next.Move(ctx, spaceID, orgID) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Move").Inc() + err = m.next.Move(ctx, spaceID, orgID) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Move").Inc() + return + } + return } // Transfer implements spaces.Spaces func (m metricsMiddleware) Transfer(ctx context.Context, spaceID string, transferToOrg string) (err error) { - m.requestMetrics.Total.WithLabelValues("Transfer").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Transfer")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Transfer").Inc() - } - }() - return m.next.Transfer(ctx, spaceID, transferToOrg) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Transfer").Inc() + err = m.next.Transfer(ctx, spaceID, transferToOrg) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Transfer").Inc() + return + } + return } // Update implements spaces.Spaces func (m metricsMiddleware) Update(ctx context.Context, space *spaces.Space) (err error) { - m.requestMetrics.Total.WithLabelValues("Update").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() - } - }() - return m.next.Update(ctx, space) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Update").Inc() + err = m.next.Update(ctx, space) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() + return + } + return } // UpdateConfig implements spaces.Spaces func (m metricsMiddleware) UpdateConfig(ctx context.Context, spaceId string, config *spaces.Config) (err error) { - m.requestMetrics.Total.WithLabelValues("UpdateConfig").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("UpdateConfig")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("UpdateConfig").Inc() - } - }() - return m.next.UpdateConfig(ctx, spaceId, config) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("UpdateConfig").Inc() + err = m.next.UpdateConfig(ctx, spaceId, config) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("UpdateConfig").Inc() + return + } + return } diff --git a/pkg/users/middleware/metrics_middleware.go b/pkg/users/middleware/metrics_middleware.go index df214661..f1aa52ff 100644 --- a/pkg/users/middleware/metrics_middleware.go +++ b/pkg/users/middleware/metrics_middleware.go @@ -33,78 +33,78 @@ func MetricsMiddleware(requestMetrics *metrics.RequestMetrics) Middleware { // Create implements users.Users func (m metricsMiddleware) Create(ctx context.Context, create *users.User) (user *users.User, err error) { - m.requestMetrics.Total.WithLabelValues("Create").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Create")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() - } - }() - return m.next.Create(ctx, create) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Create").Inc() + user, err = m.next.Create(ctx, create) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Create").Inc() + return + } + return } // Delete implements users.Users func (m metricsMiddleware) Delete(ctx context.Context, userId string) (err error) { - m.requestMetrics.Total.WithLabelValues("Delete").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Delete")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() - } - }() - return m.next.Delete(ctx, userId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Delete").Inc() + err = m.next.Delete(ctx, userId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Delete").Inc() + return + } + return } // Find implements users.Users func (m metricsMiddleware) Find(ctx context.Context, filter *users.Filter, options *options.FindOptions) (users []*users.User, total int, err error) { - m.requestMetrics.Total.WithLabelValues("Find").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Find")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc() - } - }() - return m.next.Find(ctx, filter, options) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Find").Inc() + users, total, err = m.next.Find(ctx, filter, options) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Find").Inc() + return + } + return } // Get implements users.Users func (m metricsMiddleware) Get(ctx context.Context, userId string) (user *users.User, err error) { - m.requestMetrics.Total.WithLabelValues("Get").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Get")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() - } - }() - return m.next.Get(ctx, userId) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Get").Inc() + user, err = m.next.Get(ctx, userId) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Get").Inc() + return + } + return } // GetByIdentity implements users.Users func (m metricsMiddleware) GetByIdentity(ctx context.Context, identity string) (user *users.User, err error) { - m.requestMetrics.Total.WithLabelValues("GetByIdentity").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("GetByIdentity")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("GetByIdentity").Inc() - } - }() - return m.next.GetByIdentity(ctx, identity) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("GetByIdentity").Inc() + user, err = m.next.GetByIdentity(ctx, identity) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("GetByIdentity").Inc() + return + } + return } // Update implements users.Users func (m metricsMiddleware) Update(ctx context.Context, update *users.User) (err error) { - m.requestMetrics.Total.WithLabelValues("Update").Inc() timer := prometheus.NewTimer(m.requestMetrics.DurationSeconds.WithLabelValues("Update")) - defer func() { - timer.ObserveDuration() - if err != nil { - m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() - } - }() - return m.next.Update(ctx, update) + defer timer.ObserveDuration() + m.requestMetrics.Total.WithLabelValues("Update").Inc() + err = m.next.Update(ctx, update) + if err != nil { + m.requestMetrics.FailedTotal.WithLabelValues("Update").Inc() + return + } + return } -- GitLab