mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 15:49:35 +00:00
logging for showcase
This commit is contained in:
@@ -2,6 +2,7 @@ package cached
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/repository"
|
||||
"github.com/zitadel/zitadel/backend/storage/cache"
|
||||
@@ -16,15 +17,18 @@ func NewInstance(c cache.Cache[repository.InstanceIndex, string, *repository.Ins
|
||||
}
|
||||
|
||||
func (i *Instance) ByID(ctx context.Context, id string) *repository.Instance {
|
||||
log.Println("cached.instance.byID")
|
||||
instance, _ := i.Cache.Get(ctx, repository.InstanceByID, id)
|
||||
return instance
|
||||
}
|
||||
|
||||
func (i *Instance) ByDomain(ctx context.Context, domain string) *repository.Instance {
|
||||
log.Println("cached.instance.byDomain")
|
||||
instance, _ := i.Cache.Get(ctx, repository.InstanceByDomain, domain)
|
||||
return instance
|
||||
}
|
||||
|
||||
func (i *Instance) Set(ctx context.Context, instance *repository.Instance) {
|
||||
log.Println("cached.instance.set")
|
||||
i.Cache.Set(ctx, instance)
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package cached
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/repository"
|
||||
"github.com/zitadel/zitadel/backend/storage/cache"
|
||||
@@ -16,10 +17,12 @@ func NewUser(c cache.Cache[repository.UserIndex, string, *repository.User]) *Use
|
||||
}
|
||||
|
||||
func (i *User) ByID(ctx context.Context, id string) *repository.User {
|
||||
log.Println("cached.user.byid")
|
||||
user, _ := i.Cache.Get(ctx, repository.UserByIDIndex, id)
|
||||
return user
|
||||
}
|
||||
|
||||
func (i *User) Set(ctx context.Context, user *repository.User) {
|
||||
log.Println("cached.user.set")
|
||||
i.Cache.Set(ctx, user)
|
||||
}
|
||||
|
@@ -65,31 +65,36 @@ func (i *instance) Create(ctx context.Context, tx database.Transaction, instance
|
||||
}
|
||||
|
||||
func (i *instance) ByID(ctx context.Context, querier database.Querier, id string) (*repository.Instance, error) {
|
||||
return handler.SkipNext(
|
||||
handler.SkipNilHandler(i.cache,
|
||||
handler.ResFuncToHandle(i.cache.ByID),
|
||||
),
|
||||
handler.Chain(
|
||||
handler.Decorate(
|
||||
sql.Query(querier).InstanceByID,
|
||||
traced.Decorate[string, *repository.Instance](i.tracer, tracing.WithSpanName("instance.sql.ByID")),
|
||||
return traced.Wrap(i.tracer, "instance.byID",
|
||||
handler.SkipNext(
|
||||
handler.SkipNilHandler(i.cache,
|
||||
handler.ResFuncToHandle(i.cache.ByID),
|
||||
),
|
||||
handler.Chain(
|
||||
handler.Decorates(
|
||||
sql.Query(querier).InstanceByID,
|
||||
traced.Decorate[string, *repository.Instance](i.tracer, tracing.WithSpanName("instance.sql.ByID")),
|
||||
logged.Decorate[string, *repository.Instance](i.logger, "instance.sql.ByID"),
|
||||
),
|
||||
handler.SkipNilHandler(i.cache, handler.NoReturnToHandle(i.cache.Set)),
|
||||
),
|
||||
handler.SkipNilHandler(i.cache, handler.NoReturnToHandle(i.cache.Set)),
|
||||
),
|
||||
)(ctx, id)
|
||||
}
|
||||
|
||||
func (i *instance) ByDomain(ctx context.Context, querier database.Querier, domain string) (*repository.Instance, error) {
|
||||
return handler.SkipNext(
|
||||
handler.SkipNilHandler(i.cache,
|
||||
handler.ResFuncToHandle(i.cache.ByDomain),
|
||||
),
|
||||
handler.Chain(
|
||||
handler.Decorate(
|
||||
sql.Query(querier).InstanceByDomain,
|
||||
traced.Decorate[string, *repository.Instance](i.tracer, tracing.WithSpanName("instance.sql.ByDomain")),
|
||||
return traced.Wrap(i.tracer, "instance.byDomain",
|
||||
handler.SkipNext(
|
||||
handler.SkipNilHandler(i.cache,
|
||||
handler.ResFuncToHandle(i.cache.ByDomain),
|
||||
),
|
||||
handler.Chain(
|
||||
handler.Decorate(
|
||||
sql.Query(querier).InstanceByDomain,
|
||||
traced.Decorate[string, *repository.Instance](i.tracer, tracing.WithSpanName("instance.sql.ByDomain")),
|
||||
),
|
||||
handler.SkipNilHandler(i.cache, handler.NoReturnToHandle(i.cache.Set)),
|
||||
),
|
||||
handler.SkipNilHandler(i.cache, handler.NoReturnToHandle(i.cache.Set)),
|
||||
),
|
||||
)(ctx, domain)
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package orchestrate_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"reflect"
|
||||
@@ -112,6 +113,7 @@ func Test_instance_Create(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
fmt.Printf("------------------------ %s ------------------------\n", tt.name)
|
||||
i := orchestrate.Instance(tt.opts...)
|
||||
got, err := i.Create(tt.args.ctx, tt.args.tx, tt.args.instance)
|
||||
if (err != nil) != tt.wantErr {
|
||||
@@ -227,6 +229,7 @@ func Test_instance_ByID(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
fmt.Printf("------------------------ %s ------------------------\n", tt.name)
|
||||
i := orchestrate.Instance(tt.opts...)
|
||||
got, err := i.ByID(tt.args.ctx, tt.args.tx, tt.args.id)
|
||||
if (err != nil) != tt.wantErr {
|
||||
|
@@ -15,10 +15,10 @@ func Wrap[Req, Res any](logger *logging.Logger, name string, handle handler.Hand
|
||||
if logger == nil {
|
||||
return handle
|
||||
}
|
||||
log.Println("log.wrap", name)
|
||||
return func(ctx context.Context, r Req) (_ Res, err error) {
|
||||
logger.Debug("execute", slog.String("handler", name))
|
||||
defer logger.Debug("done", slog.String("handler", name))
|
||||
log.Println("log.wrap", name)
|
||||
return handle(ctx, r)
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func Decorate[Req, Res any](logger *logging.Logger, name string) handler.Decorat
|
||||
}
|
||||
logger = logger.With("handler", name)
|
||||
logger.DebugContext(ctx, "execute")
|
||||
log.Println("log.decorate", name)
|
||||
log.Println("logged.decorate", name)
|
||||
defer func() {
|
||||
if err != nil {
|
||||
logger.ErrorContext(ctx, "failed", slog.String("cause", err.Error()))
|
||||
|
@@ -41,7 +41,7 @@ func Decorate[Req, Res any](tracer *tracing.Tracer, opts ...tracing.DecorateOpti
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
log.Println("trace")
|
||||
log.Println("traced.decorate")
|
||||
|
||||
ctx, end := o.Start(ctx, tracer)
|
||||
defer end(err)
|
||||
|
Reference in New Issue
Block a user