mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-24 13:48:49 +08:00

* NOISSUE - Fix Bugs (#20) * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add Connect Disconnect endpoints (#23) * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: Things share with users (#25) * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> * add: things share with other users Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: Listing of things, channels, groups, users (#26) * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: List of user groups & removed repeating code in groups (#29) * removed repeating code in list groups Signed-off-by: Arvindh <arvindh91@gmail.com> * add: list of user group Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: otel handler operator name for endpoints Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * add: listing of shared things and users Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: listing of shared things and users Signed-off-by: Arvindh <arvindh91@gmail.com> * add: new SDK Signed-off-by: Arvindh <arvindh91@gmail.com> * add: new SDK Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: comment Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: sdk function names Signed-off-by: Arvindh <arvindh91@gmail.com> * update: api spec Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: channels connect request Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: listing of clients and groups Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: CLI Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: array len comparision Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: nginx Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
140 lines
6.0 KiB
Go
140 lines
6.0 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package tracing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
mfclients "github.com/mainflux/mainflux/pkg/clients"
|
|
"github.com/mainflux/mainflux/things"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
var _ things.Service = (*tracingMiddleware)(nil)
|
|
|
|
type tracingMiddleware struct {
|
|
tracer trace.Tracer
|
|
svc things.Service
|
|
}
|
|
|
|
// New returns a new group service with tracing capabilities.
|
|
func New(svc things.Service, tracer trace.Tracer) things.Service {
|
|
return &tracingMiddleware{tracer, svc}
|
|
}
|
|
|
|
// CreateThings traces the "CreateThings" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) CreateThings(ctx context.Context, token string, clis ...mfclients.Client) ([]mfclients.Client, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_create_client")
|
|
defer span.End()
|
|
|
|
return tm.svc.CreateThings(ctx, token, clis...)
|
|
}
|
|
|
|
// ViewClient traces the "ViewClient" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) ViewClient(ctx context.Context, token string, id string) (mfclients.Client, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_view_client", trace.WithAttributes(attribute.String("id", id)))
|
|
defer span.End()
|
|
return tm.svc.ViewClient(ctx, token, id)
|
|
}
|
|
|
|
// ListClients traces the "ListClients" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) ListClients(ctx context.Context, token string, reqUserID string, pm mfclients.Page) (mfclients.ClientsPage, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_list_clients")
|
|
defer span.End()
|
|
return tm.svc.ListClients(ctx, token, reqUserID, pm)
|
|
}
|
|
|
|
// UpdateClient traces the "UpdateClient" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) UpdateClient(ctx context.Context, token string, cli mfclients.Client) (mfclients.Client, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_update_client_name_and_metadata", trace.WithAttributes(attribute.String("id", cli.ID)))
|
|
defer span.End()
|
|
|
|
return tm.svc.UpdateClient(ctx, token, cli)
|
|
}
|
|
|
|
// UpdateClientTags traces the "UpdateClientTags" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) UpdateClientTags(ctx context.Context, token string, cli mfclients.Client) (mfclients.Client, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_update_client_tags", trace.WithAttributes(
|
|
attribute.String("id", cli.ID),
|
|
attribute.StringSlice("tags", cli.Tags),
|
|
))
|
|
defer span.End()
|
|
|
|
return tm.svc.UpdateClientTags(ctx, token, cli)
|
|
}
|
|
|
|
// UpdateClientSecret traces the "UpdateClientSecret" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) UpdateClientSecret(ctx context.Context, token, oldSecret, newSecret string) (mfclients.Client, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_update_client_secret")
|
|
defer span.End()
|
|
|
|
return tm.svc.UpdateClientSecret(ctx, token, oldSecret, newSecret)
|
|
}
|
|
|
|
// UpdateClientOwner traces the "UpdateClientOwner" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) UpdateClientOwner(ctx context.Context, token string, cli mfclients.Client) (mfclients.Client, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_update_client_owner", trace.WithAttributes(
|
|
attribute.String("id", cli.ID),
|
|
attribute.String("owner", cli.Owner),
|
|
))
|
|
defer span.End()
|
|
|
|
return tm.svc.UpdateClientOwner(ctx, token, cli)
|
|
}
|
|
|
|
// EnableClient traces the "EnableClient" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) EnableClient(ctx context.Context, token, id string) (mfclients.Client, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_enable_client", trace.WithAttributes(attribute.String("id", id)))
|
|
defer span.End()
|
|
|
|
return tm.svc.EnableClient(ctx, token, id)
|
|
}
|
|
|
|
// DisableClient traces the "DisableClient" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) DisableClient(ctx context.Context, token, id string) (mfclients.Client, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_disable_client", trace.WithAttributes(attribute.String("id", id)))
|
|
defer span.End()
|
|
|
|
return tm.svc.DisableClient(ctx, token, id)
|
|
}
|
|
|
|
// ListClientsByGroup traces the "ListClientsByGroup" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) ListClientsByGroup(ctx context.Context, token, groupID string, pm mfclients.Page) (mfclients.MembersPage, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_list_things_by_channel", trace.WithAttributes(attribute.String("groupID", groupID)))
|
|
defer span.End()
|
|
|
|
return tm.svc.ListClientsByGroup(ctx, token, groupID, pm)
|
|
}
|
|
|
|
// ListMemberships traces the "ListMemberships" operation of the wrapped policies.Service.
|
|
func (tm *tracingMiddleware) Identify(ctx context.Context, key string) (string, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "svc_identify", trace.WithAttributes(attribute.String("key", key)))
|
|
defer span.End()
|
|
|
|
return tm.svc.Identify(ctx, key)
|
|
}
|
|
|
|
func (tm *tracingMiddleware) Authorize(ctx context.Context, req *mainflux.AuthorizeReq) (string, error) {
|
|
ctx, span := tm.tracer.Start(ctx, "connect", trace.WithAttributes(attribute.String("subject", req.Subject), attribute.String("object", req.Object)))
|
|
defer span.End()
|
|
|
|
return tm.svc.Authorize(ctx, req)
|
|
}
|
|
|
|
// Share traces the "Share" operation of the wrapped things.Service.
|
|
func (tm *tracingMiddleware) Share(ctx context.Context, token, id string, relation string, userids ...string) error {
|
|
ctx, span := tm.tracer.Start(ctx, "share", trace.WithAttributes(attribute.String("id", id), attribute.String("relation", relation), attribute.StringSlice("user_ids", userids)))
|
|
defer span.End()
|
|
return tm.svc.Share(ctx, token, id, relation, userids...)
|
|
}
|
|
|
|
// Unshare traces the "Unshare" operation of the wrapped things.Service.
|
|
func (tm *tracingMiddleware) Unshare(ctx context.Context, token, id string, relation string, userids ...string) error {
|
|
ctx, span := tm.tracer.Start(ctx, "unshare", trace.WithAttributes(attribute.String("id", id), attribute.String("relation", relation), attribute.StringSlice("user_ids", userids)))
|
|
defer span.End()
|
|
return tm.svc.Unshare(ctx, token, id, relation, userids...)
|
|
}
|