3
0

Change logs to encode uint64 values as strings

This is due to us introducing the web console and the uints needing
to be string encoded (because of JavaScript).
This commit is contained in:
Tomaž Jerman
2023-05-18 09:37:22 +02:00
parent 28bc2231c4
commit 462619f2b9
24 changed files with 116 additions and 85 deletions

View File

@@ -612,8 +612,8 @@ func (app *CortezaApp) initSystemEntities(ctx context.Context) (err error) {
app.Log.Debug(
"system entities set",
zap.Uint64s("users", uu.IDs()),
zap.Uint64s("roles", rr.IDs()),
logger.Uint64s("users", uu.IDs()),
logger.Uint64s("roles", rr.IDs()),
)
return nil

View File

@@ -22,6 +22,7 @@ import (
"github.com/cortezaproject/corteza/server/auth/request"
"github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/errors"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/payload"
systemService "github.com/cortezaproject/corteza/server/system/service"
"github.com/cortezaproject/corteza/server/system/types"
@@ -88,7 +89,7 @@ func (h AuthHandlers) oauth2AuthorizeClient(req *request.AuthReq) (err error) {
}
if !h.canAuthorizeClient(req.Context(), req.Client) {
h.Log.Error("user's roles do not allow authorization of this client", zap.Uint64("ID", req.Client.ID), zap.String("handle", req.Client.Handle))
h.Log.Error("user's roles do not allow authorization of this client", logger.Uint64("ID", req.Client.ID), zap.String("handle", req.Client.Handle))
request.SetOauth2Client(req.Session, nil)
request.SetOauth2AuthParams(req.Session, nil)
req.RedirectTo = GetLinks().Profile
@@ -328,7 +329,7 @@ func (h AuthHandlers) loadRequestedClient(req *request.AuthReq) (client *types.A
return fmt.Errorf("invalid client: %w", err)
}
h.Log.Debug("client loaded from store", zap.Uint64("ID", client.ID))
h.Log.Debug("client loaded from store", logger.Uint64("ID", client.ID))
return
}()
}

View File

@@ -2,6 +2,7 @@ package handlers
import (
"github.com/cortezaproject/corteza/server/auth/request"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/system/service"
"github.com/cortezaproject/corteza/server/system/types"
"go.uber.org/zap"
@@ -40,7 +41,7 @@ func (h *AuthHandlers) signupProc(req *request.AuthReq) error {
h.Log.Info(
"signup successful",
zap.String("email", newUser.Email),
zap.Uint64s("roles", newUser.Roles()),
logger.Uint64s("roles", newUser.Roles()),
)
req.RedirectTo = GetLinks().Profile

View File

@@ -10,6 +10,7 @@ import (
"github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/errors"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/options"
"github.com/cortezaproject/corteza/server/pkg/sentry"
"github.com/cortezaproject/corteza/server/pkg/wfexec"
@@ -169,7 +170,7 @@ func (svc *session) PendingPrompts(ctx context.Context) (pp []*wfexec.PendingPro
// Start new workflow session on a specific step with a given identity and scope
//
// Start is an asynchronous operation
// # Start is an asynchronous operation
//
// Please note that context passed to the function is NOT the the one that is
// used for the execution of the workflow. See watch function!
@@ -356,9 +357,9 @@ func (svc *session) Watch(ctx context.Context) {
if svc.opt.ExecDebug {
log := svc.log.
Named("exec").
With(zap.Uint64("workflowID", s.workflowID)).
With(zap.Uint64("runnerID", s.runner.Identity())).
With(zap.Uint64s("runnerRoles", s.runner.Roles()))
With(logger.Uint64("workflowID", s.workflowID)).
With(logger.Uint64("runnerID", s.runner.Identity())).
With(logger.Uint64s("runnerRoles", s.runner.Roles()))
opts = append(
opts,
@@ -448,7 +449,7 @@ func (svc *session) stateChangeHandler(ctx context.Context) wfexec.StateChangeHa
defer svc.mux.Unlock()
log := svc.log.With(
zap.Uint64("sessionID", s.ID()),
logger.Uint64("sessionID", s.ID()),
zap.Stringer("status", i),
)
@@ -458,7 +459,7 @@ func (svc *session) stateChangeHandler(ctx context.Context) wfexec.StateChangeHa
return
}
log = log.With(zap.Uint64("workflowID", ses.WorkflowID))
log = log.With(logger.Uint64("workflowID", ses.WorkflowID))
log.Debug("state change handler")

View File

@@ -15,6 +15,7 @@ import (
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/pkg/label"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/options"
"github.com/cortezaproject/corteza/server/pkg/wfexec"
"github.com/cortezaproject/corteza/server/store"
@@ -522,7 +523,7 @@ func (svc *trigger) registerTriggers(wf *types.Workflow, runAs auth.Identifiable
g *wfexec.Graph
issues types.WorkflowIssueSet
wfLog = svc.log.
With(zap.Uint64("workflowID", wf.ID))
With(logger.Uint64("workflowID", wf.ID))
// register only enabled, undeleted workflows
registerWorkflow = wf.Enabled && wf.DeletedAt == nil
@@ -545,7 +546,7 @@ func (svc *trigger) registerTriggers(wf *types.Workflow, runAs auth.Identifiable
svc.mux.Lock()
for _, t := range tt {
log := wfLog.With(zap.Uint64("triggerID", t.ID))
log := wfLog.With(logger.Uint64("triggerID", t.ID))
// always unregister
if svc.reg[wf.ID] == nil {
@@ -614,7 +615,7 @@ func (svc *trigger) unregisterWorkflows(wwf ...*types.Workflow) {
for _, wf := range wwf {
for triggerID, ptr := range svc.reg[wf.ID] {
svc.eventbus.Unregister(ptr)
svc.log.Debug("trigger unregistered", zap.Uint64("triggerID", triggerID), zap.Uint64("workflowID", wf.ID))
svc.log.Debug("trigger unregistered", logger.Uint64("triggerID", triggerID), logger.Uint64("workflowID", wf.ID))
delete(svc.triggers, wf.ID)
}
@@ -633,7 +634,7 @@ func (svc *trigger) unregisterTriggers(tt ...*types.Trigger) {
if ptr, has := svc.reg[t.WorkflowID][t.ID]; has {
svc.eventbus.Unregister(ptr)
svc.log.Debug("trigger unregistered", zap.Uint64("triggerID", t.ID), zap.Uint64("workflowID", t.WorkflowID))
svc.log.Debug("trigger unregistered", logger.Uint64("triggerID", t.ID), logger.Uint64("workflowID", t.WorkflowID))
delete(svc.triggers, t.ID)
}
}

View File

@@ -2,7 +2,9 @@ package types
import (
"context"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/wfexec"
"go.uber.org/zap"
)
@@ -30,9 +32,9 @@ func (s debugStep) Exec(ctx context.Context, r *wfexec.ExecRequest) (wfexec.Exec
// so we need to use logger directly from workflow and not the one we (could)
// get from context by wfexec.
log = s.log.With(
zap.Uint64("sessionID", r.SessionID),
zap.Uint64("stateID", r.StateID),
zap.Uint64("stepID", s.ID()),
logger.Uint64("sessionID", r.SessionID),
logger.Uint64("stateID", r.StateID),
logger.Uint64("stepID", s.ID()),
)
)

View File

@@ -26,7 +26,7 @@ func (f formatter) Run(m *types.Module, vv types.RecordValueSet) types.RecordVal
exprParser = expr.Parser()
log = logger.Default().
With(zap.Uint64("module", m.ID))
With(logger.Uint64("module", m.ID))
)
for _, v := range vv {

View File

@@ -63,7 +63,7 @@ func (s sanitizer) Run(m *types.Module, vv types.RecordValueSet) (out types.Reco
kind string
log = logger.Default().
With(zap.Uint64("module", m.ID))
With(logger.Uint64("module", m.ID))
)
for _, v := range out {

View File

@@ -8,6 +8,7 @@ import (
"github.com/cortezaproject/corteza/server/federation/types"
"github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/logger"
"go.uber.org/zap"
)
@@ -54,7 +55,7 @@ func (w *syncWorkerData) PrepareForNodes(ctx context.Context, urls chan Url) {
if err != nil {
w.logger.Info("could not preload federation user, skipping",
zap.Uint64("nodeID", n.ID),
logger.Uint64("nodeID", n.ID),
zap.Error(err))
continue
@@ -64,7 +65,7 @@ func (w *syncWorkerData) PrepareForNodes(ctx context.Context, urls chan Url) {
if err != nil {
w.logger.Info("could not get shared modules, skipping",
zap.Uint64("nodeID", n.ID),
logger.Uint64("nodeID", n.ID),
zap.Error(err))
continue
@@ -72,7 +73,7 @@ func (w *syncWorkerData) PrepareForNodes(ctx context.Context, urls chan Url) {
if len(set) == 0 {
w.logger.Info("there are no valid shared modules, skipping",
zap.Uint64("nodeID", n.ID),
logger.Uint64("nodeID", n.ID),
zap.Error(err))
continue
@@ -81,8 +82,8 @@ func (w *syncWorkerData) PrepareForNodes(ctx context.Context, urls chan Url) {
// go through set and prepare module mappings for it
for _, sm := range set {
z := []zap.Field{
zap.Uint64("nodeID", n.ID),
zap.Uint64("moduleID", sm.ID),
logger.Uint64("nodeID", n.ID),
logger.Uint64("moduleID", sm.ID),
zap.String("host", n.BaseURL),
zap.String("delay", w.delay.String()),
zap.Int("pagesize", w.limit),
@@ -199,7 +200,7 @@ func (w *syncWorkerData) Watch(ctx context.Context, delay time.Duration, limit i
w.logger.Error("could not fetch data from url, skipping",
zap.Error(err),
zap.String("url", s),
zap.Uint64("nodeID", meta.Node.ID),
logger.Uint64("nodeID", meta.Node.ID),
zap.String("host", meta.Node.BaseURL))
continue
@@ -219,7 +220,7 @@ func (w *syncWorkerData) Watch(ctx context.Context, delay time.Duration, limit i
if err != nil {
w.logger.Error("could not read data from synced url, skipping",
zap.Error(err),
zap.Uint64("nodeID", meta.Node.ID),
logger.Uint64("nodeID", meta.Node.ID),
zap.String("host", meta.Node.BaseURL))
continue
@@ -262,7 +263,7 @@ func (w *syncWorkerData) Watch(ctx context.Context, delay time.Duration, limit i
} else {
w.logger.Info("processed objects",
zap.Int("processed", processed.(dataProcesserResponse).Processed),
zap.Uint64("nodeID", meta.Node.ID))
logger.Uint64("nodeID", meta.Node.ID))
}
}
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/cortezaproject/corteza/server/federation/types"
"github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/logger"
"go.uber.org/zap"
)
@@ -52,7 +53,7 @@ func (w *syncWorkerStructure) PrepareForNodes(ctx context.Context, urls chan Url
if err != nil {
w.logger.Info("could not preload federation user, skipping",
zap.Uint64("nodeID", n.ID),
logger.Uint64("nodeID", n.ID),
zap.Error(err))
continue
@@ -63,7 +64,7 @@ func (w *syncWorkerStructure) PrepareForNodes(ctx context.Context, urls chan Url
basePath := fmt.Sprintf("/nodes/%d/modules/exposed/", n.SharedNodeID)
z := []zap.Field{
zap.Uint64("nodeID", n.ID),
logger.Uint64("nodeID", n.ID),
zap.String("host", n.BaseURL),
zap.String("delay", w.delay.String()),
zap.Int("pagesize", w.limit),
@@ -141,7 +142,7 @@ func (w *syncWorkerStructure) Watch(ctx context.Context, delay time.Duration, li
w.logger.Error("could not fetch data from url, skipping",
zap.Error(err),
zap.String("url", s),
zap.Uint64("nodeID", meta.Node.ID),
logger.Uint64("nodeID", meta.Node.ID),
zap.String("host", meta.Node.BaseURL))
continue
@@ -161,7 +162,7 @@ func (w *syncWorkerStructure) Watch(ctx context.Context, delay time.Duration, li
if err != nil {
w.logger.Error("could not read data from synced url, skipping",
zap.Error(err),
zap.Uint64("nodeID", meta.Node.ID),
logger.Uint64("nodeID", meta.Node.ID),
zap.String("host", meta.Node.BaseURL))
continue
@@ -182,7 +183,7 @@ func (w *syncWorkerStructure) Watch(ctx context.Context, delay time.Duration, li
// ignore
if moduleID := processed.(structureProcesserResponse).ModuleID; moduleID == 0 {
w.logger.Info("no structure change from last change, skipping",
zap.Uint64("nodeID", meta.Node.ID),
logger.Uint64("nodeID", meta.Node.ID),
zap.String("host", meta.Node.BaseURL))
continue
@@ -212,7 +213,7 @@ func (w *syncWorkerStructure) Watch(ctx context.Context, delay time.Duration, li
} else {
w.logger.Info("processed objects",
zap.Int("processed", processed.(structureProcesserResponse).Processed),
zap.Uint64("nodeID", meta.Node.ID),
logger.Uint64("nodeID", meta.Node.ID),
zap.String("host", meta.Node.BaseURL))
}

View File

@@ -6,6 +6,7 @@ import (
"time"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/go-chi/chi/v5/middleware"
"go.uber.org/zap"
@@ -39,7 +40,6 @@ type (
)
// NewService initializes action log service
//
func NewService(s actionlogStore, logger, tee *zap.Logger, policy policyMatcher) (svc *service) {
if tee == nil {
tee = zap.NewNop()
@@ -86,7 +86,7 @@ func (svc service) log(a *Action) {
zap.String("requestOrigin", a.RequestOrigin),
zap.String("requestID", a.RequestID),
zap.String("actorIPAddr", a.ActorIPAddr),
zap.Uint64("actorID", a.ActorID),
logger.Uint64("actorID", a.ActorID),
zap.String("resource", a.Resource),
zap.String("action", a.Action),
zap.Uint8("severity", uint8(a.Severity)),

View File

@@ -7,6 +7,7 @@ import (
"strconv"
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/pkg/logger"
"go.uber.org/zap"
)
@@ -163,7 +164,7 @@ func (svc *service) ReplaceSensitivityLevel(levels ...SensitivityLevel) (err err
nx := svc.sensitivityLevels
for _, l := range levels {
log := log.With(zap.Uint64("ID", l.ID), zap.Int("level", l.Level), zap.String("handle", l.Handle))
log := log.With(logger.Uint64("ID", l.ID), zap.Int("level", l.Level), zap.String("handle", l.Handle))
if nx.includes(l.ID) {
log.Debug("found existing")
} else {
@@ -205,7 +206,7 @@ func (svc *service) RemoveSensitivityLevel(levelIDs ...uint64) (err error) {
nx := svc.sensitivityLevels
for _, l := range levels {
log := log.With(zap.Uint64("ID", l.ID))
log := log.With(logger.Uint64("ID", l.ID))
if !nx.includes(l.ID) {
log.Debug("sensitivity level not found")
continue
@@ -296,7 +297,7 @@ func (svc *service) ReplaceConnection(ctx context.Context, conn *ConnectionWrap,
oldConn *ConnectionWrap
log = svc.logger.Named("connection").With(
zap.Uint64("ID", ID),
logger.Uint64("ID", ID),
zap.Any("params", conn.params),
zap.Any("config", conn.Config),
)
@@ -403,7 +404,7 @@ func (svc *service) RemoveConnection(ctx context.Context, ID uint64) (err error)
svc.updateIssues(issues)
svc.logger.Named("connection").Debug("deleted",
zap.Uint64("ID", ID),
logger.Uint64("ID", ID),
zap.Any("config", c.Config),
)
@@ -680,7 +681,7 @@ func (svc *service) ReplaceModel(ctx context.Context, model *Model) (err error)
upd bool
log = svc.logger.Named("models").With(
zap.Uint64("ID", ID),
logger.Uint64("ID", ID),
zap.String("ident", model.Ident),
zap.Any("label", model.Label),
)
@@ -745,7 +746,7 @@ func (svc *service) ReplaceModel(ctx context.Context, model *Model) (err error)
svc.addModelToRegistry(model, upd)
log.Debug(
"added",
zap.Uint64("connectionID", model.ConnectionID),
logger.Uint64("connectionID", model.ConnectionID),
)
return
@@ -759,8 +760,8 @@ func (svc *service) RemoveModel(ctx context.Context, connectionID, ID uint64) (e
old *Model
log = svc.logger.Named("models").With(
zap.Uint64("connectionID", connectionID),
zap.Uint64("ID", ID),
logger.Uint64("connectionID", connectionID),
logger.Uint64("ID", ID),
)
issues = newIssueHelper().addModel(ID)
)
@@ -872,7 +873,7 @@ func (svc *service) removeModelFromRegistry(model *Model) {
//
// We rely on the user to provide stable and valid attribute definitions.
func (svc *service) ReplaceModelAttribute(ctx context.Context, model *Model, diff *ModelDiff, hasRecords bool, trans ...TransformationFunction) (err error) {
svc.logger.Debug("updating model attribute", zap.Uint64("model", model.ResourceID))
svc.logger.Debug("updating model attribute", logger.Uint64("model", model.ResourceID))
var (
conn *ConnectionWrap
@@ -917,7 +918,7 @@ func (svc *service) ReplaceModelAttribute(ctx context.Context, model *Model, dif
modelIssues := svc.hasModelIssues(model.ResourceID)
if !modelIssues && !connectionIssues {
svc.logger.Debug("updating model attribute", zap.Uint64("connection", model.ConnectionID), zap.Uint64("model", model.ResourceID))
svc.logger.Debug("updating model attribute", logger.Uint64("connection", model.ConnectionID), logger.Uint64("model", model.ResourceID))
err = conn.connection.UpdateModelAttribute(ctx, model, diff, hasRecords, trans...)
if err != nil {
@@ -925,10 +926,10 @@ func (svc *service) ReplaceModelAttribute(ctx context.Context, model *Model, dif
}
} else {
if connectionIssues {
svc.logger.Warn("not updating model attribute due to connection issues", zap.Uint64("connection", model.ConnectionID))
svc.logger.Warn("not updating model attribute due to connection issues", logger.Uint64("connection", model.ConnectionID))
}
if modelIssues {
svc.logger.Warn("not updating model attribute due to model issues", zap.Uint64("model", model.ResourceID))
svc.logger.Warn("not updating model attribute due to model issues", logger.Uint64("model", model.ResourceID))
}
}
@@ -965,7 +966,8 @@ func (svc *service) ReplaceModelAttribute(ctx context.Context, model *Model, dif
// FindModelByRefs returns the model with all of the given refs matching
//
// @note refs are primarily used for DAL pipelines where steps can reference models
// by handles and slugs such as module and namespace.
//
// by handles and slugs such as module and namespace.
func (svc *service) FindModelByRefs(connectionID uint64, refs map[string]any) *Model {
if connectionID == 0 {
connectionID = svc.defConnID

View File

@@ -2,9 +2,11 @@ package logger
import (
"fmt"
"strconv"
"time"
"github.com/cortezaproject/corteza/server/pkg/options"
"github.com/spf13/cast"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"moul.io/zapfilter"
@@ -124,6 +126,16 @@ func Production(opt *options.LogOpt) (*zap.Logger, error) {
return conf.Build()
}
// Uint64 properly encodes values to be represented in the web console
func Uint64(k string, id uint64) zap.Field {
return zap.String(k, strconv.FormatUint(id, 10))
}
// Uint64s properly encodes values to be represented in the web console
func Uint64s(k string, id []uint64) zap.Field {
return zap.Strings(k, cast.ToStringSlice(id))
}
// Applies options from environment variables
func applyOptionsToConfig(conf zap.Config, opt *options.LogOpt) zap.Config {
// LOG_LEVEL

View File

@@ -7,6 +7,7 @@ import (
"go.uber.org/zap"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/options"
)
@@ -51,14 +52,14 @@ func NewMonitor(ctx context.Context, interval time.Duration) {
runtime.ReadMemStats(m)
log.With(
zap.Uint64("alloc", m.HeapAlloc),
zap.Uint64("totalAlloc", m.TotalAlloc),
zap.Uint64("sys", m.Sys),
zap.Uint64("mallocs", m.Mallocs),
zap.Uint64("frees", m.Frees),
logger.Uint64("alloc", m.HeapAlloc),
logger.Uint64("totalAlloc", m.TotalAlloc),
logger.Uint64("sys", m.Sys),
logger.Uint64("mallocs", m.Mallocs),
logger.Uint64("frees", m.Frees),
zap.Uint64("liveObjects", m.Mallocs-m.Frees),
zap.Uint64("pauseTotalNs", m.PauseTotalNs),
logger.Uint64("liveObjects", m.Mallocs-m.Frees),
logger.Uint64("pauseTotalNs", m.PauseTotalNs),
zap.Uint32("numGC", m.NumGC),
zap.Int("numGoRoutines", runtime.NumGoroutine()),
).Info("tick")

View File

@@ -10,6 +10,7 @@ import (
internalAuth "github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/handle"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/mail"
"github.com/cortezaproject/corteza/server/pkg/options"
"github.com/cortezaproject/corteza/server/system/service"
@@ -216,7 +217,7 @@ func defaultAuthClient(ctx context.Context, log *zap.Logger, s store.AuthClients
"Added OAuth2 client",
zap.String("name", c.Meta.Name),
zap.String("redirectURI", c.RedirectURI),
zap.Uint64("clientId", c.ID),
logger.Uint64("clientId", c.ID),
)
return nil

View File

@@ -6,6 +6,7 @@ import (
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/store"
"github.com/cortezaproject/corteza/server/system/types"
"go.uber.org/zap"
@@ -54,7 +55,7 @@ func SystemRoles(ctx context.Context, log *zap.Logger, s store.Storer) (rr []*ty
r.CreatedAt = *now()
m[r.Handle] = r
log.Info("creating system role", zap.String("handle", r.Handle), zap.Uint64("ID", r.ID))
log.Info("creating system role", zap.String("handle", r.Handle), logger.Uint64("ID", r.ID))
} else {
// use existing role
rr[i] = m[r.Handle]
@@ -64,7 +65,7 @@ func SystemRoles(ctx context.Context, log *zap.Logger, s store.Storer) (rr []*ty
r.DeletedAt = nil
r.ArchivedAt = nil
log.Info("updating system role", zap.String("handle", r.Handle), zap.Uint64("ID", r.ID))
log.Info("updating system role", zap.String("handle", r.Handle), logger.Uint64("ID", r.ID))
}
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/filter"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/store"
"github.com/cortezaproject/corteza/server/system/types"
"go.uber.org/zap"
@@ -51,7 +52,7 @@ func SystemUsers(ctx context.Context, log *zap.Logger, s store.Users) (uu []*typ
return nil, fmt.Errorf("failed to provision system user %s: %w", u.Handle, err)
}
log.Info("creating system user", zap.String("handle", u.Handle), zap.Uint64("ID", u.ID))
log.Info("creating system user", zap.String("handle", u.Handle), logger.Uint64("ID", u.ID))
} else {
u.ID = m[u.Handle].ID
@@ -75,7 +76,7 @@ func SystemUsers(ctx context.Context, log *zap.Logger, s store.Users) (uu []*typ
return nil, fmt.Errorf("failed to provision system user %s: %w", u.Handle, err)
}
log.Info("updating system user", zap.String("handle", u.Handle), zap.Uint64("ID", u.ID))
log.Info("updating system user", zap.String("handle", u.Handle), logger.Uint64("ID", u.ID))
}
}

View File

@@ -1,6 +1,7 @@
package rbac
import (
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/slice"
"go.uber.org/zap"
)
@@ -98,7 +99,7 @@ func (p partRoles) LogFields() (ff []zap.Field) {
ii = append(ii, r)
}
ff = append(ff, zap.Uint64s(k.String(), ii))
ff = append(ff, logger.Uint64s(k.String(), ii))
}
return

View File

@@ -8,6 +8,7 @@ import (
"sync"
"time"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/sentry"
"go.uber.org/zap"
)
@@ -109,7 +110,7 @@ func (svc *service) Check(ses Session, op string, res Resource) (a Access) {
svc.logger.Debug(a.String()+" "+op+" for "+res.RbacResource(),
append(
fRoles.LogFields(),
zap.Uint64("identity", ses.Identity()),
logger.Uint64("identity", ses.Identity()),
zap.Any("indexed", len(svc.indexed)),
zap.Any("rules", len(svc.rules)),
)...,

View File

@@ -11,6 +11,7 @@ import (
"github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/errors"
"github.com/cortezaproject/corteza/server/pkg/id"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/options"
"github.com/gorilla/websocket"
"go.uber.org/zap"
@@ -75,7 +76,7 @@ func Session(ctx context.Context, ws *server, conn *websocket.Conn) *session {
s.logger = ws.logger.
Named("session").
With(
zap.Uint64("id", s.id),
logger.Uint64("id", s.id),
)
return s
@@ -215,8 +216,8 @@ func (s *session) procRawMessage(raw []byte) (err error) {
i := s.Identity()
s.logger.Debug(
"authenticated",
zap.Uint64("userID", i.Identity()),
zap.Uint64s("roles", i.Roles()),
logger.Uint64("userID", i.Identity()),
logger.Uint64s("roles", i.Roles()),
)
s.server.StoreSession(s)

View File

@@ -187,7 +187,7 @@ func NewSession(ctx context.Context, g *Graph, oo ...SessionOpt) *Session {
}
s.log = s.log.
With(zap.Uint64("sessionID", s.id))
With(logger.Uint64("sessionID", s.id))
s.callStack = append(s.callStack, s.id)
@@ -467,7 +467,7 @@ func (s *Session) worker(ctx context.Context) {
return
}
s.log.Debug("pulled state from queue", zap.Uint64("stateID", st.stateId))
s.log.Debug("pulled state from queue", logger.Uint64("stateID", st.stateId))
if st.step == nil {
// We should not terminate if the session contains any delayed or prompted steps.
status := s.Status()
@@ -506,7 +506,7 @@ func (s *Session) worker(ctx context.Context) {
var (
err error
log = s.log.With(zap.Uint64("stateID", st.stateId))
log = s.log.With(logger.Uint64("stateID", st.stateId))
)
nxt, err := s.exec(ctx, log, st)
@@ -544,7 +544,7 @@ func (s *Session) worker(ctx context.Context) {
s.log.Debug(
"executed",
zap.Uint64("stateID", st.stateId),
logger.Uint64("stateID", st.stateId),
zap.Stringer("status", status),
zap.Error(st.err),
)
@@ -553,9 +553,9 @@ func (s *Session) worker(ctx context.Context) {
for _, n := range nxt {
if n.step != nil {
log.Debug("next step queued", zap.Uint64("nextStepId", n.step.ID()))
log.Debug("next step queued", logger.Uint64("nextStepId", n.step.ID()))
} else {
log.Debug("next step queued", zap.Uint64("nextStepId", 0))
log.Debug("next step queued", logger.Uint64("nextStepId", 0))
}
if err = s.enqueue(ctx, n); err != nil {
log.Error("unable to enqueue", zap.Error(err))
@@ -652,7 +652,7 @@ func (s *Session) exec(ctx context.Context, log *zap.Logger, st *State) (nxt []*
)
if st.step != nil {
log = log.With(zap.Uint64("stepID", st.step.ID()))
log = log.With(logger.Uint64("stepID", st.step.ID()))
}
{
@@ -684,7 +684,7 @@ func (s *Session) exec(ctx context.Context, log *zap.Logger, st *State) (nxt []*
// handling error with error handling
// step set in one of the previous steps
log.Warn("step execution error handled",
zap.Uint64("errorHandlerStepId", st.errHandler.ID()),
logger.Uint64("errorHandlerStepId", st.errHandler.ID()),
zap.Error(st.err),
)
@@ -840,7 +840,7 @@ func (s *Session) exec(ctx context.Context, log *zap.Logger, st *State) (nxt []*
// gracefully handling last step of iteration branch
// that does not point back to the iterator step
st.next = Steps{currLoop.Iterator()}
log.Debug("last step in iteration branch, going back", zap.Uint64("backStepId", st.next[0].ID()))
log.Debug("last step in iteration branch, going back", logger.Uint64("backStepId", st.next[0].ID()))
}
if len(st.next) == 0 {

View File

@@ -16,6 +16,7 @@ import (
"github.com/cortezaproject/corteza/server/pkg/errors"
"github.com/cortezaproject/corteza/server/pkg/filter"
labelsType "github.com/cortezaproject/corteza/server/pkg/label/types"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/store"
"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/exp"
@@ -220,10 +221,10 @@ func fix_2022_09_00_migrateComposeModuleDiscoveryConfigSettings(ctx context.Cont
} else {
query = fmt.Sprintf(updateModuleDiscoverySettings, u.Config, u.ID)
}
log.Debug("saving migrated module.config.discovery settings", zap.Uint64("id", u.ID))
log.Debug("saving migrated module.config.discovery settings", logger.Uint64("id", u.ID))
_, err = s.(*Store).DB.ExecContext(ctx, query)
if err != nil {
log.Debug("error saving migrated module.config.discovery settings", zap.Uint64("id", u.ID))
log.Debug("error saving migrated module.config.discovery settings", logger.Uint64("id", u.ID))
continue
}
}
@@ -391,7 +392,7 @@ func fix_2022_09_00_migrateOldComposeRecordValues(ctx context.Context, s *Store)
perModLog := log.With(
zap.String("handle", mod.Handle),
zap.Uint64("id", mod.ID),
logger.Uint64("id", mod.ID),
)
err = func() (err error) {
@@ -718,7 +719,7 @@ func fix_2023_03_00_migrateComposeModuleConfigForRecordDeDup(ctx context.Context
)
if err = s.Tx(ctx, func(ctx context.Context, s store.Storer) (err error) {
log.Debug("collecting module.config.recordDeDup for module", zap.Uint64("id", m.ID))
log.Debug("collecting module.config.recordDeDup for module", logger.Uint64("id", m.ID))
query = fmt.Sprintf(moduleConfigRecordDeDup, m.ID)
rows, err = s.(*Store).DB.QueryContext(ctx, query)
@@ -734,7 +735,7 @@ func fix_2023_03_00_migrateComposeModuleConfigForRecordDeDup(ctx context.Context
for rows.Next() {
if err = rows.Err(); err != nil {
log.Info("failed to scan rows to migrated module.config.recordDeDup for module",
zap.Uint64("id", m.ID))
logger.Uint64("id", m.ID))
return
}
@@ -776,9 +777,9 @@ func fix_2023_03_00_migrateComposeModuleConfigForRecordDeDup(ctx context.Context
if len(migratedRules) > 0 {
m.Config.RecordDeDup.Rules = migratedRules
log.Debug("saving migrated module.config.recordDeDup for module", zap.Uint64("id", m.ID))
log.Debug("saving migrated module.config.recordDeDup for module", logger.Uint64("id", m.ID))
if err = s.UpdateComposeModule(ctx, m); err != nil {
log.Debug("error saving migrated module.config.recordDeDup for module", zap.Uint64("id", m.ID))
log.Debug("error saving migrated module.config.recordDeDup for module", logger.Uint64("id", m.ID))
return
}
}

View File

@@ -13,6 +13,7 @@ import (
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/handle"
"github.com/cortezaproject/corteza/server/pkg/label"
"github.com/cortezaproject/corteza/server/pkg/logger"
"github.com/cortezaproject/corteza/server/pkg/options"
"github.com/cortezaproject/corteza/server/pkg/rbac"
"github.com/cortezaproject/corteza/server/pkg/slice"
@@ -912,7 +913,7 @@ func UpdateRbacRoles(ctx context.Context, log *zap.Logger, ru rbacRoleUpdater, b
for _, r := range roles {
log := log.With(
zap.Uint64("ID", r.ID),
logger.Uint64("ID", r.ID),
zap.String("handle", r.Handle),
)

View File

@@ -252,7 +252,7 @@ func (svc *settings) logChange(ctx context.Context, vv types.SettingValueSet) {
for _, v := range vv {
svc.log(ctx,
zap.String("name", v.Name),
zap.Uint64("owned-by", v.OwnedBy),
logger.Uint64("owned-by", v.OwnedBy),
zap.Stringer("value", v.Value)).
WithOptions(zap.AddCallerSkip(1)).
Debug("setting value updated")
@@ -280,7 +280,7 @@ func (svc *settings) Delete(ctx context.Context, name string, ownedBy uint64) er
svc.log(ctx,
zap.String("name", name),
zap.Uint64("owned-by", ownedBy)).Info("setting value removed")
logger.Uint64("owned-by", ownedBy)).Info("setting value removed")
return svc.updateCurrent(ctx, vv)
}