Skip to content

Commit

Permalink
update FormatDCAStatus to unify stats access withint the templates an…
Browse files Browse the repository at this point in the history
…d move config check outside of the render package
  • Loading branch information
GustavoCaso committed Nov 17, 2023
1 parent 2d39a6b commit f18ca9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
24 changes: 9 additions & 15 deletions pkg/status/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,11 @@ func FormatDCAStatus(data []byte) (string, error) {
return renderError, err
}

forwarderStats := stats["forwarderStats"]
// We nil these keys because we do not want to display that information in the collector template
stats["pyLoaderStats"] = nil
stats["pythonInit"] = nil
stats["inventories"] = nil
endpointsInfos := stats["endpointsInfos"]
logsStats := stats["logsStats"]
orchestratorStats := stats["orchestrator"]

title := fmt.Sprintf("Datadog Cluster Agent (v%s)", stats["version"])
stats["title"] = title

Expand All @@ -98,24 +95,21 @@ func FormatDCAStatus(data []byte) (string, error) {
if err := renderStatusTemplate(b, "/collector.tmpl", stats); err != nil {
errs = append(errs, err)
}
if err := renderStatusTemplate(b, "/forwarder.tmpl", forwarderStats); err != nil {
if err := renderStatusTemplate(b, "/forwarder.tmpl", stats); err != nil {
errs = append(errs, err)
}
if err := renderStatusTemplate(b, "/endpoints.tmpl", endpointsInfos); err != nil {
if err := renderStatusTemplate(b, "/endpoints.tmpl", stats); err != nil {
errs = append(errs, err)
}
if config.Datadog.GetBool("compliance_config.enabled") {
if err := renderStatusTemplate(b, "/logsagent.tmpl", logsStats); err != nil {
errs = append(errs, err)
}
if err := renderStatusTemplate(b, "/logsagent.tmpl", stats); err != nil {
errs = append(errs, err)
}
if err := renderAutodiscoveryStats(b, stats["adEnabledFeatures"], stats["adConfigErrors"], stats["filterErrors"]); err != nil {
if err := renderStatusTemplate(b, "/autodiscovery.tmpl", stats); err != nil {
errs = append(errs, err)
}
if config.Datadog.GetBool("orchestrator_explorer.enabled") {
if err := renderStatusTemplate(b, "/orchestrator.tmpl", orchestratorStats); err != nil {
errs = append(errs, err)
}

if err := renderStatusTemplate(b, "/orchestrator.tmpl", stats); err != nil {
errs = append(errs, err)
}
if err := renderErrors(b, errs); err != nil {
fmt.Println(err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/status/render/templates/orchestrator.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{/*
*/}}
{{ with .orchestrator }}
=====================
Orchestrator Explorer
=====================
Expand Down Expand Up @@ -94,3 +95,4 @@ Orchestrator Explorer
{{- end}}
{{- end}}
{{- end}}
{{ end }}
4 changes: 3 additions & 1 deletion pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ func GetDCAStatus(verbose bool) (map[string]interface{}, error) {
stats["config"] = getDCAPartialConfig()
stats["leaderelection"] = getLeaderElectionDetails()

stats["logsStats"] = logsStatus.Get(verbose)
if config.Datadog.GetBool("compliance_config.enabled") {
stats["logsStats"] = logsStatus.Get(verbose)
}

endpointsInfos, err := getEndpointsInfos()
if endpointsInfos != nil && err == nil {
Expand Down

0 comments on commit f18ca9c

Please sign in to comment.