From 742029d8a491e61abf42dc2dafcda9ae1d6356b2 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 1 Oct 2018 19:18:03 +0200 Subject: [PATCH] Global configuration log at start --- anonymize/anonymize_config_test.go | 35 ++++++++++++++++++++++++++++++ api/handler.go | 2 +- cmd/traefik/traefik.go | 15 ++++++++----- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/anonymize/anonymize_config_test.go b/anonymize/anonymize_config_test.go index 3ffe72bce..de449f3c1 100644 --- a/anonymize/anonymize_config_test.go +++ b/anonymize/anonymize_config_test.go @@ -2,12 +2,15 @@ package anonymize import ( "crypto/tls" + "os" "testing" "time" "github.com/containous/flaeg" "github.com/containous/traefik/acme" + "github.com/containous/traefik/api" "github.com/containous/traefik/configuration" + "github.com/containous/traefik/middlewares" "github.com/containous/traefik/provider" acmeprovider "github.com/containous/traefik/provider/acme" "github.com/containous/traefik/provider/boltdb" @@ -25,8 +28,11 @@ import ( "github.com/containous/traefik/provider/mesos" "github.com/containous/traefik/provider/rancher" "github.com/containous/traefik/provider/zk" + "github.com/containous/traefik/safe" traefiktls "github.com/containous/traefik/tls" "github.com/containous/traefik/types" + "github.com/elazarl/go-bindata-assetfs" + "github.com/thoas/stats" ) func TestDo_globalConfiguration(t *testing.T) { @@ -188,6 +194,35 @@ func TestDo_globalConfiguration(t *testing.T) { config.HealthCheck = &configuration.HealthCheckConfig{ Interval: flaeg.Duration(666 * time.Second), } + config.API = &api.Handler{ + EntryPoint: "traefik", + Dashboard: true, + Debug: true, + CurrentConfigurations: &safe.Safe{}, + Statistics: &types.Statistics{ + RecentErrors: 666, + }, + Stats: &stats.Stats{ + Uptime: time.Now(), + Pid: 666, + ResponseCounts: map[string]int{"foo": 1}, + TotalResponseCounts: map[string]int{"bar": 1}, + TotalResponseTime: time.Now(), + }, + StatsRecorder: &middlewares.StatsRecorder{}, + DashboardAssets: &assetfs.AssetFS{ + Asset: func(path string) ([]byte, error) { + return nil, nil + }, + AssetDir: func(path string) ([]string, error) { + return nil, nil + }, + AssetInfo: func(path string) (os.FileInfo, error) { + return nil, nil + }, + Prefix: "fii", + }, + } config.RespondingTimeouts = &configuration.RespondingTimeouts{ ReadTimeout: flaeg.Duration(666 * time.Second), WriteTimeout: flaeg.Duration(666 * time.Second), diff --git a/api/handler.go b/api/handler.go index e3e88b433..370955978 100644 --- a/api/handler.go +++ b/api/handler.go @@ -23,7 +23,7 @@ type Handler struct { Statistics *types.Statistics `description:"Enable more detailed statistics" export:"true"` Stats *thoas_stats.Stats `json:"-"` StatsRecorder *middlewares.StatsRecorder `json:"-"` - DashboardAssets *assetfs.AssetFS + DashboardAssets *assetfs.AssetFS `json:"-"` } var ( diff --git a/cmd/traefik/traefik.go b/cmd/traefik/traefik.go index 412027507..67469e6fc 100644 --- a/cmd/traefik/traefik.go +++ b/cmd/traefik/traefik.go @@ -165,21 +165,26 @@ func runCmd(globalConfiguration *configuration.GlobalConfiguration, configFile s globalConfiguration.SetEffectiveConfiguration(configFile) globalConfiguration.ValidateConfiguration() + log.Infof("Traefik version %s built on %s", version.Version, version.BuildDate) + + jsonConf, err := json.Marshal(globalConfiguration) + if err != nil { + log.Error(err) + log.Debugf("Global configuration loaded [struct] %#v", globalConfiguration) + } else { + log.Debugf("Global configuration loaded %s", string(jsonConf)) + } + if globalConfiguration.API != nil && globalConfiguration.API.Dashboard { globalConfiguration.API.DashboardAssets = &assetfs.AssetFS{Asset: genstatic.Asset, AssetInfo: genstatic.AssetInfo, AssetDir: genstatic.AssetDir, Prefix: "static"} } - jsonConf, _ := json.Marshal(globalConfiguration) - log.Infof("Traefik version %s built on %s", version.Version, version.BuildDate) - if globalConfiguration.CheckNewVersion { checkNewVersion() } stats(globalConfiguration) - log.Debugf("Global configuration loaded %s", string(jsonConf)) - providerAggregator := configuration.NewProviderAggregator(globalConfiguration) acmeprovider := globalConfiguration.InitACMEProvider()