-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ASCII-145] Update pkg/status/render
to only handle rendering logic
#20824
Changes from all commits
9616a2f
2ee0a06
6055861
aae22c9
fca2adb
48e9e0f
f2e164e
373769b
175e59d
8838c5e
f032730
3f8c310
2b5b4ae
dbf2346
a064b90
089acad
0db4d4d
31b5927
c797208
dffa6e8
6c8847a
05d8059
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -15,12 +15,7 @@ import ( | |||
"path" | ||||
"text/template" | ||||
|
||||
"github.com/DataDog/datadog-agent/comp/netflow/server" | ||||
"github.com/DataDog/datadog-agent/comp/otelcol/otlp" | ||||
checkstats "github.com/DataDog/datadog-agent/pkg/collector/check/stats" | ||||
"github.com/DataDog/datadog-agent/pkg/config" | ||||
"github.com/DataDog/datadog-agent/pkg/snmp/traps" | ||||
"github.com/DataDog/datadog-agent/pkg/util/log" | ||||
) | ||||
|
||||
var fmap = Textfmap() | ||||
|
@@ -31,28 +26,6 @@ func FormatStatus(data []byte) (string, error) { | |||
if renderError != "" || err != nil { | ||||
return renderError, err | ||||
} | ||||
forwarderStats := stats["forwarderStats"] | ||||
if forwarderStatsMap, ok := forwarderStats.(map[string]interface{}); ok { | ||||
forwarderStatsMap["config"] = stats["config"] | ||||
} else { | ||||
log.Warn("The Forwarder status format is invalid. Some parts of the `Forwarder` section may be missing.") | ||||
} | ||||
|
||||
aggregatorStats := stats["aggregatorStats"] | ||||
s, err := checkstats.TranslateEventPlatformEventTypes(aggregatorStats) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already call this function when fetching the status in the datadog-agent/pkg/status/status.go Line 335 in 30cff43
|
||||
if err != nil { | ||||
log.Debugf("failed to translate event platform event types in aggregatorStats: %s", err.Error()) | ||||
} else { | ||||
aggregatorStats = s | ||||
} | ||||
dogstatsdStats := stats["dogstatsdStats"] | ||||
logsStats := stats["logsStats"] | ||||
dcaStats := stats["clusterAgentStatus"] | ||||
endpointsInfos := stats["endpointsInfos"] | ||||
systemProbeStats := stats["systemProbeStats"] | ||||
processAgentStatus := stats["processAgentStatus"] | ||||
snmpTrapsStats := stats["snmpTrapsStats"] | ||||
netflowStats := stats["netflowStats"] | ||||
title := fmt.Sprintf("Agent (v%s)", stats["version"]) | ||||
stats["title"] = title | ||||
|
||||
|
@@ -62,55 +35,20 @@ func FormatStatus(data []byte) (string, error) { | |||
return renderStatusTemplate(b, "/collector.tmpl", stats) | ||||
} | ||||
jmxFetchFunc := func() error { return renderStatusTemplate(b, "/jmxfetch.tmpl", stats) } | ||||
forwarderFunc := func() error { return renderStatusTemplate(b, "/forwarder.tmpl", forwarderStats) } | ||||
endpointsFunc := func() error { return renderStatusTemplate(b, "/endpoints.tmpl", endpointsInfos) } | ||||
logsAgentFunc := func() error { return renderStatusTemplate(b, "/logsagent.tmpl", logsStats) } | ||||
systemProbeFunc := func() error { | ||||
if systemProbeStats != nil { | ||||
return renderStatusTemplate(b, "/systemprobe.tmpl", systemProbeStats) | ||||
} | ||||
return nil | ||||
} | ||||
processAgentFunc := func() error { return renderStatusTemplate(b, "/process-agent.tmpl", processAgentStatus) } | ||||
traceAgentFunc := func() error { return renderStatusTemplate(b, "/trace-agent.tmpl", stats["apmStats"]) } | ||||
aggregatorFunc := func() error { return renderStatusTemplate(b, "/aggregator.tmpl", aggregatorStats) } | ||||
dogstatsdFunc := func() error { return renderStatusTemplate(b, "/dogstatsd.tmpl", dogstatsdStats) } | ||||
clusterAgentFunc := func() error { | ||||
if config.Datadog.GetBool("cluster_agent.enabled") || config.Datadog.GetBool("cluster_checks.enabled") { | ||||
return renderStatusTemplate(b, "/clusteragent.tmpl", dcaStats) | ||||
} | ||||
return nil | ||||
} | ||||
snmpTrapFunc := func() error { | ||||
if traps.IsEnabled(config.Datadog) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move that check to |
||||
return renderStatusTemplate(b, "/snmp-traps.tmpl", snmpTrapsStats) | ||||
} | ||||
return nil | ||||
} | ||||
|
||||
netflowFunc := func() error { | ||||
if server.IsEnabled() { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move that check to |
||||
return renderStatusTemplate(b, "/netflow.tmpl", netflowStats) | ||||
} | ||||
return nil | ||||
} | ||||
|
||||
autodiscoveryFunc := func() error { | ||||
if config.IsContainerized() { | ||||
return renderAutodiscoveryStats(b, stats["adEnabledFeatures"], stats["adConfigErrors"], | ||||
stats["filterErrors"]) | ||||
} | ||||
return nil | ||||
} | ||||
remoteConfigFunc := func() error { | ||||
return renderStatusTemplate(b, "/remoteconfig.tmpl", stats) | ||||
} | ||||
otlpFunc := func() error { | ||||
if otlp.IsDisplayed() { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move that check to |
||||
return renderStatusTemplate(b, "/otlp.tmpl", stats) | ||||
} | ||||
return nil | ||||
} | ||||
forwarderFunc := func() error { return renderStatusTemplate(b, "/forwarder.tmpl", stats) } | ||||
endpointsFunc := func() error { return renderStatusTemplate(b, "/endpoints.tmpl", stats) } | ||||
logsAgentFunc := func() error { return renderStatusTemplate(b, "/logsagent.tmpl", stats) } | ||||
systemProbeFunc := func() error { return renderStatusTemplate(b, "/systemprobe.tmpl", stats) } | ||||
processAgentFunc := func() error { return renderStatusTemplate(b, "/process-agent.tmpl", stats) } | ||||
traceAgentFunc := func() error { return renderStatusTemplate(b, "/trace-agent.tmpl", stats) } | ||||
aggregatorFunc := func() error { return renderStatusTemplate(b, "/aggregator.tmpl", stats) } | ||||
dogstatsdFunc := func() error { return renderStatusTemplate(b, "/dogstatsd.tmpl", stats) } | ||||
clusterAgentFunc := func() error { return renderStatusTemplate(b, "/clusteragent.tmpl", stats) } | ||||
snmpTrapFunc := func() error { return renderStatusTemplate(b, "/snmp-traps.tmpl", stats) } | ||||
netflowFunc := func() error { return renderStatusTemplate(b, "/netflow.tmpl", stats) } | ||||
autodiscoveryFunc := func() error { return renderStatusTemplate(b, "/autodiscovery.tmpl", stats) } | ||||
remoteConfigFunc := func() error { return renderStatusTemplate(b, "/remoteconfig.tmpl", stats) } | ||||
otlpFunc := func() error { return renderStatusTemplate(b, "/otlp.tmpl", stats) } | ||||
|
||||
var renderFuncs []func() error | ||||
if config.IsCLCRunner() { | ||||
|
@@ -141,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 | ||||
|
||||
|
@@ -160,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) | ||||
|
@@ -209,9 +141,7 @@ func FormatSecurityAgentStatus(data []byte) (string, error) { | |||
if renderError != "" || err != nil { | ||||
return renderError, err | ||||
} | ||||
runnerStats := stats["runnerStats"] | ||||
complianceChecks := stats["complianceChecks"] | ||||
complianceStatus := stats["complianceStatus"] | ||||
|
||||
title := fmt.Sprintf("Datadog Security Agent (v%s)", stats["version"]) | ||||
stats["title"] = title | ||||
|
||||
|
@@ -220,10 +150,10 @@ func FormatSecurityAgentStatus(data []byte) (string, error) { | |||
if err := renderStatusTemplate(b, "/header.tmpl", stats); err != nil { | ||||
errs = append(errs, err) | ||||
} | ||||
if err := renderRuntimeSecurityStats(b, stats["runtimeSecurityStatus"]); err != nil { | ||||
if err := renderStatusTemplate(b, "/runtimesecurity.tmpl", stats); err != nil { | ||||
errs = append(errs, err) | ||||
} | ||||
if err := renderComplianceChecksStats(b, runnerStats, complianceChecks, complianceStatus); err != nil { | ||||
if err := renderStatusTemplate(b, "/compliance.tmpl", stats); err != nil { | ||||
errs = append(errs, err) | ||||
} | ||||
if err := renderErrors(b, errs); err != nil { | ||||
|
@@ -287,28 +217,6 @@ func FormatCheckStats(data []byte) (string, error) { | |||
return b.String(), nil | ||||
} | ||||
|
||||
func renderComplianceChecksStats(w io.Writer, runnerStats interface{}, complianceChecks, complianceStatus interface{}) error { | ||||
checkStats := make(map[string]interface{}) | ||||
checkStats["RunnerStats"] = runnerStats | ||||
checkStats["ComplianceStatus"] = complianceStatus | ||||
checkStats["ComplianceChecks"] = complianceChecks | ||||
return renderStatusTemplate(w, "/compliance.tmpl", checkStats) | ||||
} | ||||
|
||||
func renderRuntimeSecurityStats(w io.Writer, runtimeSecurityStatus interface{}) error { | ||||
status := make(map[string]interface{}) | ||||
status["RuntimeSecurityStatus"] = runtimeSecurityStatus | ||||
return renderStatusTemplate(w, "/runtimesecurity.tmpl", status) | ||||
} | ||||
|
||||
func renderAutodiscoveryStats(w io.Writer, adEnabledFeatures interface{}, adConfigErrors interface{}, filterErrors interface{}) error { | ||||
autodiscoveryStats := make(map[string]interface{}) | ||||
autodiscoveryStats["adEnabledFeatures"] = adEnabledFeatures | ||||
autodiscoveryStats["adConfigErrors"] = adConfigErrors | ||||
autodiscoveryStats["filterErrors"] = filterErrors | ||||
return renderStatusTemplate(w, "/autodiscovery.tmpl", autodiscoveryStats) | ||||
} | ||||
|
||||
//go:embed templates | ||||
var templatesFS embed.FS | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
|
||
{{- with .clusterAgentStatus -}} | ||
===================== | ||
Datadog Cluster Agent | ||
===================== | ||
{{ if .DetectionError }} | ||
- Could not detect the Datadog Cluster Agent's endpoint: {{ .DetectionError }} | ||
{{ else }} | ||
- Datadog Cluster Agent endpoint detected: {{ .Endpoint }} | ||
{{- end }} | ||
{{- if .ConnectionError }} | ||
- Could not reach the Datadog Cluster Agent: {{ .ConnectionError }} | ||
{{- end }} | ||
{{- if not .Version }} | ||
- Could not retrieve the version of the Datadog Cluster Agent. | ||
{{ else }} | ||
Successfully connected to the Datadog Cluster Agent. | ||
- Running: {{ .Version }} | ||
{{- end }} | ||
{{ if .DetectionError }} | ||
- Could not detect the Datadog Cluster Agent's endpoint: {{ .DetectionError }} | ||
{{ else }} | ||
- Datadog Cluster Agent endpoint detected: {{ .Endpoint }} | ||
{{- end }} | ||
{{- if .ConnectionError }} | ||
- Could not reach the Datadog Cluster Agent: {{ .ConnectionError }} | ||
{{- end }} | ||
{{- if not .Version }} | ||
- Could not retrieve the version of the Datadog Cluster Agent. | ||
{{ else }} | ||
Successfully connected to the Datadog Cluster Agent. | ||
- Running: {{ .Version }} | ||
{{- end }} | ||
{{- end -}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
{{/* | ||
NOTE: Changes made to this template should be reflected on the following templates, if applicable: | ||
* cmd/agent/gui/views/templates/generalStatus.tmpl | ||
* Dockerfiles/cluster-agent/dist/templates/forwarder.tmpl | ||
hush-hush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/}}========== | ||
Endpoints | ||
========== | ||
|
||
{{- with .}} | ||
{{- range $key, $value := .}} | ||
{{$key}} - API Key{{ if gt (len $value) 1}}s{{end}} ending with: | ||
{{- with .endpointsInfos -}} | ||
{{ range $key, $value := .}} | ||
{{$key}} - API Key{{ if gt (len $value) 1}}s{{end}} ending with: | ||
{{- range $idx, $apikey := $value }} | ||
- {{$apikey}} | ||
{{- end}} | ||
{{- end}} | ||
{{- else }} | ||
|
||
No endpoints information. The agent may be misconfigured. | ||
{{- end }} | ||
No endpoints information. The agent may be misconfigured. | ||
{{end }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I aggregated all forwarded stats within the same function when fetching the status.
datadog-agent/pkg/status/status.go
Lines 320 to 327 in 30cff43