Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Log loaded config at debug level #5

Merged
merged 1 commit into from
Feb 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
10 changes: 10 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/tetratelabs/log"
"github.com/tetratelabs/run"
"github.com/tetratelabs/run/pkg/signal"
"github.com/tetratelabs/telemetry"

"github.com/tetrateio/authservice-go/internal"
"github.com/tetrateio/authservice-go/internal/server"
Expand All @@ -34,11 +35,20 @@ func main() {
authzServer = server.New(&configFile.Config, authz.Register)
)

configLog := run.NewPreRunner("config-log", func() error {
cfgLog := internal.Logger(internal.Config)
if cfgLog.Level() == telemetry.LevelDebug {
cfgLog.Debug("configuration loaded", "config", internal.ConfigToJSONString(&configFile.Config))
}
return nil
})

g := run.Group{Logger: internal.Logger(internal.Default)}

g.Register(
configFile, // load the configuration
logging, // set up the logging system
configLog, // log the configuration
authzServer, // start the server
&signal.Handler{}, // handle graceful termination
)
Expand Down
5 changes: 5 additions & 0 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ func (l *LocalConfigFile) Validate() error {

return l.Config.ValidateAll()
}

func ConfigToJSONString(c *configv1.Config) string {
b, _ := protojson.Marshal(c)
return string(b)
}
20 changes: 20 additions & 0 deletions internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,23 @@ func TestLoadMock(t *testing.T) {
require.NoError(t, err)
require.True(t, proto.Equal(want, &cfg.Config))
}

func TestConfigToJSONString(t *testing.T) {
tests := []struct {
name string
config *configv1.Config
want string
}{
{"nil", nil, "{}"},
{"empty", &configv1.Config{}, "{}"},
{"simple", &configv1.Config{ListenPort: 8080}, `{"listenPort":8080}`},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ConfigToJSONString(tt.config)
require.JSONEq(t, tt.want, got)
})
}

}
2 changes: 2 additions & 0 deletions internal/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

const (
Authz = "authz"
Config = "config"
Default = "default"
Requests = "requests"
Server = "server"
Expand All @@ -37,6 +38,7 @@ const (
// scopes contains the list of all logging scopes
var scopes = map[string]string{
Authz: "Envoy ext-authz filter implementation messages",
Config: "Configuration messages",
Default: "Default",
Requests: "Logs all requests and responses received by the server",
Server: "Server request handling messages",
Expand Down
Loading