Skip to content

Commit

Permalink
remove indirection for rendering the collector template
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Nov 8, 2023
1 parent ff86696 commit 90c8916
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 38 deletions.
4 changes: 2 additions & 2 deletions cmd/agent/gui/views/templates/collectorStatus.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
Average Execution Time : {{humanizeDuration .AverageExecutionTime "ms"}}<br>
Last Execution Date : {{formatUnixTime .UpdateTimestamp}}<br>
Last Successful Execution Date : {{ if .LastSuccessDate }}{{formatUnixTime .LastSuccessDate}}{{ else }}Never{{ end }}<br>
{{- if index $.Stats.inventories .CheckID }}
{{- if index $.Stats.checkMetadata .CheckID }}
Metadata:<br>
<span class="stat_subdata">
{{- range $k, $v := index $.Stats.inventories .CheckID }}
{{- range $k, $v := index $.Stats.checkMetadata .CheckID }}
{{ $k }}: {{ $v }}<br>
{{- end }}
</span>
Expand Down
40 changes: 10 additions & 30 deletions pkg/status/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"]
Expand All @@ -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) }
Expand Down Expand Up @@ -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"]
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions pkg/status/templates/collector.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Collector

Running Checks
==============
{{- with .RunnerStats }}
{{- with .runnerStats }}
{{- if and (not .Runs) (not .Checks)}}
No checks have run yet
{{end -}}
Expand All @@ -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 }}
Expand Down Expand Up @@ -93,7 +93,7 @@ Collector
{{- end }}
{{- end }}

{{- with .AutoConfigStats }}
{{- with .autoConfigStats }}
{{- if .ConfigErrors}}
Config Errors
==============
Expand All @@ -105,7 +105,7 @@ Collector
{{- end}}
{{- end }}

{{- with .CheckSchedulerStats }}
{{- with .checkSchedulerStats }}
{{- if .LoaderErrors}}
Loading Errors
==============
Expand Down

0 comments on commit 90c8916

Please sign in to comment.