From 36f3accf0d6a86a2749db8ea846d7e56d2da1612 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 6 Mar 2019 11:58:27 +0100 Subject: [PATCH] log phantomjs output even if it timeout and include orgId when render alert --- pkg/log/log.go | 11 +++++++++-- pkg/services/alerting/notifier.go | 2 +- pkg/services/rendering/phantomjs.go | 19 +++++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pkg/log/log.go b/pkg/log/log.go index 2e3b6303a6e..eb739f855ea 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -25,6 +25,7 @@ var filters map[string]log15.Lvl func init() { loggersToClose = make([]DisposableHandler, 0) loggersToReload = make([]ReloadableHandler, 0) + filters = map[string]log15.Lvl{} Root = log15.Root() Root.SetHandler(log15.DiscardHandler()) } @@ -197,7 +198,7 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) { // Log level. _, level := getLogLevelFromConfig("log."+mode, defaultLevelName, cfg) - filters := getFilters(util.SplitString(sec.Key("filters").String())) + modeFilters := getFilters(util.SplitString(sec.Key("filters").String())) format := getLogFormat(sec.Key("format").MustString("")) var handler log15.Handler @@ -230,12 +231,18 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) { } for key, value := range defaultFilters { + if _, exist := modeFilters[key]; !exist { + modeFilters[key] = value + } + } + + for key, value := range modeFilters { if _, exist := filters[key]; !exist { filters[key] = value } } - handler = LogFilterHandler(level, filters, handler) + handler = LogFilterHandler(level, modeFilters, handler) handlers = append(handlers, handler) } diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index 2ef5ebbade3..1a717ae2b54 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -138,7 +138,7 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) { return err } - renderOpts.Path = fmt.Sprintf("d-solo/%s/%s?panelId=%d", ref.Uid, ref.Slug, context.Rule.PanelId) + renderOpts.Path = fmt.Sprintf("d-solo/%s/%s?orgId=%d&panelId=%d", ref.Uid, ref.Slug, context.Rule.OrgId, context.Rule.PanelId) result, err := n.renderService.Render(context.Ctx, renderOpts) if err != nil { diff --git a/pkg/services/rendering/phantomjs.go b/pkg/services/rendering/phantomjs.go index 1bd7489c153..29c2f39fd77 100644 --- a/pkg/services/rendering/phantomjs.go +++ b/pkg/services/rendering/phantomjs.go @@ -36,7 +36,7 @@ func (rs *RenderingService) renderViaPhantomJS(ctx context.Context, opts Opts) ( defer middleware.RemoveRenderAuthKey(renderKey) phantomDebugArg := "--debug=false" - if log.GetLogLevelFor("renderer") >= log.LvlDebug { + if log.GetLogLevelFor("rendering") >= log.LvlDebug { phantomDebugArg = "--debug=true" } @@ -64,13 +64,26 @@ func (rs *RenderingService) renderViaPhantomJS(ctx context.Context, opts Opts) ( cmd := exec.CommandContext(commandCtx, binPath, cmdArgs...) cmd.Stderr = cmd.Stdout + timezone := "" + if opts.Timezone != "" { + timezone = isoTimeOffsetToPosixTz(opts.Timezone) baseEnviron := os.Environ() - cmd.Env = appendEnviron(baseEnviron, "TZ", isoTimeOffsetToPosixTz(opts.Timezone)) + cmd.Env = appendEnviron(baseEnviron, "TZ", timezone) } + rs.log.Debug("executing Phantomjs", "binPath", binPath, "cmdArgs", cmdArgs, "timezone", timezone) + out, err := cmd.Output() + if out != nil { + rs.log.Debug("Phantomjs output", "out", string(out)) + } + + if err != nil { + rs.log.Debug("Phantomjs error", "error", err) + } + // check for timeout first if commandCtx.Err() == context.DeadlineExceeded { rs.log.Info("Rendering timed out") @@ -82,8 +95,6 @@ func (rs *RenderingService) renderViaPhantomJS(ctx context.Context, opts Opts) ( return nil, err } - rs.log.Debug("Phantomjs output", "out", string(out)) - rs.log.Debug("Image rendered", "path", pngPath) return &RenderResult{FilePath: pngPath}, nil }