Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(app): add common logging of version, config on startup #12245

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions app/kuma-cp/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -62,28 +61,21 @@ func newRunCmdWithOpts(opts kuma_cmd.RunCmdOpts) *cobra.Command {
runLog.Info(`[WARNING] "standalone" mode is deprecated. Changing it to "zone". Set KUMA_MODE to "zone" as "standalone" will be removed in the future.`)
cfg.Mode = config_core.Zone
}

kuma_cp.PrintDeprecations(&cfg, cmd.OutOrStdout())

gracefulCtx, ctx, _ := opts.SetupSignalHandler()
// this needs to be done before we log the config as bootstrap may change it.
rt, err := bootstrap.Bootstrap(gracefulCtx, cfg)
if err != nil {
runLog.Error(err, "unable to set up Control Plane runtime")
return err
}

cfgForDisplay, err := config.ConfigForDisplay(&cfg)
if err != nil {
runLog.Error(err, "unable to prepare config for display")
return err
runLog.Error(err, "unable to prepare config for display, log config will be empty")
}
cfgBytes, err := config.ToJson(cfgForDisplay)
if err != nil {
runLog.Error(err, "unable to convert config to json")
return err
}
runLog.Info(fmt.Sprintf("Current config %s", cfgBytes))
runLog.Info(fmt.Sprintf("Running in mode `%s`", cfg.Mode))

runLog.Info("starting Control Plane", "version", kuma_version.Build.Version, "mode", cfg.Mode, "config", cfgForDisplay)
if err := os.RaiseFileLimit(); err != nil {
runLog.Error(err, "unable to raise the open file limit")
}
Expand Down Expand Up @@ -166,7 +158,7 @@ func newRunCmdWithOpts(opts kuma_cmd.RunCmdOpts) *cobra.Command {
return err
}

runLog.Info("starting Control Plane", "version", kuma_version.Build.Version)
runLog.Info("starting Control Plane runtime")
if err := rt.Start(gracefulCtx.Done()); err != nil {
runLog.Error(err, "problem running Control Plane")
return err
Expand Down
9 changes: 4 additions & 5 deletions app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {

kumadp.PrintDeprecations(cfg, cmd.OutOrStdout())

if conf, err := config.ToJson(cfg); err == nil {
runLog.Info("effective configuration", "config", string(conf))
} else {
runLog.Error(err, "unable to format effective configuration", "config", cfg)
return err
cfgForDisplay, err := config.ConfigForDisplay(cfg)
if err != nil {
runLog.Error(err, "unable to format effective configuration")
}
runLog.Info("starting Data Plane", "version", kuma_version.Build.Version, "config", cfgForDisplay)

// Map the resource types that are acceptable depending on the value of the `--proxy-type` flag.
proxyTypeMap := map[string]model.ResourceType{
Expand Down
6 changes: 1 addition & 5 deletions pkg/api-server/config_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ func addConfigEndpoints(ws *restful.WebService, access access.ControlPlaneMetada
if err != nil {
return err
}
json, err := config.ToJson(cfgForDisplay)
if err != nil {
return err
}
ws.Route(ws.GET("/config").To(func(req *restful.Request, resp *restful.Response) {
ctx := req.Request.Context()
if err := access.ValidateView(ctx, user.FromCtx(ctx)); err != nil {
rest_errors.HandleError(ctx, resp, err, "Access denied")
return
}
resp.AddHeader("content-type", "application/json")
if _, err := resp.Write(json); err != nil {
if _, err := resp.Write([]byte(cfgForDisplay)); err != nil {
log.Error(err, "Could not write the index response")
}
}))
Expand Down
10 changes: 7 additions & 3 deletions pkg/config/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import (
"sigs.k8s.io/yaml"
)

func ConfigForDisplay(cfg Config) (Config, error) {
func ConfigForDisplay(cfg Config) (string, error) {
// copy config so we don't override values, because nested structs in config are pointers
newCfg, err := copyConfig(cfg)
if err != nil {
return nil, err
return "", err
}
newCfg.Sanitize()
return newCfg, nil
b, err := json.Marshal(newCfg)
if err != nil {
return "", err
}
return string(b), nil
}

func copyConfig(cfg Config) (Config, error) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/kds/envoyadmin/kds_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/api/system/v1alpha1"
"github.com/kumahq/kuma/pkg/config"
config_util "github.com/kumahq/kuma/pkg/config"
kuma_cp "github.com/kumahq/kuma/pkg/config/app/kuma-cp"
store_config "github.com/kumahq/kuma/pkg/config/core/resources/store"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
Expand All @@ -33,11 +32,10 @@ var _ = Describe("KDS client", func() {
cfg := kuma_cp.DefaultConfig()
cfg.Store.Type = storeType
displayCfg, _ := config.ConfigForDisplay(&cfg)
bytes, _ := config_util.ToJson(displayCfg)
zoneInsight.Spec.Subscriptions = []*v1alpha1.KDSSubscription{
{
ConnectTime: util_proto.MustTimestampProto(t1),
Config: string(bytes),
Config: displayCfg,
},
}
return zoneInsight
Expand Down
8 changes: 2 additions & 6 deletions pkg/kds/zone/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ func Setup(rt core_runtime.Runtime) error {
}
kubeFactory := resources_k8s.NewSimpleKubeFactory()
cfg := rt.Config()
cfgForDisplay, err := config.ConfigForDisplay(&cfg)
if err != nil {
return errors.Wrap(err, "could not construct config for display")
}
cfgJson, err := config.ToJson(cfgForDisplay)
cfgJson, err := config.ConfigForDisplay(&cfg)
if err != nil {
return errors.Wrap(err, "could not marshall config to json")
}
Expand All @@ -68,7 +64,7 @@ func Setup(rt core_runtime.Runtime) error {
syncClient := kds_client_v2.NewKDSSyncClient(
log,
reg.ObjectTypes(model.HasKDSFlag(model.GlobalToZoneSelector)),
kds_client_v2.NewDeltaKDSStream(stream, zone, rt, string(cfgJson)),
kds_client_v2.NewDeltaKDSStream(stream, zone, rt, cfgJson),
kds_sync_store_v2.ZoneSyncCallback(
stream.Context(),
rt.KDSContext().Configs,
Expand Down
Loading