From 90c8916cae645ac58e1adde0992444e241e94573 Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Wed, 8 Nov 2023 16:29:09 +0100 Subject: [PATCH] remove indirection for rendering the collector template --- .../gui/views/templates/collectorStatus.tmpl | 4 +- pkg/status/render.go | 40 +++++-------------- pkg/status/templates/collector.tmpl | 12 +++--- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/cmd/agent/gui/views/templates/collectorStatus.tmpl b/cmd/agent/gui/views/templates/collectorStatus.tmpl index 0d067b62ec13e4..3c48e023d9f63c 100644 --- a/cmd/agent/gui/views/templates/collectorStatus.tmpl +++ b/cmd/agent/gui/views/templates/collectorStatus.tmpl @@ -40,10 +40,10 @@ Average Execution Time : {{humanizeDuration .AverageExecutionTime "ms"}}
Last Execution Date : {{formatUnixTime .UpdateTimestamp}}
Last Successful Execution Date : {{ if .LastSuccessDate }}{{formatUnixTime .LastSuccessDate}}{{ else }}Never{{ end }}
- {{- if index $.Stats.inventories .CheckID }} + {{- if index $.Stats.checkMetadata .CheckID }} Metadata:
- {{- range $k, $v := index $.Stats.inventories .CheckID }} + {{- range $k, $v := index $.Stats.checkMetadata .CheckID }} {{ $k }}: {{ $v }}
{{- end }}
diff --git a/pkg/status/render.go b/pkg/status/render.go index b58fd4345a3ae0..727b87f0efc948 100644 --- a/pkg/status/render.go +++ b/pkg/status/render.go @@ -36,11 +36,7 @@ func FormatStatus(data []byte) (string, error) { } else { log.Warn("The Forwarder status format is invalid. Some parts of the `Forwarder` section may be missing.") } - runnerStats := stats["runnerStats"] - pyLoaderStats := stats["pyLoaderStats"] - pythonInit := stats["pythonInit"] - autoConfigStats := stats["autoConfigStats"] - checkSchedulerStats := stats["checkSchedulerStats"] + aggregatorStats := stats["aggregatorStats"] s, err := checkstats.TranslateEventPlatformEventTypes(aggregatorStats) if err != nil { @@ -52,7 +48,6 @@ func FormatStatus(data []byte) (string, error) { logsStats := stats["logsStats"] dcaStats := stats["clusterAgentStatus"] endpointsInfos := stats["endpointsInfos"] - inventoriesStats := stats["inventories"] systemProbeStats := stats["systemProbeStats"] processAgentStatus := stats["processAgentStatus"] snmpTrapsStats := stats["snmpTrapsStats"] @@ -63,7 +58,7 @@ func FormatStatus(data []byte) (string, error) { var b = new(bytes.Buffer) headerFunc := func() error { return RenderStatusTemplate(b, "/header.tmpl", stats) } checkStatsFunc := func() error { - return renderChecksStats(b, runnerStats, pyLoaderStats, pythonInit, autoConfigStats, checkSchedulerStats, inventoriesStats, "") + return RenderStatusTemplate(b, "/collector.tmpl", stats) } jmxFetchFunc := func() error { return RenderStatusTemplate(b, "/jmxfetch.tmpl", stats) } forwarderFunc := func() error { return RenderStatusTemplate(b, "/forwarder.tmpl", forwarderStats) } @@ -146,9 +141,11 @@ func FormatDCAStatus(data []byte) (string, error) { } forwarderStats := stats["forwarderStats"] - runnerStats := stats["runnerStats"] - autoConfigStats := stats["autoConfigStats"] - checkSchedulerStats := stats["checkSchedulerStats"] + + stats["pyLoaderStats"] = nil + stats["pythonInit"] = nil + stats["checkMetadata"] = nil + endpointsInfos := stats["endpointsInfos"] logsStats := stats["logsStats"] orchestratorStats := stats["orchestrator"] @@ -160,7 +157,7 @@ func FormatDCAStatus(data []byte) (string, error) { if err := RenderStatusTemplate(b, "/header.tmpl", stats); err != nil { errs = append(errs, err) } - if err := renderChecksStats(b, runnerStats, nil, nil, autoConfigStats, checkSchedulerStats, nil, ""); err != nil { + if err := RenderStatusTemplate(b, "/collector.tmpl", stats); err != nil { errs = append(errs, err) } if err := RenderStatusTemplate(b, "/forwarder.tmpl", forwarderStats); err != nil { @@ -271,32 +268,15 @@ func FormatMetadataMapCLI(data []byte) (string, error) { return b.String(), nil } -func renderChecksStats(w io.Writer, runnerStats, pyLoaderStats, pythonInit, autoConfigStats, checkSchedulerStats, inventoriesStats interface{}, onlyCheck string) error { - checkStats := make(map[string]interface{}) - checkStats["RunnerStats"] = runnerStats - checkStats["pyLoaderStats"] = pyLoaderStats - checkStats["pythonInit"] = pythonInit - checkStats["AutoConfigStats"] = autoConfigStats - checkStats["CheckSchedulerStats"] = checkSchedulerStats - checkStats["OnlyCheck"] = onlyCheck - checkStats["CheckMetadata"] = inventoriesStats - return RenderStatusTemplate(w, "/collector.tmpl", checkStats) -} - func renderCheckStats(data []byte, checkName string) (string, error) { stats, renderError, err := unmarshalStatus(data) if renderError != "" || err != nil { return renderError, err } - runnerStats := stats["runnerStats"] - pyLoaderStats := stats["pyLoaderStats"] - pythonInit := stats["pythonInit"] - autoConfigStats := stats["autoConfigStats"] - checkSchedulerStats := stats["checkSchedulerStats"] - inventoriesStats := stats["inventories"] + var b = new(bytes.Buffer) var errs []error - if err := renderChecksStats(b, runnerStats, pyLoaderStats, pythonInit, autoConfigStats, checkSchedulerStats, inventoriesStats, checkName); err != nil { + if err := RenderStatusTemplate(b, "/collector.tmpl", stats); err != nil { errs = append(errs, err) } if err := renderErrors(b, errs); err != nil { diff --git a/pkg/status/templates/collector.tmpl b/pkg/status/templates/collector.tmpl index 056b2f49323d54..1bae9d08d679e4 100644 --- a/pkg/status/templates/collector.tmpl +++ b/pkg/status/templates/collector.tmpl @@ -18,7 +18,7 @@ Collector Running Checks ============== -{{- with .RunnerStats }} +{{- with .runnerStats }} {{- if and (not .Runs) (not .Checks)}} No checks have run yet {{end -}} @@ -43,10 +43,10 @@ Collector Average Execution Time : {{humanizeDuration .AverageExecutionTime "ms"}} Last Execution Date : {{formatUnixTime .UpdateTimestamp}} Last Successful Execution Date : {{ if .LastSuccessDate }}{{formatUnixTime .LastSuccessDate}}{{ else }}Never{{ end }} - {{- if $.CheckMetadata }} - {{- if index $.CheckMetadata .CheckID }} + {{- if $.checkMetadata }} + {{- if index $.checkMetadata .CheckID }} metadata: - {{- range $k, $v := index $.CheckMetadata .CheckID }} + {{- range $k, $v := index $.checkMetadata .CheckID }} {{ $k }}: {{ $v }} {{- end }} {{- end }} @@ -93,7 +93,7 @@ Collector {{- end }} {{- end }} -{{- with .AutoConfigStats }} +{{- with .autoConfigStats }} {{- if .ConfigErrors}} Config Errors ============== @@ -105,7 +105,7 @@ Collector {{- end}} {{- end }} -{{- with .CheckSchedulerStats }} +{{- with .checkSchedulerStats }} {{- if .LoaderErrors}} Loading Errors ==============