Skip to content

Commit

Permalink
Render agent status using status component (#22115)
Browse files Browse the repository at this point in the history
Render agent status using status component

Co-authored-by: KevinFairise2 <kevin.fairise@datadoghq.com>
  • Loading branch information
GustavoCaso and KevinFairise2 authored Jan 25, 2024
1 parent 664558d commit 1f83d84
Show file tree
Hide file tree
Showing 114 changed files with 4,757 additions and 377 deletions.
2 changes: 2 additions & 0 deletions cmd/agent/subcommands/jmx/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/flare"
"github.com/DataDog/datadog-agent/comp/core/log/logimpl"
"github.com/DataDog/datadog-agent/comp/core/secrets"
"github.com/DataDog/datadog-agent/comp/core/status"
"github.com/DataDog/datadog-agent/comp/core/tagger"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta"
"github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors"
Expand Down Expand Up @@ -137,6 +138,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
fx.Provide(func() demultiplexer.Component { return nil }),
fx.Provide(func() inventorychecks.Component { return nil }),
fx.Provide(func() packagesigning.Component { return nil }),
fx.Provide(func() status.Component { return nil }),
fx.Provide(tagger.NewTaggerParamsForCoreAgent),
tagger.Module(),
)
Expand Down
46 changes: 46 additions & 0 deletions cmd/agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import (
"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/core/log/logimpl"
"github.com/DataDog/datadog-agent/comp/core/secrets"
"github.com/DataDog/datadog-agent/comp/core/status"
"github.com/DataDog/datadog-agent/comp/core/status/statusimpl"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
"github.com/DataDog/datadog-agent/comp/core/tagger"
Expand All @@ -57,6 +59,7 @@ import (
"github.com/DataDog/datadog-agent/comp/dogstatsd/replay"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
dogstatsddebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug"
dogstatsdStatusimpl "github.com/DataDog/datadog-agent/comp/dogstatsd/status/statusimpl"
"github.com/DataDog/datadog-agent/comp/forwarder"
"github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder"
orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl"
Expand All @@ -76,13 +79,17 @@ import (
netflowServer "github.com/DataDog/datadog-agent/comp/netflow/server"
"github.com/DataDog/datadog-agent/comp/otelcol"
otelcollector "github.com/DataDog/datadog-agent/comp/otelcol/collector"
processagentStatusImpl "github.com/DataDog/datadog-agent/comp/process/status/statusimpl"
"github.com/DataDog/datadog-agent/comp/remote-config/rcclient"
traceagentStatusImpl "github.com/DataDog/datadog-agent/comp/trace/status/statusimpl"
"github.com/DataDog/datadog-agent/pkg/api/healthprobe"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/providers"
"github.com/DataDog/datadog-agent/pkg/cloudfoundry/containertagger"
"github.com/DataDog/datadog-agent/pkg/collector"
"github.com/DataDog/datadog-agent/pkg/collector/check"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/embed/jmx"
"github.com/DataDog/datadog-agent/pkg/collector/corechecks/net"
"github.com/DataDog/datadog-agent/pkg/collector/python"
"github.com/DataDog/datadog-agent/pkg/commonchecks"
pkgconfig "github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/remote/data"
Expand All @@ -92,8 +99,16 @@ import (
"github.com/DataDog/datadog-agent/pkg/pidfile"
"github.com/DataDog/datadog-agent/pkg/serializer"
"github.com/DataDog/datadog-agent/pkg/snmp/traps"
snmpStatus "github.com/DataDog/datadog-agent/pkg/snmp/traps/status"
autodiscoveryStatus "github.com/DataDog/datadog-agent/pkg/status/autodiscovery"
clusteragentStatus "github.com/DataDog/datadog-agent/pkg/status/clusteragent"
collectorStatus "github.com/DataDog/datadog-agent/pkg/status/collector"
endpointsStatus "github.com/DataDog/datadog-agent/pkg/status/endpoints"
"github.com/DataDog/datadog-agent/pkg/status/health"
httpproxyStatus "github.com/DataDog/datadog-agent/pkg/status/httpproxy"
jmxStatus "github.com/DataDog/datadog-agent/pkg/status/jmx"
otlpStatus "github.com/DataDog/datadog-agent/pkg/status/otlp"
systemprobeStatus "github.com/DataDog/datadog-agent/pkg/status/systemprobe"
pkgTelemetry "github.com/DataDog/datadog-agent/pkg/telemetry"
"github.com/DataDog/datadog-agent/pkg/util"
pkgcommon "github.com/DataDog/datadog-agent/pkg/util/common"
Expand Down Expand Up @@ -189,6 +204,7 @@ func run(log log.Component,
_ langDetectionCl.Component,
agentAPI internalAPI.Component,
_ packagesigning.Component,
statusComponent status.Component,
) error {
defer func() {
stopAgent(cliParams, server, demultiplexer, agentAPI)
Expand Down Expand Up @@ -249,6 +265,7 @@ func run(log log.Component,
invAgent,
agentAPI,
invChecks,
statusComponent,
); err != nil {
return err
}
Expand Down Expand Up @@ -282,6 +299,34 @@ func getSharedFxOption() fx.Option {
collectors.GetCatalog(),
fx.Provide(defaults.DefaultParams),
workloadmeta.Module(),
fx.Supply(
status.Params{
PythonVersionGetFunc: func() string { return python.GetPythonVersion() },
},
status.NewInformationProvider(collectorStatus.Provider{}),
status.NewHeaderInformationProvider(net.Provider{}),
status.NewInformationProvider(jmxStatus.Provider{}),
status.NewInformationProvider(endpointsStatus.Provider{}),
),
fx.Provide(func(config config.Component) status.InformationProvider {
return status.NewInformationProvider(snmpStatus.GetProvider(config))
}),
fx.Provide(func(config config.Component) status.InformationProvider {
return status.NewInformationProvider(clusteragentStatus.GetProvider(config))
}),
fx.Provide(func(config config.Component) status.InformationProvider {
return status.NewInformationProvider(systemprobeStatus.GetProvider(config))
}),
fx.Provide(func(config config.Component) status.InformationProvider {
return status.NewInformationProvider(httpproxyStatus.GetProvider(config))
}),
fx.Provide(func(config config.Component) status.InformationProvider {
return status.NewInformationProvider(autodiscoveryStatus.GetProvider())
}),
traceagentStatusImpl.Module(),
processagentStatusImpl.Module(),
dogstatsdStatusimpl.Module(),
statusimpl.Module(),
apiimpl.Module(),

dogstatsd.Bundle(),
Expand Down Expand Up @@ -352,6 +397,7 @@ func startAgent(
invAgent inventoryagent.Component,
agentAPI internalAPI.Component,
invChecks inventorychecks.Component,
_ status.Component,
) error {

var err error
Expand Down
3 changes: 3 additions & 0 deletions cmd/agent/subcommands/run/command_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/core/log/logimpl"
"github.com/DataDog/datadog-agent/comp/core/secrets"
"github.com/DataDog/datadog-agent/comp/core/status"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
"github.com/DataDog/datadog-agent/comp/core/tagger"
Expand Down Expand Up @@ -104,6 +105,7 @@ func StartAgentWithDefaults(ctxChan <-chan context.Context) (<-chan error, error
_ netflowServer.Component,
agentAPI internalAPI.Component,
pkgSigning packagesigning.Component,
statusComponent status.Component,
) error {

defer StopAgentWithDefaults(server, demultiplexer, agentAPI)
Expand All @@ -127,6 +129,7 @@ func StartAgentWithDefaults(ctxChan <-chan context.Context) (<-chan error, error
invAgent,
agentAPI,
invChecks,
statusComponent,
)
if err != nil {
return err
Expand Down
13 changes: 7 additions & 6 deletions cmd/agent/subcommands/status/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
"github.com/DataDog/datadog-agent/pkg/api/util"
pkgconfig "github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/status/render"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/DataDog/datadog-agent/pkg/util/scrubber"

Expand Down Expand Up @@ -150,6 +149,12 @@ func requestStatus(config config.Component, cliParams *cliParams) error {
v.Set("verbose", "true")
}

if cliParams.prettyPrintJSON || cliParams.jsonStatus {
v.Set("format", "json")
} else {
v.Set("format", "text")
}

url := url.URL{
Scheme: "https",
Host: fmt.Sprintf("%v:%v", ipcAddress, config.GetInt("cmd_port")),
Expand All @@ -170,11 +175,7 @@ func requestStatus(config config.Component, cliParams *cliParams) error {
} else if cliParams.jsonStatus {
s = string(r)
} else {
formattedStatus, err := render.FormatStatus(r)
if err != nil {
return err
}
s = scrubMessage(formattedStatus)
s = scrubMessage(string(r))
}

if cliParams.statusFilePath != "" {
Expand Down
12 changes: 12 additions & 0 deletions comp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ Package serverdebug implements a component to run the dogstatsd server debug

Package statsd implements a component to get a statsd client.

### [comp/dogstatsd/status](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/dogstatsd/status)

Package status implements the core status component information provider interface

## [comp/etw](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/etw) (Component Bundle)

*Datadog Team*: windows-agent
Expand Down Expand Up @@ -323,6 +327,10 @@ Package rtcontainercheck implements a component to handle realtime Container dat

Package runner implements a component to run data collection checks in the Process Agent.

### [comp/process/status](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/process/status)

Package status implements the core status component information provider interface

### [comp/process/submitter](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/process/submitter)

Package submitter implements a component to submit collected data in the Process Agent to
Expand Down Expand Up @@ -362,3 +370,7 @@ Package trace implements the "trace" bundle, providing components for the Trace

Package config implements a component to handle trace-agent configuration. This
component temporarily wraps pkg/trace/config.

### [comp/trace/status](https://pkg.go.dev/github.com/DataDog/datadog-agent/comp/trace/status)

Package status implements the core status component information provider interface
10 changes: 8 additions & 2 deletions comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ package demultiplexerimpl
import (
"context"

"go.uber.org/fx"

demultiplexerComp "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer"
"github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager"
"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/core/status"
"github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder"
orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator"
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/DataDog/datadog-agent/pkg/util/hostname"
"go.uber.org/fx"
)

// Module defines the fx options for this component.
Expand Down Expand Up @@ -51,7 +53,8 @@ type provides struct {
// implements diagnosesendermanager.Component). This has the nice consequence of preventing having
// demultiplexerimpl.Module and diagnosesendermanagerimpl.Module in the same fx.App because there would
// be two ways to create diagnosesendermanager.Component.
SenderManager diagnosesendermanager.Component
SenderManager diagnosesendermanager.Component
StatusProvider status.InformationProvider
}

func newDemultiplexer(deps dependencies) (provides, error) {
Expand All @@ -78,6 +81,9 @@ func newDemultiplexer(deps dependencies) (provides, error) {
return provides{
Comp: demultiplexer,
SenderManager: demultiplexer,
StatusProvider: status.NewInformationProvider(demultiplexerStatus{
Log: deps.Log,
}),
}, nil
}

Expand Down
74 changes: 74 additions & 0 deletions comp/aggregator/demultiplexer/demultiplexerimpl/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-present Datadog, Inc.

// Package demultiplexerimpl defines the aggregator demultiplexer
package demultiplexerimpl

import (
"embed"
"encoding/json"
"expvar"
"io"

checkstats "github.com/DataDog/datadog-agent/pkg/collector/check/stats"

"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/core/status"
)

//go:embed status_templates
var templatesFS embed.FS

type demultiplexerStatus struct {
Log log.Component
}

func (d demultiplexerStatus) getStatusInfo() map[string]interface{} {
stats := make(map[string]interface{})

d.populateStatus(stats)

return stats
}

func (d demultiplexerStatus) populateStatus(stats map[string]interface{}) {
aggregatorStatsJSON := []byte(expvar.Get("aggregator").String())
aggregatorStats := make(map[string]interface{})
json.Unmarshal(aggregatorStatsJSON, &aggregatorStats) //nolint:errcheck
stats["aggregatorStats"] = aggregatorStats
s, err := checkstats.TranslateEventPlatformEventTypes(stats["aggregatorStats"])
if err != nil {
d.Log.Debugf("failed to translate event platform event types in aggregatorStats: %s", err.Error())
} else {
stats["aggregatorStats"] = s
}
}

// Name returns the name
func (d demultiplexerStatus) Name() string {
return "Aggregator"
}

// Section return the section
func (d demultiplexerStatus) Section() string {
return "aggregator"
}

// JSON populates the status map
func (d demultiplexerStatus) JSON(_ bool, stats map[string]interface{}) error {
d.populateStatus(stats)

return nil
}

// Text renders the text output
func (d demultiplexerStatus) Text(_ bool, buffer io.Writer) error {
return status.RenderText(templatesFS, "aggregator.tmpl", buffer, d.getStatusInfo())
}

// HTML renders the html output
func (d demultiplexerStatus) HTML(_ bool, buffer io.Writer) error {
return status.RenderHTML(templatesFS, "aggregatorHTML.tmpl", buffer, d.getStatusInfo())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{- with .aggregatorStats }}
{{- if .ChecksMetricSample }}
Checks Metric Sample: {{humanize .ChecksMetricSample}}
{{- end }}
{{- if .DogstatsdMetricSample}}
Dogstatsd Metric Sample: {{humanize .DogstatsdMetricSample}}
{{- end }}
{{- if .Event}}
Event: {{humanize .Event}}
{{- end }}
{{- if .EventsFlushed}}
Events Flushed: {{humanize .EventsFlushed}}
{{- end }}
{{- if .EventsFlushErrors}}
Events Flush Errors: {{humanize .EventsFlushErrors}}
{{- end }}
{{- if .NumberOfFlush}}
Number Of Flushes: {{humanize .NumberOfFlush}}
{{- end }}
{{- if .SeriesFlushed}}
Series Flushed: {{humanize .SeriesFlushed}}
{{- end }}
{{- if .SeriesFlushErrors}}
Series Flush Errors: {{humanize .SeriesFlushErrors}}
{{- end }}
{{- if .ServiceCheck}}
Service Check: {{humanize .ServiceCheck}}
{{- end }}
{{- if .ServiceCheckFlushed}}
Service Checks Flushed: {{humanize .ServiceCheckFlushed}}
{{- end }}
{{- if .ServiceCheckFlushErrors}}
Service Checks Flush Errors: {{humanize .ServiceCheckFlushErrors}}
{{- end }}
{{- if .SketchesFlushed}}
Sketches Flushed: {{humanize .SketchesFlushed}}
{{- end }}
{{- if .SketchesFlushErrors}}
Sketches Flush Errors: {{humanize .SketchesFlushErrors}}
{{- end }}
{{- if .ChecksHistogramBucketMetricSample }}
Checks Histogram Bucket Metric Sample: {{humanize .ChecksHistogramBucketMetricSample}}
{{- end }}
{{- if .EventPlatformEvents }}
{{- range $k, $v := .EventPlatformEvents }}
{{ $k }}: {{humanize $v}}
{{- end }}
{{- end }}
{{- if .HostnameUpdate}}
Hostname Update: {{humanize .HostnameUpdate}}
{{- end }}
{{- end }}
Loading

0 comments on commit 1f83d84

Please sign in to comment.