-
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
Fix fx related issues for agenttelemetry improvements #29789
Changes from 3 commits
4b0e5b7
320605d
0f63b8a
e482bf1
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 |
---|---|---|
|
@@ -115,3 +115,13 @@ func TestShowMetadataSecurityAgentCommand(t *testing.T) { | |
require.Equal(t, false, secretParams.Enabled) | ||
}) | ||
} | ||
|
||
func TestShowAgentTelemetryCommand(t *testing.T) { | ||
fxutil.TestOneShotSubcommand(t, | ||
Commands(&command.GlobalParams{}), | ||
[]string{"diagnose", "show-metadata", "agent-telemetry"}, | ||
printPayload, | ||
func(_ core.BundleParams, secretParams secrets.Params) { | ||
require.Equal(t, false, secretParams.Enabled) | ||
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. ❓ question: What is the goal of this test ? 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. I would expect this test to check 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. @ogaca-dd @misteriaud fixed 😄 |
||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,32 +15,25 @@ package agenttelemetryimpl | |
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"go.uber.org/fx" | ||
"golang.org/x/exp/maps" | ||
|
||
api "github.com/DataDog/datadog-agent/comp/api/api/def" | ||
agenttelemetry "github.com/DataDog/datadog-agent/comp/core/agenttelemetry/def" | ||
"github.com/DataDog/datadog-agent/comp/core/config" | ||
log "github.com/DataDog/datadog-agent/comp/core/log/def" | ||
"github.com/DataDog/datadog-agent/comp/core/telemetry" | ||
"github.com/DataDog/datadog-agent/pkg/util/fxutil" | ||
compdef "github.com/DataDog/datadog-agent/comp/def" | ||
httputils "github.com/DataDog/datadog-agent/pkg/util/http" | ||
"github.com/DataDog/datadog-agent/pkg/util/scrubber" | ||
|
||
dto "github.com/prometheus/client_model/go" | ||
) | ||
|
||
// Module defines the fx options for this component. | ||
func Module() fxutil.Module { | ||
return fxutil.Component( | ||
fx.Provide(newAgentTelemetryProvider), | ||
) | ||
} | ||
|
||
type atel struct { | ||
cfgComp config.Component | ||
logComp log.Component | ||
|
@@ -55,21 +48,23 @@ type atel struct { | |
cancel context.CancelFunc | ||
} | ||
|
||
type provides struct { | ||
fx.Out | ||
// Provides defines the output of the agenttelemetry component | ||
type Provides struct { | ||
compdef.Out | ||
|
||
Comp agenttelemetry.Component | ||
Endpoint api.AgentEndpointProvider | ||
} | ||
|
||
type dependencies struct { | ||
fx.In | ||
// Requires declares the input types to the constructor | ||
type Requires struct { | ||
compdef.In | ||
|
||
Log log.Component | ||
Config config.Component | ||
Telemetry telemetry.Component | ||
|
||
Lc fx.Lifecycle | ||
Lc compdef.Lifecycle | ||
} | ||
|
||
// Interfacing with runner. | ||
|
@@ -142,7 +137,8 @@ func createAtel( | |
} | ||
} | ||
|
||
func newAgentTelemetryProvider(deps dependencies) provides { | ||
// NewComponent creates a new agent telemetry component. | ||
func NewComponent(deps Requires) Provides { | ||
a := createAtel( | ||
deps.Config, | ||
deps.Log, | ||
|
@@ -153,7 +149,7 @@ func newAgentTelemetryProvider(deps dependencies) provides { | |
|
||
// If agent telemetry is enabled and configured properly add the start and stop hooks | ||
if a.enabled { | ||
deps.Lc.Append(fx.Hook{ | ||
deps.Lc.Append(compdef.Hook{ | ||
OnStart: func(_ context.Context) error { | ||
return a.start() | ||
}, | ||
|
@@ -163,7 +159,7 @@ func newAgentTelemetryProvider(deps dependencies) provides { | |
}) | ||
} | ||
|
||
return provides{ | ||
return Provides{ | ||
Comp: a, | ||
Endpoint: api.NewAgentEndpointProvider(a.writePayload, "/metadata/agent-telemetry", "GET"), | ||
} | ||
|
@@ -376,6 +372,11 @@ func (a *atel) run(profiles []*Profile) { | |
} | ||
|
||
func (a *atel) writePayload(w http.ResponseWriter, _ *http.Request) { | ||
if !a.enabled { | ||
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 need to check id the feature is enable otherwise |
||
httputils.SetJSONError(w, errors.New("agent-telemetry is not enabled. Please enable agent telemetry"), 400) | ||
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. @iglendd I'm open to change the error message display to the users, maybe a link to the documentation would be nice |
||
return | ||
} | ||
|
||
a.logComp.Info("Dumping agent telemetry payload") | ||
|
||
payload, err := a.GetAsJSON() | ||
|
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.
Note: This is a breaking change. I guess this should be OK as the command is very new.
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.
It is not a breaking change as the command is not release yet. This PR uses this PR as the starting point #29770
The starting point PR hasn't being merge yet