From bcf9c32a8f350f5d18b6747cda55c088c38211ba Mon Sep 17 00:00:00 2001 From: Felix Gateru Date: Wed, 16 Oct 2024 12:08:31 +0300 Subject: [PATCH 1/4] refactor(middleware): group service middleware Signed-off-by: Felix Gateru --- auth/middleware/doc.go | 9 +++++++++ auth/{api => middleware}/logging.go | 2 +- auth/{api => middleware}/metrics.go | 2 +- auth/{tracing => middleware}/tracing.go | 6 +++--- auth/tracing/doc.go | 12 ------------ bootstrap/middleware/doc.go | 9 +++++++++ bootstrap/{tracing => middleware}/tracing.go | 6 +++--- bootstrap/tracing/doc.go | 12 ------------ certs/middleware/doc.go | 9 +++++++++ certs/{api => middleware}/logging.go | 2 +- certs/{api => middleware}/metrics.go | 2 +- certs/{tracing => middleware}/tracing.go | 6 +++--- certs/tracing/doc.go | 12 ------------ cmd/auth/main.go | 9 ++++----- cmd/bootstrap/main.go | 3 +-- cmd/certs/main.go | 8 ++++---- cmd/coap/main.go | 8 ++++---- cmd/postgres-reader/main.go | 5 +++-- cmd/provision/main.go | 3 ++- cmd/things/main.go | 6 ++---- cmd/timescale-reader/main.go | 5 +++-- cmd/users/main.go | 6 ++---- cmd/ws/main.go | 8 ++++---- coap/middleware/doc.go | 9 +++++++++ coap/{api => middleware}/logging.go | 2 +- coap/{api => middleware}/metrics.go | 2 +- coap/{tracing/adapter.go => middleware/tracing.go} | 6 +++--- coap/tracing/doc.go | 12 ------------ consumers/notifiers/middleware/doc.go | 9 +++++++++ consumers/notifiers/{api => middleware}/logging.go | 2 +- consumers/notifiers/{api => middleware}/metrics.go | 2 +- .../{tracing => middleware}/subscriptions.go | 2 +- consumers/notifiers/tracing/doc.go | 12 ------------ internal/groups/middleware/doc.go | 6 +++++- internal/groups/{tracing => middleware}/tracing.go | 6 +++--- internal/groups/tracing/doc.go | 12 ------------ invitations/middleware/doc.go | 10 +++++----- journal/middleware/doc.go | 7 +++++-- provision/middleware/doc.go | 9 +++++++++ provision/{api => middleware}/logging.go | 2 +- readers/middleware/doc.go | 9 +++++++++ readers/{api => middleware}/logging.go | 2 +- readers/{api => middleware}/metrics.go | 2 +- things/middleware/doc.go | 6 +++++- things/{tracing => middleware}/tracing.go | 6 +++--- things/tracing/doc.go | 12 ------------ users/middleware/doc.go | 6 +++++- users/{tracing => middleware}/tracing.go | 6 +++--- users/tracing/doc.go | 12 ------------ ws/middleware/doc.go | 9 +++++++++ ws/{api => middleware}/logging.go | 2 +- ws/{api => middleware}/metrics.go | 2 +- ws/{tracing => middleware}/tracing.go | 6 +++--- ws/tracing/doc.go | 12 ------------ 54 files changed, 164 insertions(+), 188 deletions(-) create mode 100644 auth/middleware/doc.go rename auth/{api => middleware}/logging.go (99%) rename auth/{api => middleware}/metrics.go (99%) rename auth/{tracing => middleware}/tracing.go (96%) delete mode 100644 auth/tracing/doc.go create mode 100644 bootstrap/middleware/doc.go rename bootstrap/{tracing => middleware}/tracing.go (97%) delete mode 100644 bootstrap/tracing/doc.go create mode 100644 certs/middleware/doc.go rename certs/{api => middleware}/logging.go (99%) rename certs/{api => middleware}/metrics.go (99%) rename certs/{tracing => middleware}/tracing.go (93%) delete mode 100644 certs/tracing/doc.go create mode 100644 coap/middleware/doc.go rename coap/{api => middleware}/logging.go (99%) rename coap/{api => middleware}/metrics.go (98%) rename coap/{tracing/adapter.go => middleware/tracing.go} (88%) delete mode 100644 coap/tracing/doc.go create mode 100644 consumers/notifiers/middleware/doc.go rename consumers/notifiers/{api => middleware}/logging.go (99%) rename consumers/notifiers/{api => middleware}/metrics.go (99%) rename consumers/notifiers/{tracing => middleware}/subscriptions.go (99%) delete mode 100644 consumers/notifiers/tracing/doc.go rename internal/groups/{tracing => middleware}/tracing.go (96%) delete mode 100644 internal/groups/tracing/doc.go create mode 100644 provision/middleware/doc.go rename provision/{api => middleware}/logging.go (99%) create mode 100644 readers/middleware/doc.go rename readers/{api => middleware}/logging.go (98%) rename readers/{api => middleware}/metrics.go (98%) rename things/{tracing => middleware}/tracing.go (97%) delete mode 100644 things/tracing/doc.go rename users/{tracing => middleware}/tracing.go (98%) delete mode 100644 users/tracing/doc.go create mode 100644 ws/middleware/doc.go rename ws/{api => middleware}/logging.go (98%) rename ws/{api => middleware}/metrics.go (98%) rename ws/{tracing => middleware}/tracing.go (82%) delete mode 100644 ws/tracing/doc.go diff --git a/auth/middleware/doc.go b/auth/middleware/doc.go new file mode 100644 index 0000000000..0af8300b06 --- /dev/null +++ b/auth/middleware/doc.go @@ -0,0 +1,9 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides tracing, logging and metrics middleware +// for Magistrala Auth service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. +package middleware diff --git a/auth/api/logging.go b/auth/middleware/logging.go similarity index 99% rename from auth/api/logging.go rename to auth/middleware/logging.go index 30182bb4c4..f6133f4b50 100644 --- a/auth/api/logging.go +++ b/auth/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/auth/api/metrics.go b/auth/middleware/metrics.go similarity index 99% rename from auth/api/metrics.go rename to auth/middleware/metrics.go index 1e2befa8d2..3f68dbe05e 100644 --- a/auth/api/metrics.go +++ b/auth/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/auth/tracing/tracing.go b/auth/middleware/tracing.go similarity index 96% rename from auth/tracing/tracing.go rename to auth/middleware/tracing.go index 97b5f1790f..e7ae39c72d 100644 --- a/auth/tracing/tracing.go +++ b/auth/middleware/tracing.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package tracing +package middleware import ( "context" @@ -20,8 +20,8 @@ type tracingMiddleware struct { svc auth.Service } -// New returns a new group service with tracing capabilities. -func New(svc auth.Service, tracer trace.Tracer) auth.Service { +// TracingMiddleware returns a new auth service with tracing capabilities. +func TracingMiddleware(svc auth.Service, tracer trace.Tracer) auth.Service { return &tracingMiddleware{tracer, svc} } diff --git a/auth/tracing/doc.go b/auth/tracing/doc.go deleted file mode 100644 index 5aa1b44b98..0000000000 --- a/auth/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala Users service. -// -// This package provides tracing middleware for Magistrala Users service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala Users service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing diff --git a/bootstrap/middleware/doc.go b/bootstrap/middleware/doc.go new file mode 100644 index 0000000000..0a10a40144 --- /dev/null +++ b/bootstrap/middleware/doc.go @@ -0,0 +1,9 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides authorization, tracing, logging and metrics middleware +// for Magistrala Boostrap service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. +package middleware diff --git a/bootstrap/tracing/tracing.go b/bootstrap/middleware/tracing.go similarity index 97% rename from bootstrap/tracing/tracing.go rename to bootstrap/middleware/tracing.go index cd188050b8..63652ee455 100644 --- a/bootstrap/tracing/tracing.go +++ b/bootstrap/middleware/tracing.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package tracing +package middleware import ( "context" @@ -19,8 +19,8 @@ type tracingMiddleware struct { svc bootstrap.Service } -// New returns a new bootstrap service with tracing capabilities. -func New(svc bootstrap.Service, tracer trace.Tracer) bootstrap.Service { +// TracingMiddleware returns a new bootstrap service with tracing capabilities. +func TracingMiddleware(svc bootstrap.Service, tracer trace.Tracer) bootstrap.Service { return &tracingMiddleware{tracer, svc} } diff --git a/bootstrap/tracing/doc.go b/bootstrap/tracing/doc.go deleted file mode 100644 index 5aa1b44b98..0000000000 --- a/bootstrap/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala Users service. -// -// This package provides tracing middleware for Magistrala Users service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala Users service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing diff --git a/certs/middleware/doc.go b/certs/middleware/doc.go new file mode 100644 index 0000000000..0af8300b06 --- /dev/null +++ b/certs/middleware/doc.go @@ -0,0 +1,9 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides tracing, logging and metrics middleware +// for Magistrala Auth service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. +package middleware diff --git a/certs/api/logging.go b/certs/middleware/logging.go similarity index 99% rename from certs/api/logging.go rename to certs/middleware/logging.go index 86a113f625..93805a4131 100644 --- a/certs/api/logging.go +++ b/certs/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/certs/api/metrics.go b/certs/middleware/metrics.go similarity index 99% rename from certs/api/metrics.go rename to certs/middleware/metrics.go index fee094753a..122198a3b8 100644 --- a/certs/api/metrics.go +++ b/certs/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/certs/tracing/tracing.go b/certs/middleware/tracing.go similarity index 93% rename from certs/tracing/tracing.go rename to certs/middleware/tracing.go index cf8604a89b..247c330d36 100644 --- a/certs/tracing/tracing.go +++ b/certs/middleware/tracing.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package tracing +package middleware import ( "context" @@ -18,8 +18,8 @@ type tracingMiddleware struct { svc certs.Service } -// New returns a new certs service with tracing capabilities. -func New(svc certs.Service, tracer trace.Tracer) certs.Service { +// TracingMiddleware returns a new certs service with tracing capabilities. +func TracingMiddleware(svc certs.Service, tracer trace.Tracer) certs.Service { return &tracingMiddleware{tracer, svc} } diff --git a/certs/tracing/doc.go b/certs/tracing/doc.go deleted file mode 100644 index 6a419f3b5c..0000000000 --- a/certs/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala Users Groups service. -// -// This package provides tracing middleware for Magistrala Users Groups service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala Users Groups service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing diff --git a/cmd/auth/main.go b/cmd/auth/main.go index a29477830c..f92b175ab8 100644 --- a/cmd/auth/main.go +++ b/cmd/auth/main.go @@ -15,15 +15,14 @@ import ( chclient "github.com/absmach/callhome/pkg/client" "github.com/absmach/magistrala" "github.com/absmach/magistrala/auth" - api "github.com/absmach/magistrala/auth/api" authgrpcapi "github.com/absmach/magistrala/auth/api/grpc/auth" domainsgrpcapi "github.com/absmach/magistrala/auth/api/grpc/domains" tokengrpcapi "github.com/absmach/magistrala/auth/api/grpc/token" httpapi "github.com/absmach/magistrala/auth/api/http" "github.com/absmach/magistrala/auth/events" "github.com/absmach/magistrala/auth/jwt" + "github.com/absmach/magistrala/auth/middleware" apostgres "github.com/absmach/magistrala/auth/postgres" - "github.com/absmach/magistrala/auth/tracing" mglog "github.com/absmach/magistrala/logger" "github.com/absmach/magistrala/pkg/jaeger" "github.com/absmach/magistrala/pkg/policies/spicedb" @@ -224,10 +223,10 @@ func newService(ctx context.Context, db *sqlx.DB, tracer trace.Tracer, cfg confi logger.Error(fmt.Sprintf("failed to init event store middleware : %s", err)) return nil } - svc = api.LoggingMiddleware(svc, logger) + svc = middleware.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("groups", "api") - svc = api.MetricsMiddleware(svc, counter, latency) - svc = tracing.New(svc, tracer) + svc = middleware.MetricsMiddleware(svc, counter, latency) + svc = middleware.TracingMiddleware(svc, tracer) return svc } diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index cfe998b41e..4ea8653a0f 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -20,7 +20,6 @@ import ( "github.com/absmach/magistrala/bootstrap/events/producer" "github.com/absmach/magistrala/bootstrap/middleware" bootstrappg "github.com/absmach/magistrala/bootstrap/postgres" - "github.com/absmach/magistrala/bootstrap/tracing" mglog "github.com/absmach/magistrala/logger" authsvcAuthn "github.com/absmach/magistrala/pkg/authn/authsvc" mgauthz "github.com/absmach/magistrala/pkg/authz" @@ -223,7 +222,7 @@ func newService(ctx context.Context, authz mgauthz.Authorization, policySvc poli svc = middleware.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") svc = middleware.MetricsMiddleware(svc, counter, latency) - svc = tracing.New(svc, tracer) + svc = middleware.TracingMiddleware(svc, tracer) return svc, nil } diff --git a/cmd/certs/main.go b/cmd/certs/main.go index 00c7ac3242..a3085ff47b 100644 --- a/cmd/certs/main.go +++ b/cmd/certs/main.go @@ -16,8 +16,8 @@ import ( "github.com/absmach/magistrala" "github.com/absmach/magistrala/certs" "github.com/absmach/magistrala/certs/api" + "github.com/absmach/magistrala/certs/middleware" pki "github.com/absmach/magistrala/certs/pki/amcerts" - "github.com/absmach/magistrala/certs/tracing" mglog "github.com/absmach/magistrala/logger" authsvcAuthn "github.com/absmach/magistrala/pkg/authn/authsvc" "github.com/absmach/magistrala/pkg/grpcclient" @@ -159,10 +159,10 @@ func newService(tracer trace.Tracer, logger *slog.Logger, cfg config, pkiAgent p } sdk := mgsdk.NewSDK(config) svc := certs.New(sdk, pkiAgent) - svc = api.LoggingMiddleware(svc, logger) + svc = middleware.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = api.MetricsMiddleware(svc, counter, latency) - svc = tracing.New(svc, tracer) + svc = middleware.MetricsMiddleware(svc, counter, latency) + svc = middleware.TracingMiddleware(svc, tracer) return svc } diff --git a/cmd/coap/main.go b/cmd/coap/main.go index ad16e992c1..0b765b43eb 100644 --- a/cmd/coap/main.go +++ b/cmd/coap/main.go @@ -15,7 +15,7 @@ import ( "github.com/absmach/magistrala" "github.com/absmach/magistrala/coap" "github.com/absmach/magistrala/coap/api" - "github.com/absmach/magistrala/coap/tracing" + "github.com/absmach/magistrala/coap/middleware" mglog "github.com/absmach/magistrala/logger" "github.com/absmach/magistrala/pkg/grpcclient" jaegerclient "github.com/absmach/magistrala/pkg/jaeger" @@ -128,12 +128,12 @@ func main() { svc := coap.New(thingsClient, nps) - svc = tracing.New(tracer, svc) + svc = middleware.TracingMiddleware(tracer, svc) - svc = api.LoggingMiddleware(svc, logger) + svc = middleware.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = middleware.MetricsMiddleware(svc, counter, latency) hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(cfg.InstanceID), logger) diff --git a/cmd/postgres-reader/main.go b/cmd/postgres-reader/main.go index d07f40a2af..d8bb5f4bcb 100644 --- a/cmd/postgres-reader/main.go +++ b/cmd/postgres-reader/main.go @@ -23,6 +23,7 @@ import ( "github.com/absmach/magistrala/pkg/uuid" "github.com/absmach/magistrala/readers" "github.com/absmach/magistrala/readers/api" + "github.com/absmach/magistrala/readers/middleware" "github.com/absmach/magistrala/readers/postgres" "github.com/caarlos0/env/v11" "github.com/jmoiron/sqlx" @@ -147,9 +148,9 @@ func main() { func newService(db *sqlx.DB, logger *slog.Logger) readers.MessageRepository { svc := postgres.New(db) - svc = api.LoggingMiddleware(svc, logger) + svc = middleware.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("postgres", "message_reader") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = middleware.MetricsMiddleware(svc, counter, latency) return svc } diff --git a/cmd/provision/main.go b/cmd/provision/main.go index 939a070b8b..d7957f575f 100644 --- a/cmd/provision/main.go +++ b/cmd/provision/main.go @@ -24,6 +24,7 @@ import ( "github.com/absmach/magistrala/pkg/uuid" "github.com/absmach/magistrala/provision" "github.com/absmach/magistrala/provision/api" + "github.com/absmach/magistrala/provision/middleware" "github.com/caarlos0/env/v11" "golang.org/x/sync/errgroup" ) @@ -84,7 +85,7 @@ func main() { SDK := mgsdk.NewSDK(SDKCfg) svc := provision.New(cfg, SDK, logger) - svc = api.NewLoggingMiddleware(svc, logger) + svc = middleware.NewLoggingMiddleware(svc, logger) httpServerConfig := server.Config{Host: "", Port: cfg.Server.HTTPPort, KeyFile: cfg.Server.ServerKey, CertFile: cfg.Server.ServerCert} hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger) diff --git a/cmd/things/main.go b/cmd/things/main.go index 7110e4c09b..a2c3ff7e0b 100644 --- a/cmd/things/main.go +++ b/cmd/things/main.go @@ -20,7 +20,6 @@ import ( gevents "github.com/absmach/magistrala/internal/groups/events" gmiddleware "github.com/absmach/magistrala/internal/groups/middleware" gpostgres "github.com/absmach/magistrala/internal/groups/postgres" - gtracing "github.com/absmach/magistrala/internal/groups/tracing" mglog "github.com/absmach/magistrala/logger" authsvcAuthn "github.com/absmach/magistrala/pkg/authn/authsvc" mgauthz "github.com/absmach/magistrala/pkg/authz" @@ -44,7 +43,6 @@ import ( thevents "github.com/absmach/magistrala/things/events" tmiddleware "github.com/absmach/magistrala/things/middleware" thingspg "github.com/absmach/magistrala/things/postgres" - ctracing "github.com/absmach/magistrala/things/tracing" "github.com/authzed/authzed-go/v1" "github.com/authzed/grpcutil" "github.com/caarlos0/env/v11" @@ -262,12 +260,12 @@ func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth csvc = tmiddleware.AuthorizationMiddleware(csvc, authz) gsvc = gmiddleware.AuthorizationMiddleware(gsvc, authz) - csvc = ctracing.New(csvc, tracer) + csvc = tmiddleware.TracingMiddleware(csvc, tracer) csvc = tmiddleware.LoggingMiddleware(csvc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") csvc = tmiddleware.MetricsMiddleware(csvc, counter, latency) - gsvc = gtracing.New(gsvc, tracer) + gsvc = gmiddleware.TracingMiddleware(gsvc, tracer) gsvc = gmiddleware.LoggingMiddleware(gsvc, logger) counter, latency = prometheus.MakeMetrics(fmt.Sprintf("%s_groups", svcName), "api") gsvc = gmiddleware.MetricsMiddleware(gsvc, counter, latency) diff --git a/cmd/timescale-reader/main.go b/cmd/timescale-reader/main.go index ba6dde416a..a9d6760826 100644 --- a/cmd/timescale-reader/main.go +++ b/cmd/timescale-reader/main.go @@ -23,6 +23,7 @@ import ( "github.com/absmach/magistrala/pkg/uuid" "github.com/absmach/magistrala/readers" "github.com/absmach/magistrala/readers/api" + "github.com/absmach/magistrala/readers/middleware" "github.com/absmach/magistrala/readers/timescale" "github.com/caarlos0/env/v11" "github.com/jmoiron/sqlx" @@ -145,9 +146,9 @@ func main() { func newService(db *sqlx.DB, logger *slog.Logger) readers.MessageRepository { svc := timescale.New(db) - svc = api.LoggingMiddleware(svc, logger) + svc = middleware.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("timescale", "message_reader") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = middleware.MetricsMiddleware(svc, counter, latency) return svc } diff --git a/cmd/users/main.go b/cmd/users/main.go index 2c8a53e080..6f118a4da3 100644 --- a/cmd/users/main.go +++ b/cmd/users/main.go @@ -21,7 +21,6 @@ import ( gevents "github.com/absmach/magistrala/internal/groups/events" gmiddleware "github.com/absmach/magistrala/internal/groups/middleware" gpostgres "github.com/absmach/magistrala/internal/groups/postgres" - gtracing "github.com/absmach/magistrala/internal/groups/tracing" mglog "github.com/absmach/magistrala/logger" authsvcAuthn "github.com/absmach/magistrala/pkg/authn/authsvc" mgauthz "github.com/absmach/magistrala/pkg/authz" @@ -47,7 +46,6 @@ import ( "github.com/absmach/magistrala/users/hasher" cmiddleware "github.com/absmach/magistrala/users/middleware" clientspg "github.com/absmach/magistrala/users/postgres" - ctracing "github.com/absmach/magistrala/users/tracing" "github.com/authzed/authzed-go/v1" "github.com/authzed/grpcutil" "github.com/caarlos0/env/v11" @@ -282,12 +280,12 @@ func newService(ctx context.Context, authz mgauthz.Authorization, token magistra csvc = cmiddleware.AuthorizationMiddleware(csvc, authz, c.SelfRegister) gsvc = gmiddleware.AuthorizationMiddleware(gsvc, authz) - csvc = ctracing.New(csvc, tracer) + csvc = cmiddleware.TracingMiddleware(csvc, tracer) csvc = cmiddleware.LoggingMiddleware(csvc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") csvc = cmiddleware.MetricsMiddleware(csvc, counter, latency) - gsvc = gtracing.New(gsvc, tracer) + gsvc = gmiddleware.TracingMiddleware(gsvc, tracer) gsvc = gmiddleware.LoggingMiddleware(gsvc, logger) counter, latency = prometheus.MakeMetrics("groups", "api") gsvc = gmiddleware.MetricsMiddleware(gsvc, counter, latency) diff --git a/cmd/ws/main.go b/cmd/ws/main.go index 0844332d37..686964ed33 100644 --- a/cmd/ws/main.go +++ b/cmd/ws/main.go @@ -26,7 +26,7 @@ import ( "github.com/absmach/magistrala/pkg/uuid" "github.com/absmach/magistrala/ws" "github.com/absmach/magistrala/ws/api" - "github.com/absmach/magistrala/ws/tracing" + "github.com/absmach/magistrala/ws/middleware" "github.com/absmach/mproxy/pkg/session" "github.com/absmach/mproxy/pkg/websockets" "github.com/caarlos0/env/v11" @@ -156,10 +156,10 @@ func main() { func newService(thingsClient magistrala.ThingsServiceClient, nps messaging.PubSub, logger *slog.Logger, tracer trace.Tracer) ws.Service { svc := ws.New(thingsClient, nps) - svc = tracing.New(tracer, svc) - svc = api.LoggingMiddleware(svc, logger) + svc = middleware.TracingMiddleware(tracer, svc) + svc = middleware.LoggingMiddleware(svc, logger) counter, latency := prometheus.MakeMetrics("ws_adapter", "api") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = middleware.MetricsMiddleware(svc, counter, latency) return svc } diff --git a/coap/middleware/doc.go b/coap/middleware/doc.go new file mode 100644 index 0000000000..419c357cbb --- /dev/null +++ b/coap/middleware/doc.go @@ -0,0 +1,9 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides tracing, logging and metrics middleware +// for Magistrala COAP service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. +package middleware diff --git a/coap/api/logging.go b/coap/middleware/logging.go similarity index 99% rename from coap/api/logging.go rename to coap/middleware/logging.go index 2f81f77f92..765e0a2f04 100644 --- a/coap/api/logging.go +++ b/coap/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/coap/api/metrics.go b/coap/middleware/metrics.go similarity index 98% rename from coap/api/metrics.go rename to coap/middleware/metrics.go index e6bca32927..74fc66acc7 100644 --- a/coap/api/metrics.go +++ b/coap/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/coap/tracing/adapter.go b/coap/middleware/tracing.go similarity index 88% rename from coap/tracing/adapter.go rename to coap/middleware/tracing.go index f2d3e92a4f..c1d33863c0 100644 --- a/coap/tracing/adapter.go +++ b/coap/middleware/tracing.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package tracing +package middleware import ( "context" @@ -27,8 +27,8 @@ type tracingServiceMiddleware struct { svc coap.Service } -// New creates a new instance of TracingServiceMiddleware that wraps an existing CoAP service with tracing capabilities. -func New(tracer trace.Tracer, svc coap.Service) coap.Service { +// TracingMiddleware creates a new instance of TracingServiceMiddleware that wraps an existing CoAP service with tracing capabilities. +func TracingMiddleware(tracer trace.Tracer, svc coap.Service) coap.Service { return &tracingServiceMiddleware{ tracer: tracer, svc: svc, diff --git a/coap/tracing/doc.go b/coap/tracing/doc.go deleted file mode 100644 index 2d65dbe4e1..0000000000 --- a/coap/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala WebSocket adapter service. -// -// This package provides tracing middleware for Magistrala WebSocket adapter service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala WebSocket adapter service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing diff --git a/consumers/notifiers/middleware/doc.go b/consumers/notifiers/middleware/doc.go new file mode 100644 index 0000000000..90f73cb03a --- /dev/null +++ b/consumers/notifiers/middleware/doc.go @@ -0,0 +1,9 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides tracing, logging and metrics middleware +// for Magistrala Notifiers service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. +package middleware diff --git a/consumers/notifiers/api/logging.go b/consumers/notifiers/middleware/logging.go similarity index 99% rename from consumers/notifiers/api/logging.go rename to consumers/notifiers/middleware/logging.go index e327d92265..3ea0a2e517 100644 --- a/consumers/notifiers/api/logging.go +++ b/consumers/notifiers/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/consumers/notifiers/api/metrics.go b/consumers/notifiers/middleware/metrics.go similarity index 99% rename from consumers/notifiers/api/metrics.go rename to consumers/notifiers/middleware/metrics.go index 209730288d..0dfa9ee520 100644 --- a/consumers/notifiers/api/metrics.go +++ b/consumers/notifiers/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/consumers/notifiers/tracing/subscriptions.go b/consumers/notifiers/middleware/subscriptions.go similarity index 99% rename from consumers/notifiers/tracing/subscriptions.go rename to consumers/notifiers/middleware/subscriptions.go index c8c2920123..0db7cf708b 100644 --- a/consumers/notifiers/tracing/subscriptions.go +++ b/consumers/notifiers/middleware/subscriptions.go @@ -3,7 +3,7 @@ // Package tracing contains middlewares that will add spans // to existing traces. -package tracing +package middleware import ( "context" diff --git a/consumers/notifiers/tracing/doc.go b/consumers/notifiers/tracing/doc.go deleted file mode 100644 index 2d65dbe4e1..0000000000 --- a/consumers/notifiers/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala WebSocket adapter service. -// -// This package provides tracing middleware for Magistrala WebSocket adapter service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala WebSocket adapter service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing diff --git a/internal/groups/middleware/doc.go b/internal/groups/middleware/doc.go index 2ffa0936ad..7e600044cd 100644 --- a/internal/groups/middleware/doc.go +++ b/internal/groups/middleware/doc.go @@ -1,5 +1,9 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -// Package middleware provides middleware for Magistrala Groups service. +// Package middleware provides authoprization, tracing, logging and metrics middleware +// for Magistrala Groups service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. package middleware diff --git a/internal/groups/tracing/tracing.go b/internal/groups/middleware/tracing.go similarity index 96% rename from internal/groups/tracing/tracing.go rename to internal/groups/middleware/tracing.go index 190188668f..2b4d4414a0 100644 --- a/internal/groups/tracing/tracing.go +++ b/internal/groups/middleware/tracing.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package tracing +package middleware import ( "context" @@ -19,8 +19,8 @@ type tracingMiddleware struct { gsvc groups.Service } -// New returns a new group service with tracing capabilities. -func New(gsvc groups.Service, tracer trace.Tracer) groups.Service { +// TracingMiddleware returns a new group service with tracing capabilities. +func TracingMiddleware(gsvc groups.Service, tracer trace.Tracer) groups.Service { return &tracingMiddleware{tracer, gsvc} } diff --git a/internal/groups/tracing/doc.go b/internal/groups/tracing/doc.go deleted file mode 100644 index 6a419f3b5c..0000000000 --- a/internal/groups/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala Users Groups service. -// -// This package provides tracing middleware for Magistrala Users Groups service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala Users Groups service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing diff --git a/invitations/middleware/doc.go b/invitations/middleware/doc.go index 1fdf252ff0..5449127402 100644 --- a/invitations/middleware/doc.go +++ b/invitations/middleware/doc.go @@ -1,9 +1,9 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -// Package middleware contains the middleware for the invitations service. -// It is responsible for the following: -// - Logging -// - Metrics -// - Tracing +// Package middleware provides authorization, tracing, logging and metrics middleware +// for Magistrala Invitations service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. package middleware diff --git a/journal/middleware/doc.go b/journal/middleware/doc.go index 71d2571337..4e9d9ea2c8 100644 --- a/journal/middleware/doc.go +++ b/journal/middleware/doc.go @@ -1,6 +1,9 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -// Package middleware provides middleware for the journal service. -// This is logging, metrics, and tracing middleware. +// Package middleware provides tracing, logging and metrics middleware +// for Magistrala Journal service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. package middleware diff --git a/provision/middleware/doc.go b/provision/middleware/doc.go new file mode 100644 index 0000000000..2e786b4c7b --- /dev/null +++ b/provision/middleware/doc.go @@ -0,0 +1,9 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides logging middleware for Magistrala +// Provision service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. +package middleware diff --git a/provision/api/logging.go b/provision/middleware/logging.go similarity index 99% rename from provision/api/logging.go rename to provision/middleware/logging.go index 4b2aca3d18..760882eda5 100644 --- a/provision/api/logging.go +++ b/provision/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "log/slog" diff --git a/readers/middleware/doc.go b/readers/middleware/doc.go new file mode 100644 index 0000000000..cd95d44a73 --- /dev/null +++ b/readers/middleware/doc.go @@ -0,0 +1,9 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides logging and metrics middleware +// for Magistrala Readers service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. +package middleware diff --git a/readers/api/logging.go b/readers/middleware/logging.go similarity index 98% rename from readers/api/logging.go rename to readers/middleware/logging.go index 49eedcbc09..ffce2d5a3c 100644 --- a/readers/api/logging.go +++ b/readers/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "log/slog" diff --git a/readers/api/metrics.go b/readers/middleware/metrics.go similarity index 98% rename from readers/api/metrics.go rename to readers/middleware/metrics.go index 026f3f4357..c885258972 100644 --- a/readers/api/metrics.go +++ b/readers/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "time" diff --git a/things/middleware/doc.go b/things/middleware/doc.go index 253c83585f..b5a5693a8d 100644 --- a/things/middleware/doc.go +++ b/things/middleware/doc.go @@ -1,5 +1,9 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -// Package middleware provides middleware for Magistrala Things service. +// Package middleware provides authorization, tracing, logging and metrics middleware +// for Magistrala Things service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. package middleware diff --git a/things/tracing/tracing.go b/things/middleware/tracing.go similarity index 97% rename from things/tracing/tracing.go rename to things/middleware/tracing.go index ae6e33e214..0fcab28019 100644 --- a/things/tracing/tracing.go +++ b/things/middleware/tracing.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package tracing +package middleware import ( "context" @@ -20,8 +20,8 @@ type tracingMiddleware struct { svc things.Service } -// New returns a new group service with tracing capabilities. -func New(svc things.Service, tracer trace.Tracer) things.Service { +// TracingMiddleware returns a new things service with tracing capabilities. +func TracingMiddleware(svc things.Service, tracer trace.Tracer) things.Service { return &tracingMiddleware{tracer, svc} } diff --git a/things/tracing/doc.go b/things/tracing/doc.go deleted file mode 100644 index 1d803beca5..0000000000 --- a/things/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala things clients service. -// -// This package provides tracing middleware for Magistrala things clients service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala things clients service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing diff --git a/users/middleware/doc.go b/users/middleware/doc.go index ce2aef4859..b2273580a6 100644 --- a/users/middleware/doc.go +++ b/users/middleware/doc.go @@ -1,5 +1,9 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -// Package middleware provides middleware for Magistrala Users service. +// Package middleware provides authorization, tracing, logging and metrics middleware +// for Magistrala Users service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. package middleware diff --git a/users/tracing/tracing.go b/users/middleware/tracing.go similarity index 98% rename from users/tracing/tracing.go rename to users/middleware/tracing.go index 81e63c9519..0039b46bd8 100644 --- a/users/tracing/tracing.go +++ b/users/middleware/tracing.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package tracing +package middleware import ( "context" @@ -21,8 +21,8 @@ type tracingMiddleware struct { svc users.Service } -// New returns a new group service with tracing capabilities. -func New(svc users.Service, tracer trace.Tracer) users.Service { +// TracingMiddleware returns a new users service with tracing capabilities. +func TracingMiddleware(svc users.Service, tracer trace.Tracer) users.Service { return &tracingMiddleware{tracer, svc} } diff --git a/users/tracing/doc.go b/users/tracing/doc.go deleted file mode 100644 index 5aa1b44b98..0000000000 --- a/users/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala Users service. -// -// This package provides tracing middleware for Magistrala Users service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala Users service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing diff --git a/ws/middleware/doc.go b/ws/middleware/doc.go new file mode 100644 index 0000000000..d7a661a265 --- /dev/null +++ b/ws/middleware/doc.go @@ -0,0 +1,9 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides logging, metrics and tracing middleware +// for Magistrala WebSockets service. +// +// For more details about tracing instrumentation for Magistrala messaging refer +// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. +package middleware diff --git a/ws/api/logging.go b/ws/middleware/logging.go similarity index 98% rename from ws/api/logging.go rename to ws/middleware/logging.go index 5c693a45e2..81b84c5502 100644 --- a/ws/api/logging.go +++ b/ws/middleware/logging.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package api +package middleware import ( "context" diff --git a/ws/api/metrics.go b/ws/middleware/metrics.go similarity index 98% rename from ws/api/metrics.go rename to ws/middleware/metrics.go index a1a8d59322..c099dd3755 100644 --- a/ws/api/metrics.go +++ b/ws/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" diff --git a/ws/tracing/tracing.go b/ws/middleware/tracing.go similarity index 82% rename from ws/tracing/tracing.go rename to ws/middleware/tracing.go index ed7e62c9ce..cf62a354e6 100644 --- a/ws/tracing/tracing.go +++ b/ws/middleware/tracing.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -package tracing +package middleware import ( "context" @@ -23,8 +23,8 @@ type tracingMiddleware struct { svc ws.Service } -// New returns a new websocket service with tracing capabilities. -func New(tracer trace.Tracer, svc ws.Service) ws.Service { +// TracingMiddleware returns a new websocket service with tracing capabilities. +func TracingMiddleware(tracer trace.Tracer, svc ws.Service) ws.Service { return &tracingMiddleware{ tracer: tracer, svc: svc, diff --git a/ws/tracing/doc.go b/ws/tracing/doc.go deleted file mode 100644 index 2d65dbe4e1..0000000000 --- a/ws/tracing/doc.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Abstract Machines -// SPDX-License-Identifier: Apache-2.0 - -// Package tracing provides tracing instrumentation for Magistrala WebSocket adapter service. -// -// This package provides tracing middleware for Magistrala WebSocket adapter service. -// It can be used to trace incoming requests and add tracing capabilities to -// Magistrala WebSocket adapter service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. -package tracing From 8128e0dc195693cf08d244aebb26184c960c04ac Mon Sep 17 00:00:00 2001 From: Felix Gateru Date: Tue, 22 Oct 2024 12:06:16 +0300 Subject: [PATCH 2/4] docs(middleware): update middleware godocs Signed-off-by: Felix Gateru --- certs/middleware/doc.go | 4 ++-- provision/middleware/doc.go | 3 --- readers/middleware/doc.go | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/certs/middleware/doc.go b/certs/middleware/doc.go index 0af8300b06..9b6bcb31a5 100644 --- a/certs/middleware/doc.go +++ b/certs/middleware/doc.go @@ -1,8 +1,8 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -// Package middleware provides tracing, logging and metrics middleware -// for Magistrala Auth service. +// Package middleware provides logging, metrics and tracing middleware +// for Magistrala Certs service. // // For more details about tracing instrumentation for Magistrala messaging refer // to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. diff --git a/provision/middleware/doc.go b/provision/middleware/doc.go index 2e786b4c7b..545025adc1 100644 --- a/provision/middleware/doc.go +++ b/provision/middleware/doc.go @@ -3,7 +3,4 @@ // Package middleware provides logging middleware for Magistrala // Provision service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. package middleware diff --git a/readers/middleware/doc.go b/readers/middleware/doc.go index cd95d44a73..590deb1c98 100644 --- a/readers/middleware/doc.go +++ b/readers/middleware/doc.go @@ -3,7 +3,4 @@ // Package middleware provides logging and metrics middleware // for Magistrala Readers service. -// -// For more details about tracing instrumentation for Magistrala messaging refer -// to the documentation at https://docs.magistrala.abstractmachines.fr/tracing/. package middleware From 61c9c587a5758306b415e8b94b9960ef154fa2ca Mon Sep 17 00:00:00 2001 From: Felix Gateru Date: Tue, 22 Oct 2024 13:12:09 +0300 Subject: [PATCH 3/4] docs(middleware): update middleware godocs Signed-off-by: Felix Gateru --- auth/middleware/doc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/middleware/doc.go b/auth/middleware/doc.go index 0af8300b06..7157981698 100644 --- a/auth/middleware/doc.go +++ b/auth/middleware/doc.go @@ -1,7 +1,7 @@ // Copyright (c) Abstract Machines // SPDX-License-Identifier: Apache-2.0 -// Package middleware provides tracing, logging and metrics middleware +// Package middleware provides logging metrics and tracing middleware // for Magistrala Auth service. // // For more details about tracing instrumentation for Magistrala messaging refer From 430d8c01993021915951047df8939912c1bb1216 Mon Sep 17 00:00:00 2001 From: Felix Gateru Date: Wed, 23 Oct 2024 15:03:29 +0300 Subject: [PATCH 4/4] refactor(middleware): rename to reduce stuttering Signed-off-by: Felix Gateru --- auth/middleware/logging.go | 4 ++-- auth/middleware/metrics.go | 4 ++-- auth/middleware/tracing.go | 4 ++-- bootstrap/middleware/authorization.go | 4 ++-- bootstrap/middleware/logging.go | 4 ++-- bootstrap/middleware/metrics.go | 4 ++-- bootstrap/middleware/tracing.go | 4 ++-- certs/middleware/logging.go | 4 ++-- certs/middleware/metrics.go | 4 ++-- certs/middleware/tracing.go | 4 ++-- cmd/auth/main.go | 6 +++--- cmd/bootstrap/main.go | 8 ++++---- cmd/certs/main.go | 6 +++--- cmd/coap/main.go | 6 +++--- cmd/invitations/main.go | 2 +- cmd/journal/main.go | 4 ++-- cmd/postgres-reader/main.go | 4 ++-- cmd/things/main.go | 16 ++++++++-------- cmd/timescale-reader/main.go | 4 ++-- cmd/users/main.go | 16 ++++++++-------- cmd/ws/main.go | 6 +++--- coap/middleware/logging.go | 4 ++-- coap/middleware/metrics.go | 4 ++-- coap/middleware/tracing.go | 4 ++-- consumers/notifiers/middleware/logging.go | 4 ++-- consumers/notifiers/middleware/metrics.go | 4 ++-- internal/groups/middleware/authorization.go | 4 ++-- internal/groups/middleware/logging.go | 4 ++-- internal/groups/middleware/metrics.go | 4 ++-- internal/groups/middleware/tracing.go | 4 ++-- invitations/middleware/authorization.go | 2 +- journal/middleware/logging.go | 4 ++-- journal/middleware/metrics.go | 5 ++--- readers/middleware/logging.go | 4 ++-- readers/middleware/metrics.go | 4 ++-- things/middleware/authorization.go | 4 ++-- things/middleware/logging.go | 2 +- things/middleware/metrics.go | 4 ++-- things/middleware/tracing.go | 4 ++-- users/middleware/authorization.go | 4 ++-- users/middleware/logging.go | 4 ++-- users/middleware/metrics.go | 4 ++-- users/middleware/tracing.go | 4 ++-- ws/middleware/logging.go | 4 ++-- ws/middleware/metrics.go | 4 ++-- ws/middleware/tracing.go | 4 ++-- 46 files changed, 107 insertions(+), 108 deletions(-) diff --git a/auth/middleware/logging.go b/auth/middleware/logging.go index f6133f4b50..d0497617ec 100644 --- a/auth/middleware/logging.go +++ b/auth/middleware/logging.go @@ -21,8 +21,8 @@ type loggingMiddleware struct { svc auth.Service } -// LoggingMiddleware adds logging facilities to the core service. -func LoggingMiddleware(svc auth.Service, logger *slog.Logger) auth.Service { +// Logging adds logging facilities to the core service. +func Logging(svc auth.Service, logger *slog.Logger) auth.Service { return &loggingMiddleware{logger, svc} } diff --git a/auth/middleware/metrics.go b/auth/middleware/metrics.go index 3f68dbe05e..27bfc693ba 100644 --- a/auth/middleware/metrics.go +++ b/auth/middleware/metrics.go @@ -22,8 +22,8 @@ type metricsMiddleware struct { svc auth.Service } -// MetricsMiddleware instruments core service by tracking request count and latency. -func MetricsMiddleware(svc auth.Service, counter metrics.Counter, latency metrics.Histogram) auth.Service { +// Metrics instruments core service by tracking request count and latency. +func Metrics(svc auth.Service, counter metrics.Counter, latency metrics.Histogram) auth.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/auth/middleware/tracing.go b/auth/middleware/tracing.go index e7ae39c72d..b3f939deff 100644 --- a/auth/middleware/tracing.go +++ b/auth/middleware/tracing.go @@ -20,8 +20,8 @@ type tracingMiddleware struct { svc auth.Service } -// TracingMiddleware returns a new auth service with tracing capabilities. -func TracingMiddleware(svc auth.Service, tracer trace.Tracer) auth.Service { +// Tracing returns a new auth service with tracing capabilities. +func Tracing(svc auth.Service, tracer trace.Tracer) auth.Service { return &tracingMiddleware{tracer, svc} } diff --git a/bootstrap/middleware/authorization.go b/bootstrap/middleware/authorization.go index cc14e55a1a..643222c6a6 100644 --- a/bootstrap/middleware/authorization.go +++ b/bootstrap/middleware/authorization.go @@ -20,8 +20,8 @@ type authorizationMiddleware struct { authz mgauthz.Authorization } -// AuthorizationMiddleware adds authorization to the clients service. -func AuthorizationMiddleware(svc bootstrap.Service, authz mgauthz.Authorization) bootstrap.Service { +// Authorization adds authorization to the clients service. +func Authorization(svc bootstrap.Service, authz mgauthz.Authorization) bootstrap.Service { return &authorizationMiddleware{ svc: svc, authz: authz, diff --git a/bootstrap/middleware/logging.go b/bootstrap/middleware/logging.go index 362920d84e..005dc39405 100644 --- a/bootstrap/middleware/logging.go +++ b/bootstrap/middleware/logging.go @@ -21,8 +21,8 @@ type loggingMiddleware struct { svc bootstrap.Service } -// LoggingMiddleware adds logging facilities to the bootstrap service. -func LoggingMiddleware(svc bootstrap.Service, logger *slog.Logger) bootstrap.Service { +// Logging adds logging facilities to the bootstrap service. +func Logging(svc bootstrap.Service, logger *slog.Logger) bootstrap.Service { return &loggingMiddleware{logger, svc} } diff --git a/bootstrap/middleware/metrics.go b/bootstrap/middleware/metrics.go index cd95e4e6c4..7c0f5fc8dc 100644 --- a/bootstrap/middleware/metrics.go +++ b/bootstrap/middleware/metrics.go @@ -22,8 +22,8 @@ type metricsMiddleware struct { svc bootstrap.Service } -// MetricsMiddleware instruments core service by tracking request count and latency. -func MetricsMiddleware(svc bootstrap.Service, counter metrics.Counter, latency metrics.Histogram) bootstrap.Service { +// Metrics instruments core service by tracking request count and latency. +func Metrics(svc bootstrap.Service, counter metrics.Counter, latency metrics.Histogram) bootstrap.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/bootstrap/middleware/tracing.go b/bootstrap/middleware/tracing.go index 63652ee455..0b47c66980 100644 --- a/bootstrap/middleware/tracing.go +++ b/bootstrap/middleware/tracing.go @@ -19,8 +19,8 @@ type tracingMiddleware struct { svc bootstrap.Service } -// TracingMiddleware returns a new bootstrap service with tracing capabilities. -func TracingMiddleware(svc bootstrap.Service, tracer trace.Tracer) bootstrap.Service { +// Tracing returns a new bootstrap service with tracing capabilities. +func Tracing(svc bootstrap.Service, tracer trace.Tracer) bootstrap.Service { return &tracingMiddleware{tracer, svc} } diff --git a/certs/middleware/logging.go b/certs/middleware/logging.go index 93805a4131..d5082a3060 100644 --- a/certs/middleware/logging.go +++ b/certs/middleware/logging.go @@ -20,8 +20,8 @@ type loggingMiddleware struct { svc certs.Service } -// LoggingMiddleware adds logging facilities to the bootstrap service. -func LoggingMiddleware(svc certs.Service, logger *slog.Logger) certs.Service { +// Logging adds logging facilities to the bootstrap service. +func Logging(svc certs.Service, logger *slog.Logger) certs.Service { return &loggingMiddleware{logger, svc} } diff --git a/certs/middleware/metrics.go b/certs/middleware/metrics.go index 122198a3b8..3f850a8d86 100644 --- a/certs/middleware/metrics.go +++ b/certs/middleware/metrics.go @@ -21,8 +21,8 @@ type metricsMiddleware struct { svc certs.Service } -// MetricsMiddleware instruments core service by tracking request count and latency. -func MetricsMiddleware(svc certs.Service, counter metrics.Counter, latency metrics.Histogram) certs.Service { +// Metrics instruments core service by tracking request count and latency. +func Metrics(svc certs.Service, counter metrics.Counter, latency metrics.Histogram) certs.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/certs/middleware/tracing.go b/certs/middleware/tracing.go index 247c330d36..016b372a53 100644 --- a/certs/middleware/tracing.go +++ b/certs/middleware/tracing.go @@ -18,8 +18,8 @@ type tracingMiddleware struct { svc certs.Service } -// TracingMiddleware returns a new certs service with tracing capabilities. -func TracingMiddleware(svc certs.Service, tracer trace.Tracer) certs.Service { +// Tracing returns a new certs service with tracing capabilities. +func Tracing(svc certs.Service, tracer trace.Tracer) certs.Service { return &tracingMiddleware{tracer, svc} } diff --git a/cmd/auth/main.go b/cmd/auth/main.go index f92b175ab8..05080a5f07 100644 --- a/cmd/auth/main.go +++ b/cmd/auth/main.go @@ -223,10 +223,10 @@ func newService(ctx context.Context, db *sqlx.DB, tracer trace.Tracer, cfg confi logger.Error(fmt.Sprintf("failed to init event store middleware : %s", err)) return nil } - svc = middleware.LoggingMiddleware(svc, logger) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("groups", "api") - svc = middleware.MetricsMiddleware(svc, counter, latency) - svc = middleware.TracingMiddleware(svc, tracer) + svc = middleware.Metrics(svc, counter, latency) + svc = middleware.Tracing(svc, tracer) return svc } diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index 4ea8653a0f..db7b437acc 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -217,12 +217,12 @@ func newService(ctx context.Context, authz mgauthz.Authorization, policySvc poli return nil, err } - svc = middleware.AuthorizationMiddleware(svc, authz) + svc = middleware.Authorization(svc, authz) svc = producer.NewEventStoreMiddleware(svc, publisher) - svc = middleware.LoggingMiddleware(svc, logger) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = middleware.MetricsMiddleware(svc, counter, latency) - svc = middleware.TracingMiddleware(svc, tracer) + svc = middleware.Metrics(svc, counter, latency) + svc = middleware.Tracing(svc, tracer) return svc, nil } diff --git a/cmd/certs/main.go b/cmd/certs/main.go index a3085ff47b..ce58eed351 100644 --- a/cmd/certs/main.go +++ b/cmd/certs/main.go @@ -159,10 +159,10 @@ func newService(tracer trace.Tracer, logger *slog.Logger, cfg config, pkiAgent p } sdk := mgsdk.NewSDK(config) svc := certs.New(sdk, pkiAgent) - svc = middleware.LoggingMiddleware(svc, logger) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = middleware.MetricsMiddleware(svc, counter, latency) - svc = middleware.TracingMiddleware(svc, tracer) + svc = middleware.Metrics(svc, counter, latency) + svc = middleware.Tracing(svc, tracer) return svc } diff --git a/cmd/coap/main.go b/cmd/coap/main.go index 0b765b43eb..868fbe2673 100644 --- a/cmd/coap/main.go +++ b/cmd/coap/main.go @@ -128,12 +128,12 @@ func main() { svc := coap.New(thingsClient, nps) - svc = middleware.TracingMiddleware(tracer, svc) + svc = middleware.Tracing(tracer, svc) - svc = middleware.LoggingMiddleware(svc, logger) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = middleware.MetricsMiddleware(svc, counter, latency) + svc = middleware.Metrics(svc, counter, latency) hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(cfg.InstanceID), logger) diff --git a/cmd/invitations/main.go b/cmd/invitations/main.go index 8f79da3915..07454dab92 100644 --- a/cmd/invitations/main.go +++ b/cmd/invitations/main.go @@ -186,7 +186,7 @@ func newService(db *sqlx.DB, dbConfig clientspg.Config, authz mgauthz.Authorizat sdk := mgsdk.NewSDK(config) svc := invitations.NewService(token, repo, sdk) - svc = middleware.AuthorizationMiddleware(authz, svc) + svc = middleware.Authorization(authz, svc) svc = middleware.Tracing(svc, tracer) svc = middleware.Logging(logger, svc) counter, latency := prometheus.MakeMetrics(svcName, "api") diff --git a/cmd/journal/main.go b/cmd/journal/main.go index 3df9c5cdaf..7c87d51631 100644 --- a/cmd/journal/main.go +++ b/cmd/journal/main.go @@ -184,9 +184,9 @@ func newService(db *sqlx.DB, dbConfig pgclient.Config, authn mgauthn.Authenticat idp := uuid.New() svc := journal.NewService(authn, authz, idp, repo) - svc = middleware.LoggingMiddleware(svc, logger) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("journal", "journal_writer") - svc = middleware.MetricsMiddleware(svc, counter, latency) + svc = middleware.Metrics(svc, counter, latency) svc = middleware.Tracing(svc, tracer) return svc diff --git a/cmd/postgres-reader/main.go b/cmd/postgres-reader/main.go index d8bb5f4bcb..b73552bd76 100644 --- a/cmd/postgres-reader/main.go +++ b/cmd/postgres-reader/main.go @@ -148,9 +148,9 @@ func main() { func newService(db *sqlx.DB, logger *slog.Logger) readers.MessageRepository { svc := postgres.New(db) - svc = middleware.LoggingMiddleware(svc, logger) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("postgres", "message_reader") - svc = middleware.MetricsMiddleware(svc, counter, latency) + svc = middleware.Metrics(svc, counter, latency) return svc } diff --git a/cmd/things/main.go b/cmd/things/main.go index a2c3ff7e0b..e5a1cc9bda 100644 --- a/cmd/things/main.go +++ b/cmd/things/main.go @@ -257,18 +257,18 @@ func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth return nil, nil, err } - csvc = tmiddleware.AuthorizationMiddleware(csvc, authz) - gsvc = gmiddleware.AuthorizationMiddleware(gsvc, authz) + csvc = tmiddleware.Authorization(csvc, authz) + gsvc = gmiddleware.Authorization(gsvc, authz) - csvc = tmiddleware.TracingMiddleware(csvc, tracer) - csvc = tmiddleware.LoggingMiddleware(csvc, logger) + csvc = tmiddleware.Tracing(csvc, tracer) + csvc = tmiddleware.Logging(csvc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - csvc = tmiddleware.MetricsMiddleware(csvc, counter, latency) + csvc = tmiddleware.Metrics(csvc, counter, latency) - gsvc = gmiddleware.TracingMiddleware(gsvc, tracer) - gsvc = gmiddleware.LoggingMiddleware(gsvc, logger) + gsvc = gmiddleware.Tracing(gsvc, tracer) + gsvc = gmiddleware.Logging(gsvc, logger) counter, latency = prometheus.MakeMetrics(fmt.Sprintf("%s_groups", svcName), "api") - gsvc = gmiddleware.MetricsMiddleware(gsvc, counter, latency) + gsvc = gmiddleware.Metrics(gsvc, counter, latency) return csvc, gsvc, err } diff --git a/cmd/timescale-reader/main.go b/cmd/timescale-reader/main.go index a9d6760826..a58cacafa1 100644 --- a/cmd/timescale-reader/main.go +++ b/cmd/timescale-reader/main.go @@ -146,9 +146,9 @@ func main() { func newService(db *sqlx.DB, logger *slog.Logger) readers.MessageRepository { svc := timescale.New(db) - svc = middleware.LoggingMiddleware(svc, logger) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("timescale", "message_reader") - svc = middleware.MetricsMiddleware(svc, counter, latency) + svc = middleware.Metrics(svc, counter, latency) return svc } diff --git a/cmd/users/main.go b/cmd/users/main.go index 6f118a4da3..482bf5d954 100644 --- a/cmd/users/main.go +++ b/cmd/users/main.go @@ -277,18 +277,18 @@ func newService(ctx context.Context, authz mgauthz.Authorization, token magistra return nil, nil, err } - csvc = cmiddleware.AuthorizationMiddleware(csvc, authz, c.SelfRegister) - gsvc = gmiddleware.AuthorizationMiddleware(gsvc, authz) + csvc = cmiddleware.Authorization(csvc, authz, c.SelfRegister) + gsvc = gmiddleware.Authorization(gsvc, authz) - csvc = cmiddleware.TracingMiddleware(csvc, tracer) - csvc = cmiddleware.LoggingMiddleware(csvc, logger) + csvc = cmiddleware.Tracing(csvc, tracer) + csvc = cmiddleware.Logging(csvc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - csvc = cmiddleware.MetricsMiddleware(csvc, counter, latency) + csvc = cmiddleware.Metrics(csvc, counter, latency) - gsvc = gmiddleware.TracingMiddleware(gsvc, tracer) - gsvc = gmiddleware.LoggingMiddleware(gsvc, logger) + gsvc = gmiddleware.Tracing(gsvc, tracer) + gsvc = gmiddleware.Logging(gsvc, logger) counter, latency = prometheus.MakeMetrics("groups", "api") - gsvc = gmiddleware.MetricsMiddleware(gsvc, counter, latency) + gsvc = gmiddleware.Metrics(gsvc, counter, latency) clientID, err := createAdmin(ctx, c, cRepo, hsr, csvc) if err != nil { diff --git a/cmd/ws/main.go b/cmd/ws/main.go index 686964ed33..3adbc4b966 100644 --- a/cmd/ws/main.go +++ b/cmd/ws/main.go @@ -156,10 +156,10 @@ func main() { func newService(thingsClient magistrala.ThingsServiceClient, nps messaging.PubSub, logger *slog.Logger, tracer trace.Tracer) ws.Service { svc := ws.New(thingsClient, nps) - svc = middleware.TracingMiddleware(tracer, svc) - svc = middleware.LoggingMiddleware(svc, logger) + svc = middleware.Tracing(tracer, svc) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("ws_adapter", "api") - svc = middleware.MetricsMiddleware(svc, counter, latency) + svc = middleware.Metrics(svc, counter, latency) return svc } diff --git a/coap/middleware/logging.go b/coap/middleware/logging.go index 765e0a2f04..f7d67cc768 100644 --- a/coap/middleware/logging.go +++ b/coap/middleware/logging.go @@ -21,8 +21,8 @@ type loggingMiddleware struct { svc coap.Service } -// LoggingMiddleware adds logging facilities to the adapter. -func LoggingMiddleware(svc coap.Service, logger *slog.Logger) coap.Service { +// Logging adds logging facilities to the adapter. +func Logging(svc coap.Service, logger *slog.Logger) coap.Service { return &loggingMiddleware{logger, svc} } diff --git a/coap/middleware/metrics.go b/coap/middleware/metrics.go index 74fc66acc7..1830e987a7 100644 --- a/coap/middleware/metrics.go +++ b/coap/middleware/metrics.go @@ -22,8 +22,8 @@ type metricsMiddleware struct { svc coap.Service } -// MetricsMiddleware instruments adapter by tracking request count and latency. -func MetricsMiddleware(svc coap.Service, counter metrics.Counter, latency metrics.Histogram) coap.Service { +// Metrics instruments adapter by tracking request count and latency. +func Metrics(svc coap.Service, counter metrics.Counter, latency metrics.Histogram) coap.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/coap/middleware/tracing.go b/coap/middleware/tracing.go index c1d33863c0..5ac61f6d1c 100644 --- a/coap/middleware/tracing.go +++ b/coap/middleware/tracing.go @@ -27,8 +27,8 @@ type tracingServiceMiddleware struct { svc coap.Service } -// TracingMiddleware creates a new instance of TracingServiceMiddleware that wraps an existing CoAP service with tracing capabilities. -func TracingMiddleware(tracer trace.Tracer, svc coap.Service) coap.Service { +// Tracing creates a new instance of TracingServiceMiddleware that wraps an existing CoAP service with tracing capabilities. +func Tracing(tracer trace.Tracer, svc coap.Service) coap.Service { return &tracingServiceMiddleware{ tracer: tracer, svc: svc, diff --git a/consumers/notifiers/middleware/logging.go b/consumers/notifiers/middleware/logging.go index 3ea0a2e517..9743880b22 100644 --- a/consumers/notifiers/middleware/logging.go +++ b/consumers/notifiers/middleware/logging.go @@ -20,8 +20,8 @@ type loggingMiddleware struct { svc notifiers.Service } -// LoggingMiddleware adds logging facilities to the core service. -func LoggingMiddleware(svc notifiers.Service, logger *slog.Logger) notifiers.Service { +// Logging adds logging facilities to the core service. +func Logging(svc notifiers.Service, logger *slog.Logger) notifiers.Service { return &loggingMiddleware{logger, svc} } diff --git a/consumers/notifiers/middleware/metrics.go b/consumers/notifiers/middleware/metrics.go index 0dfa9ee520..08c16be887 100644 --- a/consumers/notifiers/middleware/metrics.go +++ b/consumers/notifiers/middleware/metrics.go @@ -21,8 +21,8 @@ type metricsMiddleware struct { svc notifiers.Service } -// MetricsMiddleware instruments core service by tracking request count and latency. -func MetricsMiddleware(svc notifiers.Service, counter metrics.Counter, latency metrics.Histogram) notifiers.Service { +// Metrics instruments core service by tracking request count and latency. +func Metrics(svc notifiers.Service, counter metrics.Counter, latency metrics.Histogram) notifiers.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/internal/groups/middleware/authorization.go b/internal/groups/middleware/authorization.go index d6a2e0acff..cf5ec398be 100644 --- a/internal/groups/middleware/authorization.go +++ b/internal/groups/middleware/authorization.go @@ -21,8 +21,8 @@ type authorizationMiddleware struct { authz mgauthz.Authorization } -// AuthorizationMiddleware adds authorization to the clients service. -func AuthorizationMiddleware(svc groups.Service, authz mgauthz.Authorization) groups.Service { +// Authorization adds authorization to the clients service. +func Authorization(svc groups.Service, authz mgauthz.Authorization) groups.Service { return &authorizationMiddleware{ svc: svc, authz: authz, diff --git a/internal/groups/middleware/logging.go b/internal/groups/middleware/logging.go index 220f924d09..49a8b96582 100644 --- a/internal/groups/middleware/logging.go +++ b/internal/groups/middleware/logging.go @@ -19,8 +19,8 @@ type loggingMiddleware struct { svc groups.Service } -// LoggingMiddleware adds logging facilities to the groups service. -func LoggingMiddleware(svc groups.Service, logger *slog.Logger) groups.Service { +// Logging adds logging facilities to the groups service. +func Logging(svc groups.Service, logger *slog.Logger) groups.Service { return &loggingMiddleware{logger, svc} } diff --git a/internal/groups/middleware/metrics.go b/internal/groups/middleware/metrics.go index 7d6fa13f7f..999b5f76b3 100644 --- a/internal/groups/middleware/metrics.go +++ b/internal/groups/middleware/metrics.go @@ -20,8 +20,8 @@ type metricsMiddleware struct { svc groups.Service } -// MetricsMiddleware instruments policies service by tracking request count and latency. -func MetricsMiddleware(svc groups.Service, counter metrics.Counter, latency metrics.Histogram) groups.Service { +// Metrics instruments policies service by tracking request count and latency. +func Metrics(svc groups.Service, counter metrics.Counter, latency metrics.Histogram) groups.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/internal/groups/middleware/tracing.go b/internal/groups/middleware/tracing.go index 2b4d4414a0..52182047d7 100644 --- a/internal/groups/middleware/tracing.go +++ b/internal/groups/middleware/tracing.go @@ -19,8 +19,8 @@ type tracingMiddleware struct { gsvc groups.Service } -// TracingMiddleware returns a new group service with tracing capabilities. -func TracingMiddleware(gsvc groups.Service, tracer trace.Tracer) groups.Service { +// Tracing returns a new group service with tracing capabilities. +func Tracing(gsvc groups.Service, tracer trace.Tracer) groups.Service { return &tracingMiddleware{tracer, gsvc} } diff --git a/invitations/middleware/authorization.go b/invitations/middleware/authorization.go index 73ecf3e1f4..d542929bd9 100644 --- a/invitations/middleware/authorization.go +++ b/invitations/middleware/authorization.go @@ -25,7 +25,7 @@ type authorizationMiddleware struct { svc invitations.Service } -func AuthorizationMiddleware(authz authz.Authorization, svc invitations.Service) invitations.Service { +func Authorization(authz authz.Authorization, svc invitations.Service) invitations.Service { return &authorizationMiddleware{authz, svc} } diff --git a/journal/middleware/logging.go b/journal/middleware/logging.go index 5ab991a672..b5f4859f2f 100644 --- a/journal/middleware/logging.go +++ b/journal/middleware/logging.go @@ -18,8 +18,8 @@ type loggingMiddleware struct { service journal.Service } -// LoggingMiddleware adds logging facilities to the adapter. -func LoggingMiddleware(service journal.Service, logger *slog.Logger) journal.Service { +// Logging adds logging facilities to the adapter. +func Logging(service journal.Service, logger *slog.Logger) journal.Service { return &loggingMiddleware{ logger: logger, service: service, diff --git a/journal/middleware/metrics.go b/journal/middleware/metrics.go index fdd098d9d3..ea0c0a8eb8 100644 --- a/journal/middleware/metrics.go +++ b/journal/middleware/metrics.go @@ -19,9 +19,8 @@ type metricsMiddleware struct { service journal.Service } -// MetricsMiddleware returns new message repository -// with Save method wrapped to expose metrics. -func MetricsMiddleware(service journal.Service, counter metrics.Counter, latency metrics.Histogram) journal.Service { +// Metrics returns new message repository with Save method wrapped to expose metrics. +func Metrics(service journal.Service, counter metrics.Counter, latency metrics.Histogram) journal.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/readers/middleware/logging.go b/readers/middleware/logging.go index ffce2d5a3c..e9787f7392 100644 --- a/readers/middleware/logging.go +++ b/readers/middleware/logging.go @@ -19,8 +19,8 @@ type loggingMiddleware struct { svc readers.MessageRepository } -// LoggingMiddleware adds logging facilities to the core service. -func LoggingMiddleware(svc readers.MessageRepository, logger *slog.Logger) readers.MessageRepository { +// Logging adds logging facilities to the core service. +func Logging(svc readers.MessageRepository, logger *slog.Logger) readers.MessageRepository { return &loggingMiddleware{ logger: logger, svc: svc, diff --git a/readers/middleware/metrics.go b/readers/middleware/metrics.go index c885258972..485450d73d 100644 --- a/readers/middleware/metrics.go +++ b/readers/middleware/metrics.go @@ -20,8 +20,8 @@ type metricsMiddleware struct { svc readers.MessageRepository } -// MetricsMiddleware instruments core service by tracking request count and latency. -func MetricsMiddleware(svc readers.MessageRepository, counter metrics.Counter, latency metrics.Histogram) readers.MessageRepository { +// Metrics instruments core service by tracking request count and latency. +func Metrics(svc readers.MessageRepository, counter metrics.Counter, latency metrics.Histogram) readers.MessageRepository { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/things/middleware/authorization.go b/things/middleware/authorization.go index 034c195d44..ef060d8b65 100644 --- a/things/middleware/authorization.go +++ b/things/middleware/authorization.go @@ -21,8 +21,8 @@ type authorizationMiddleware struct { authz mgauthz.Authorization } -// AuthorizationMiddleware adds authorization to the clients service. -func AuthorizationMiddleware(svc things.Service, authz mgauthz.Authorization) things.Service { +// Authorization adds authorization to the clients service. +func Authorization(svc things.Service, authz mgauthz.Authorization) things.Service { return &authorizationMiddleware{ svc: svc, authz: authz, diff --git a/things/middleware/logging.go b/things/middleware/logging.go index f388965354..b8c73ec88e 100644 --- a/things/middleware/logging.go +++ b/things/middleware/logging.go @@ -21,7 +21,7 @@ type loggingMiddleware struct { svc things.Service } -func LoggingMiddleware(svc things.Service, logger *slog.Logger) things.Service { +func Logging(svc things.Service, logger *slog.Logger) things.Service { return &loggingMiddleware{logger, svc} } diff --git a/things/middleware/metrics.go b/things/middleware/metrics.go index baf7c69a79..758f305a2e 100644 --- a/things/middleware/metrics.go +++ b/things/middleware/metrics.go @@ -21,8 +21,8 @@ type metricsMiddleware struct { svc things.Service } -// MetricsMiddleware returns a new metrics middleware wrapper. -func MetricsMiddleware(svc things.Service, counter metrics.Counter, latency metrics.Histogram) things.Service { +// Metrics returns a new metrics middleware wrapper. +func Metrics(svc things.Service, counter metrics.Counter, latency metrics.Histogram) things.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/things/middleware/tracing.go b/things/middleware/tracing.go index 0fcab28019..feb1d86496 100644 --- a/things/middleware/tracing.go +++ b/things/middleware/tracing.go @@ -20,8 +20,8 @@ type tracingMiddleware struct { svc things.Service } -// TracingMiddleware returns a new things service with tracing capabilities. -func TracingMiddleware(svc things.Service, tracer trace.Tracer) things.Service { +// Tracing returns a new things service with tracing capabilities. +func Tracing(svc things.Service, tracer trace.Tracer) things.Service { return &tracingMiddleware{tracer, svc} } diff --git a/users/middleware/authorization.go b/users/middleware/authorization.go index edb78d6539..d7e3a5a5a4 100644 --- a/users/middleware/authorization.go +++ b/users/middleware/authorization.go @@ -25,8 +25,8 @@ type authorizationMiddleware struct { selfRegister bool } -// AuthorizationMiddleware adds authorization to the clients service. -func AuthorizationMiddleware(svc users.Service, authz mgauthz.Authorization, selfRegister bool) users.Service { +// Authorization adds authorization to the clients service. +func Authorization(svc users.Service, authz mgauthz.Authorization, selfRegister bool) users.Service { return &authorizationMiddleware{ svc: svc, authz: authz, diff --git a/users/middleware/logging.go b/users/middleware/logging.go index 73bbed51ee..2c4e586541 100644 --- a/users/middleware/logging.go +++ b/users/middleware/logging.go @@ -21,8 +21,8 @@ type loggingMiddleware struct { svc users.Service } -// LoggingMiddleware adds logging facilities to the clients service. -func LoggingMiddleware(svc users.Service, logger *slog.Logger) users.Service { +// Logging adds logging facilities to the clients service. +func Logging(svc users.Service, logger *slog.Logger) users.Service { return &loggingMiddleware{logger, svc} } diff --git a/users/middleware/metrics.go b/users/middleware/metrics.go index 17e27f4b5a..280c60d63c 100644 --- a/users/middleware/metrics.go +++ b/users/middleware/metrics.go @@ -22,8 +22,8 @@ type metricsMiddleware struct { svc users.Service } -// MetricsMiddleware instruments policies service by tracking request count and latency. -func MetricsMiddleware(svc users.Service, counter metrics.Counter, latency metrics.Histogram) users.Service { +// Metrics instruments policies service by tracking request count and latency. +func Metrics(svc users.Service, counter metrics.Counter, latency metrics.Histogram) users.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/users/middleware/tracing.go b/users/middleware/tracing.go index 0039b46bd8..363a1f98f0 100644 --- a/users/middleware/tracing.go +++ b/users/middleware/tracing.go @@ -21,8 +21,8 @@ type tracingMiddleware struct { svc users.Service } -// TracingMiddleware returns a new users service with tracing capabilities. -func TracingMiddleware(svc users.Service, tracer trace.Tracer) users.Service { +// Tracing returns a new users service with tracing capabilities. +func Tracing(svc users.Service, tracer trace.Tracer) users.Service { return &tracingMiddleware{tracer, svc} } diff --git a/ws/middleware/logging.go b/ws/middleware/logging.go index 81b84c5502..54ee3e9113 100644 --- a/ws/middleware/logging.go +++ b/ws/middleware/logging.go @@ -18,8 +18,8 @@ type loggingMiddleware struct { svc ws.Service } -// LoggingMiddleware adds logging facilities to the websocket service. -func LoggingMiddleware(svc ws.Service, logger *slog.Logger) ws.Service { +// Logging adds logging facilities to the websocket service. +func Logging(svc ws.Service, logger *slog.Logger) ws.Service { return &loggingMiddleware{logger, svc} } diff --git a/ws/middleware/metrics.go b/ws/middleware/metrics.go index c099dd3755..7d26011c44 100644 --- a/ws/middleware/metrics.go +++ b/ws/middleware/metrics.go @@ -21,8 +21,8 @@ type metricsMiddleware struct { svc ws.Service } -// MetricsMiddleware instruments adapter by tracking request count and latency. -func MetricsMiddleware(svc ws.Service, counter metrics.Counter, latency metrics.Histogram) ws.Service { +// Metrics instruments adapter by tracking request count and latency. +func Metrics(svc ws.Service, counter metrics.Counter, latency metrics.Histogram) ws.Service { return &metricsMiddleware{ counter: counter, latency: latency, diff --git a/ws/middleware/tracing.go b/ws/middleware/tracing.go index cf62a354e6..634f9007d2 100644 --- a/ws/middleware/tracing.go +++ b/ws/middleware/tracing.go @@ -23,8 +23,8 @@ type tracingMiddleware struct { svc ws.Service } -// TracingMiddleware returns a new websocket service with tracing capabilities. -func TracingMiddleware(tracer trace.Tracer, svc ws.Service) ws.Service { +// Tracing returns a new websocket service with tracing capabilities. +func Tracing(tracer trace.Tracer, svc ws.Service) ws.Service { return &tracingMiddleware{ tracer: tracer, svc: svc,