Skip to content

feat: robust logging #289

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

Merged
merged 8 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion .testcoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ exclude:
- common/config/config.go
- mocks
- common/apis/*
- export_test.go
- export_test_integration.go
# remove it later:
- listener/reconciler/clusteraccess/subroutines.go
- listener/reconciler/singlecluster

17 changes: 1 addition & 16 deletions cmd/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/spf13/cobra"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/openmfp/golang-commons/logger"

"github.com/openmfp/kubernetes-graphql-gateway/gateway/manager"
)

Expand All @@ -24,12 +22,7 @@ var gatewayCmd = &cobra.Command{
Short: "Run the GQL Gateway",
Example: "go run main.go gateway",
RunE: func(_ *cobra.Command, _ []string) error {
log, err := setupLogger(defaultCfg.Log.Level)
if err != nil {
return fmt.Errorf("failed to setup logger: %w", err)
}

log.Info().Str("LogLevel", log.GetLevel().String()).Msg("Starting server...")
log.Info().Str("LogLevel", log.GetLevel().String()).Msg("Starting the Gateway...")

ctx, _, shutdown := openmfpcontext.StartContext(log, appCfg, 1*time.Second)
defer shutdown()
Expand Down Expand Up @@ -127,11 +120,3 @@ var gatewayCmd = &cobra.Command{
return nil
},
}

// setupLogger initializes the logger with the given log level
func setupLogger(logLevel string) (*logger.Logger, error) {
loggerCfg := logger.DefaultConfig()
loggerCfg.Name = "crdGateway"
loggerCfg.Level = logLevel
return logger.New(loggerCfg)
}
12 changes: 11 additions & 1 deletion cmd/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook"

gatewayv1alpha1 "github.com/openmfp/kubernetes-graphql-gateway/common/apis/v1alpha1"
"github.com/openmfp/kubernetes-graphql-gateway/listener/pkg/apischema"
"github.com/openmfp/kubernetes-graphql-gateway/listener/pkg/workspacefile"
"github.com/openmfp/kubernetes-graphql-gateway/listener/reconciler"
"github.com/openmfp/kubernetes-graphql-gateway/listener/reconciler/clusteraccess"
"github.com/openmfp/kubernetes-graphql-gateway/listener/reconciler/kcp"
Expand Down Expand Up @@ -74,6 +76,8 @@ var listenCmd = &cobra.Command{
}
},
Run: func(cmd *cobra.Command, args []string) {
log.Info().Str("LogLevel", log.GetLevel().String()).Msg("Starting the Listener...")

ctx := ctrl.SetupSignalHandler()
restCfg := ctrl.GetConfigOrDie()

Expand Down Expand Up @@ -123,7 +127,13 @@ var listenCmd = &cobra.Command{

reconcilerInstance = kcpReconciler
} else {
reconcilerInstance, err = clusteraccess.CreateMultiClusterReconciler(appCfg, reconcilerOpts, log)
ioHandler, err := workspacefile.NewIOHandler(appCfg.OpenApiDefinitionsPath)
if err != nil {
log.Error().Err(err).Msg("unable to create IO handler")
os.Exit(1)
}

reconcilerInstance, err = clusteraccess.NewClusterAccessReconciler(ctx, appCfg, reconcilerOpts, ioHandler, apischema.NewResolver(log), log)
if err != nil {
log.Error().Err(err).Msg("unable to create cluster access reconciler")
os.Exit(1)
Expand Down
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func initConfig() {
v.SetDefault("gateway-url-graphql-suffix", "graphql")
}

// setupLogger initializes the logger with the given log level
func setupLogger(logLevel string) (*logger.Logger, error) {
loggerCfg := logger.DefaultConfig()
loggerCfg.Name = "crdGateway"
loggerCfg.Level = logLevel
return logger.New(loggerCfg)
}

func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
Loading