Skip to content

Commit

Permalink
feat(health): switch health endpoint from Info to Debug log calls on …
Browse files Browse the repository at this point in the history
…success

Also add new global `--log-level` so debug logging can be turend on.
  • Loading branch information
jimehk committed May 20, 2024
1 parent 75be2e9 commit c81fc42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,38 @@ package cmd

import (
"fmt"
"log/slog"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// NewRootCommand creates a new root command for the zadara-exporter.
func NewRootCommand(version string, commit string) *cobra.Command {
func NewRootCommand(version, commit string) *cobra.Command {
cmd := &cobra.Command{
Use: "zadara-exporter",
Short: "Zadara exporter for Prometheus",
Version: fmt.Sprintf("%s (%s)", version, commit),
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
levelStr := viper.GetString("log-level")

level := slog.LevelInfo
err := level.UnmarshalText([]byte(levelStr))
if err != nil {
return fmt.Errorf("failed to parse log level: %w", err)
}

slog.SetLogLoggerLevel(level)

return nil
},
}

cmd.PersistentFlags().String("config", "", "The path to the configuration file")
cmd.PersistentFlags().String("log-level", "info", "The path to the configuration file")

must(viper.BindPFlag("config", cmd.PersistentFlags().Lookup("config")))
must(viper.BindPFlag("log-level", cmd.PersistentFlags().Lookup("log-level")))

cmd.AddCommand(NewServerCommand())

Expand Down
2 changes: 1 addition & 1 deletion health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var couldNotConnect bool

for _, target := range targets {
slog.Info("Checking target", "target", target.Name)
slog.Debug("Checking target", "target", target.Name)
client := commandcenter.NewClient(target)

_, err := client.GetStores(r.Context(), target.CloudName)
Expand Down

0 comments on commit c81fc42

Please sign in to comment.