From fbf3469e8005a229e6023d93e45b233e6e319ea7 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Fri, 19 Mar 2021 09:41:26 +0000 Subject: [PATCH] Fix loading timezone info on windows (#32029) (#32149) * Fix loading timezone info on windows * Move setting zoneinfo to config load * Construct proper file path Co-authored-by: Arve Knudsen Co-authored-by: Arve Knudsen (cherry picked from commit ea484312a04940b12ded65c3f30a53564bbfb777) Co-authored-by: Tania B --- pkg/setting/setting.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 550af2f820d..10adfd444e3 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -12,6 +12,7 @@ import ( "os" "path" "path/filepath" + "runtime" "strconv" "strings" "time" @@ -48,6 +49,9 @@ const ( authProxySyncTTL = 60 ) +// zoneInfo names environment variable for setting the path to look for the timezone database in go +const zoneInfo = "ZONEINFO" + var ( // App settings. Env = Dev @@ -751,6 +755,14 @@ func (cfg *Cfg) validateStaticRootPath() error { func (cfg *Cfg) Load(args *CommandLineArgs) error { setHomePath(args) + // Fix for missing IANA db on Windows + _, zoneInfoSet := os.LookupEnv(zoneInfo) + if runtime.GOOS == "windows" && !zoneInfoSet { + if err := os.Setenv(zoneInfo, filepath.Join(HomePath, "tools", "zoneinfo.zip")); err != nil { + cfg.Logger.Error("Can't set ZONEINFO environment variable", "err", err) + } + } + iniFile, err := cfg.loadConfiguration(args) if err != nil { return err