-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
{"baseBranch":"main","baseCommit":"fec0279bf16165ce57f6a5c62feb16ab81c5c287","createdAt":"2025-02-07T16:02:18.102740Z","headSha":"9c4ba04558deee740658b7353f447424b899b292","id":"a98d0ba7-79ba-46af-82be-1c72fd21d28b","priority":"200","pullRequestNumber":"33556","queuedAt":"2025-02-07T16:02:18.090674Z","status":"STATUS_QUEUED"}
- Loading branch information
Showing
9 changed files
with
212 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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 2025-present Datadog, Inc. | ||
|
||
// Package status implements the core status component information provider interface | ||
package status | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"go.uber.org/fx" | ||
|
||
"github.com/DataDog/datadog-agent/cmd/otel-agent/subcommands" | ||
"github.com/DataDog/datadog-agent/comp/api/authtoken/fetchonlyimpl" | ||
coreconfig "github.com/DataDog/datadog-agent/comp/core/config" | ||
log "github.com/DataDog/datadog-agent/comp/core/log/def" | ||
logfx "github.com/DataDog/datadog-agent/comp/core/log/fx" | ||
"github.com/DataDog/datadog-agent/comp/core/secrets" | ||
"github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" | ||
status "github.com/DataDog/datadog-agent/comp/otelcol/status/def" | ||
otelagentStatusfx "github.com/DataDog/datadog-agent/comp/otelcol/status/fx" | ||
"github.com/DataDog/datadog-agent/pkg/util/fxutil" | ||
"github.com/DataDog/datadog-agent/pkg/util/option" | ||
) | ||
|
||
type dependencies struct { | ||
fx.In | ||
|
||
Status status.Component | ||
} | ||
|
||
const headerText = "==========\nOTel Agent\n==========\n" | ||
|
||
// MakeCommand returns a `status` command to be used by agent binaries. | ||
func MakeCommand(globalConfGetter func() *subcommands.GlobalParams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "status", | ||
Short: "Print the current status", | ||
Long: ``, | ||
RunE: func(*cobra.Command, []string) error { | ||
globalParams := globalConfGetter() | ||
return fxutil.OneShot( | ||
runStatus, | ||
fx.Supply(coreconfig.NewAgentParams(globalParams.CoreConfPath, coreconfig.WithExtraConfFiles(globalParams.ConfPaths))), | ||
fx.Supply(option.None[secrets.Component]()), | ||
fx.Supply(secrets.NewEnabledParams()), | ||
fx.Supply(log.ForOneShot(globalParams.LoggerName, "off", true)), | ||
coreconfig.Module(), | ||
secretsimpl.Module(), | ||
logfx.Module(), | ||
fetchonlyimpl.Module(), | ||
otelagentStatusfx.Module(), | ||
) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runStatus(deps dependencies) error { | ||
statusText, err := deps.Status.GetStatus() | ||
if err != nil { | ||
return err | ||
} | ||
_, err = os.Stdout.Write([]byte(headerText + statusText)) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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 2025-present Datadog, Inc. | ||
|
||
package status | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/DataDog/datadog-agent/cmd/otel-agent/subcommands" | ||
"github.com/DataDog/datadog-agent/pkg/util/fxutil" | ||
) | ||
|
||
func newGlobalParamsTest(t *testing.T) *subcommands.GlobalParams { | ||
config := path.Join(t.TempDir(), "datadog.yaml") | ||
err := os.WriteFile(config, []byte("hostname: test"), 0644) | ||
require.NoError(t, err) | ||
return &subcommands.GlobalParams{ | ||
CoreConfPath: config, | ||
ConfPaths: []string{"test_config.yaml"}, | ||
} | ||
} | ||
|
||
func TestStatusCommand(t *testing.T) { | ||
globalConfGetter := func() *subcommands.GlobalParams { | ||
return newGlobalParamsTest(t) | ||
} | ||
fxutil.TestOneShotSubcommand(t, | ||
[]*cobra.Command{MakeCommand(globalConfGetter)}, | ||
[]string{"status"}, | ||
runStatus, | ||
func() {}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
http: | ||
endpoint: "localhost:4318" | ||
grpc: | ||
endpoint: "localhost:4317" | ||
|
||
exporters: | ||
datadog: | ||
api: | ||
key: "abc" | ||
|
||
service: | ||
pipelines: | ||
traces: | ||
receivers: [otlp] | ||
exporters: [datadog] | ||
telemetry: | ||
metrics: | ||
address: 127.0.0.1:8888 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters