Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
tracing: rebase and instrument mailer with OTel
Browse files Browse the repository at this point in the history
  • Loading branch information
vascoguita committed Oct 10, 2022
1 parent 35e6f41 commit 3ae4274
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
10 changes: 9 additions & 1 deletion internal/http/services/mailer/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ import (
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/rhttp/global"
"github.com/cs3org/reva/pkg/sharedconf"
"github.com/cs3org/reva/pkg/tracing"
"github.com/mitchellh/mapstructure"
"github.com/rs/zerolog"
)

const serviceName = "mailer"
const tracerName = "mailer"

func init() {
global.Register("mailer", New)
}
Expand All @@ -62,6 +66,7 @@ type config struct {
}

type svc struct {
tracing.HttpMiddleware
conf *config
client gateway.GatewayAPIClient
tplBody *template.Template
Expand All @@ -70,14 +75,17 @@ type svc struct {

// New creates a new mailer service
func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) {
ctx, span := tracing.SpanStart(context.Background(), serviceName, tracerName, "New")
defer span.End()

conf := &config{}
if err := mapstructure.Decode(m, conf); err != nil {
return nil, err
}

conf.init()

client, err := pool.GetGatewayServiceClient(pool.Endpoint(conf.GatewaySVC))
client, err := pool.GetGatewayServiceClient(ctx, pool.Endpoint(conf.GatewaySVC))
if err != nil {
return nil, err
}
Expand Down
30 changes: 2 additions & 28 deletions pkg/auth/manager/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (am *mgr) getOIDCProvider(ctx context.Context) (*oidc.Provider, error) {
func (am *mgr) resolveUser(ctx context.Context, claims map[string]interface{}) error {
ctx, span := tracing.SpanStartFromContext(ctx, tracerName, "resolveUser")
defer span.End()

var (
claim string
value string
Expand Down Expand Up @@ -355,44 +355,18 @@ func (am *mgr) resolveUser(ctx context.Context, claims map[string]interface{}) e
for _, m := range intersection {
value = am.oidcUsersMapping[m.(string)].Username
}
<<<<<<< HEAD
resolve = true
} else if uid == 0 || gid == 0 {
claim = "mail"
value = claims["email"].(string)
resolve = true
=======

upsc, err := pool.GetUserProviderServiceClient(ctx, pool.Endpoint(am.c.GatewaySvc))
if err != nil {
return errors.Wrap(err, "error getting user provider grpc client")
}
getUserByClaimResp, err := upsc.GetUserByClaim(ctx, &user.GetUserByClaimRequest{
Claim: "username",
Value: username,
})
if err != nil {
return errors.Wrapf(err, "error getting user by username '%v'", username)
}
if getUserByClaimResp.Status.Code != rpc.Code_CODE_OK {
return status.NewErrorFromCode(getUserByClaimResp.Status.Code, "oidc")
}

// take the properties of the mapped target user to override the claims
claims["preferred_username"] = username
claims[am.c.IDClaim] = getUserByClaimResp.GetUser().GetId().OpaqueId
claims["iss"] = getUserByClaimResp.GetUser().GetId().Idp
claims[am.c.UIDClaim] = getUserByClaimResp.GetUser().UidNumber
claims[am.c.GIDClaim] = getUserByClaimResp.GetUser().GidNumber
appctx.GetLogger(ctx).Debug().Str("username", username).Interface("claims", claims).Msg("resolveUser: claims overridden from mapped user")
>>>>>>> dc7bec30 (tracing: instrument GRPC clients and the share, storage, utils, cbox and auth packages)
}

if !resolve {
return nil
}

upsc, err := pool.GetGatewayServiceClient(pool.Endpoint(am.c.GatewaySvc))
upsc, err := pool.GetGatewayServiceClient(ctx, pool.Endpoint(am.c.GatewaySvc))
if err != nil {
return errors.Wrap(err, "error getting user provider grpc client")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cbox/publicshare/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (m *manager) isProjectAdmin(ctx context.Context, u *user.User) bool {
func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters []*link.ListPublicSharesRequest_Filter, md *provider.ResourceInfo, sign bool) ([]*link.PublicShare, error) {
ctx, span := tracing.SpanStartFromContext(ctx, tracerName, "ListPublicShares")
defer span.End()

query := "select coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with, coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, coalesce(item_type, '') as item_type, coalesce(token,'') as token, coalesce(expiration, '') as expiration, coalesce(share_name, '') as share_name, id, stime, permissions, quicklink, description FROM oc_share WHERE (orphan = 0 or orphan IS NULL) AND (share_type=?) AND internal=false"
var resourceFilters, ownerFilters, creatorFilters string
var resourceParams, ownerParams, creatorParams []interface{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cbox/share/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (m *mgr) GetShare(ctx context.Context, ref *collaboration.ShareReference) (
func (m *mgr) Unshare(ctx context.Context, ref *collaboration.ShareReference) error {
ctx, span := tracing.SpanStartFromContext(ctx, tracerName, "Unshare")
defer span.End()

var query string
params := []interface{}{}
switch {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ func encodeLock(l *provider.Lock) (string, error) {
func (fs *eosfs) RefreshLock(ctx context.Context, ref *provider.Reference, newLock *provider.Lock, existingLockID string) error {
ctx, span := tracing.SpanStartFromContext(ctx, tracerName, "RefreshLock")
defer span.End()

if newLock.Type == provider.LockType_LOCK_TYPE_SHARED {
return errtypes.NotSupported("shared lock not yet implemented")
}
Expand Down

0 comments on commit 3ae4274

Please sign in to comment.