Cleanup action log request origins
This commit is contained in:
@@ -9,14 +9,12 @@ type ctxKey int
|
||||
|
||||
const (
|
||||
RequestOrigin_APP_Init = "app/init"
|
||||
RequestOrigin_APP_Serve = "app/serve"
|
||||
RequestOrigin_APP_Upgrade = "app/upgrade"
|
||||
RequestOrigin_APP_Activate = "app/activate"
|
||||
RequestOrigin_APP_Provision = "app/provision"
|
||||
RequestOrigin_APP_Run = "app/run"
|
||||
RequestOrigin_HTTPServer_API_REST = "app/http-server/api/rest"
|
||||
RequestOrigin_HTTPServer_API_GRPC = "app/http-server/api/grpc"
|
||||
RequestOrigin_CLI = "app/cli"
|
||||
)
|
||||
|
||||
// RequestOriginKey is the key that holds th unique request ID in a request context.
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/actionlog"
|
||||
)
|
||||
|
||||
// RunSetup calls Setup hooks on all runnable parts
|
||||
@@ -25,6 +27,7 @@ func RunSetup(log *zap.Logger, opts *Options, pp ...Runnable) (err error) {
|
||||
// It stops on first error
|
||||
func RunInitialize(ctx context.Context, pp ...Runnable) (err error) {
|
||||
for _, app := range pp {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Init)
|
||||
err = app.Initialize(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -39,6 +42,7 @@ func RunInitialize(ctx context.Context, pp ...Runnable) (err error) {
|
||||
// It stops on first error
|
||||
func RunUpgrade(ctx context.Context, pp ...Runnable) (err error) {
|
||||
for _, app := range pp {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Upgrade)
|
||||
err = app.Upgrade(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -53,6 +57,7 @@ func RunUpgrade(ctx context.Context, pp ...Runnable) (err error) {
|
||||
// It stops on first error
|
||||
func RunActivate(ctx context.Context, pp ...Runnable) (err error) {
|
||||
for _, app := range pp {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Activate)
|
||||
err = app.Activate(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -67,6 +72,7 @@ func RunActivate(ctx context.Context, pp ...Runnable) (err error) {
|
||||
// It stops on first error
|
||||
func RunProvision(ctx context.Context, pp ...Runnable) (err error) {
|
||||
for _, app := range pp {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Provision)
|
||||
err = app.Provision(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
+4
-4
@@ -133,7 +133,6 @@ func (r *runner) Initialize(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Init)
|
||||
if err = RunInitialize(ctx, r.parts...); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -153,7 +152,6 @@ func (r *runner) Upgrade(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
if r.opt.Upgrade.Always {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Upgrade)
|
||||
if err = RunUpgrade(ctx, r.parts...); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -173,7 +171,6 @@ func (r *runner) Activate(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Activate)
|
||||
if err = RunActivate(ctx, r.parts...); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -192,7 +189,6 @@ func (r *runner) Provision(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
if r.opt.Provision.Always {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Provision)
|
||||
if err = RunProvision(ctx, r.parts...); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -281,10 +277,12 @@ func (r *runner) Run(ctx context.Context) error {
|
||||
})
|
||||
|
||||
upgradeCmd := cli.UpgradeCommand(func() (err error) {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Init)
|
||||
if err = r.Initialize(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Upgrade)
|
||||
if err = RunUpgrade(ctx, r.parts...); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -293,10 +291,12 @@ func (r *runner) Run(ctx context.Context) error {
|
||||
})
|
||||
|
||||
provisionCmd := cli.ProvisionCommand(func() (err error) {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Activate)
|
||||
if err = r.Activate(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Provision)
|
||||
if err = RunProvision(ctx, r.parts...); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user