diff --git a/auth/middleware/doc.go b/auth/middleware/doc.go new file mode 100644 index 0000000000..7157981698 --- /dev/null +++ b/auth/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 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 98% rename from auth/api/logging.go rename to auth/middleware/logging.go index 30182bb4c4..d0497617ec 100644 --- a/auth/api/logging.go +++ b/auth/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" @@ -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/api/metrics.go b/auth/middleware/metrics.go similarity index 96% rename from auth/api/metrics.go rename to auth/middleware/metrics.go index 1e2befa8d2..27bfc693ba 100644 --- a/auth/api/metrics.go +++ b/auth/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" @@ -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/tracing/tracing.go b/auth/middleware/tracing.go similarity index 97% rename from auth/tracing/tracing.go rename to auth/middleware/tracing.go index 97b5f1790f..b3f939deff 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 { +// 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/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/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/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/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/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..0b47c66980 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 { +// 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/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..9b6bcb31a5 --- /dev/null +++ b/certs/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 Certs 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 96% rename from certs/api/logging.go rename to certs/middleware/logging.go index 86a113f625..d5082a3060 100644 --- a/certs/api/logging.go +++ b/certs/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" @@ -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/api/metrics.go b/certs/middleware/metrics.go similarity index 92% rename from certs/api/metrics.go rename to certs/middleware/metrics.go index fee094753a..3f850a8d86 100644 --- a/certs/api/metrics.go +++ b/certs/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" @@ -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/tracing/tracing.go b/certs/middleware/tracing.go similarity index 94% rename from certs/tracing/tracing.go rename to certs/middleware/tracing.go index cf8604a89b..016b372a53 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 { +// 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/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..05080a5f07 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.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("groups", "api") - svc = api.MetricsMiddleware(svc, counter, latency) - svc = tracing.New(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 cfe998b41e..db7b437acc 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" @@ -218,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 = tracing.New(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 00c7ac3242..ce58eed351 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.Logging(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = api.MetricsMiddleware(svc, counter, latency) - svc = tracing.New(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 ad16e992c1..868fbe2673 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.Tracing(tracer, svc) - svc = api.LoggingMiddleware(svc, logger) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics(svcName, "api") - svc = api.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 d07f40a2af..b73552bd76 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.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("postgres", "message_reader") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = middleware.Metrics(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..e5a1cc9bda 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" @@ -259,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 = ctracing.New(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 = gtracing.New(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 ba6dde416a..a58cacafa1 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.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("timescale", "message_reader") - svc = api.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 2c8a53e080..482bf5d954 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" @@ -279,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 = ctracing.New(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 = gtracing.New(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 0844332d37..3adbc4b966 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.Tracing(tracer, svc) + svc = middleware.Logging(svc, logger) counter, latency := prometheus.MakeMetrics("ws_adapter", "api") - svc = api.MetricsMiddleware(svc, counter, latency) + svc = middleware.Metrics(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 94% rename from coap/api/logging.go rename to coap/middleware/logging.go index 2f81f77f92..f7d67cc768 100644 --- a/coap/api/logging.go +++ b/coap/middleware/logging.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" @@ -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/api/metrics.go b/coap/middleware/metrics.go similarity index 89% rename from coap/api/metrics.go rename to coap/middleware/metrics.go index e6bca32927..1830e987a7 100644 --- a/coap/api/metrics.go +++ b/coap/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" @@ -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/tracing/adapter.go b/coap/middleware/tracing.go similarity index 89% rename from coap/tracing/adapter.go rename to coap/middleware/tracing.go index f2d3e92a4f..5ac61f6d1c 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 { +// 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/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 96% rename from consumers/notifiers/api/logging.go rename to consumers/notifiers/middleware/logging.go index e327d92265..9743880b22 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" @@ -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/api/metrics.go b/consumers/notifiers/middleware/metrics.go similarity index 92% rename from consumers/notifiers/api/metrics.go rename to consumers/notifiers/middleware/metrics.go index 209730288d..08c16be887 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" @@ -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/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/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/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/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/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..52182047d7 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 { +// 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/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/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/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/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/provision/middleware/doc.go b/provision/middleware/doc.go new file mode 100644 index 0000000000..545025adc1 --- /dev/null +++ b/provision/middleware/doc.go @@ -0,0 +1,6 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides logging middleware for Magistrala +// Provision service. +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..590deb1c98 --- /dev/null +++ b/readers/middleware/doc.go @@ -0,0 +1,6 @@ +// Copyright (c) Abstract Machines +// SPDX-License-Identifier: Apache-2.0 + +// Package middleware provides logging and metrics middleware +// for Magistrala Readers service. +package middleware diff --git a/readers/api/logging.go b/readers/middleware/logging.go similarity index 87% rename from readers/api/logging.go rename to readers/middleware/logging.go index 49eedcbc09..e9787f7392 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" @@ -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/api/metrics.go b/readers/middleware/metrics.go similarity index 77% rename from readers/api/metrics.go rename to readers/middleware/metrics.go index 026f3f4357..485450d73d 100644 --- a/readers/api/metrics.go +++ b/readers/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "time" @@ -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/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/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/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..feb1d86496 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 { +// 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/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/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/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/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/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..363a1f98f0 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 { +// 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/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 87% rename from ws/api/logging.go rename to ws/middleware/logging.go index 5c693a45e2..54ee3e9113 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" @@ -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/api/metrics.go b/ws/middleware/metrics.go similarity index 81% rename from ws/api/metrics.go rename to ws/middleware/metrics.go index a1a8d59322..7d26011c44 100644 --- a/ws/api/metrics.go +++ b/ws/middleware/metrics.go @@ -3,7 +3,7 @@ //go:build !test -package api +package middleware import ( "context" @@ -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/tracing/tracing.go b/ws/middleware/tracing.go similarity index 83% rename from ws/tracing/tracing.go rename to ws/middleware/tracing.go index ed7e62c9ce..634f9007d2 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 { +// 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, 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