Skip to content
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

remove hardcoded logs-agent component from API component #34890

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmd/agent/subcommands/jmx/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import (
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx"
logsAgent "github.com/DataDog/datadog-agent/comp/logs/agent"
integrations "github.com/DataDog/datadog-agent/comp/logs/integrations/def"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservice"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservicemrf"
Expand Down Expand Up @@ -150,7 +149,6 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
fx.Supply(option.None[rcservice.Component]()),
fx.Supply(option.None[rcservicemrf.Component]()),
fx.Supply(option.None[collector.Component]()),
fx.Supply(option.None[logsAgent.Component]()),
fx.Supply(option.None[integrations.Component]()),
fx.Provide(func() dogstatsdServer.Component { return nil }),
fx.Provide(func() pidmap.Component { return nil }),
Expand Down
4 changes: 0 additions & 4 deletions comp/api/api/apiimpl/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap"
replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/def"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
logsAgent "github.com/DataDog/datadog-agent/comp/logs/agent"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservice"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservicemrf"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
Expand All @@ -50,7 +49,6 @@ type apiServer struct {
authToken authtoken.Component
taggerComp tagger.Component
autoConfig autodiscovery.Component
logsAgentComp option.Option[logsAgent.Component]
wmeta workloadmeta.Component
collector option.Option[collector.Component]
senderManager diagnosesendermanager.Component
Expand All @@ -75,7 +73,6 @@ type dependencies struct {
Tagger tagger.Component
Cfg config.Component
AutoConfig autodiscovery.Component
LogsAgentComp option.Option[logsAgent.Component]
WorkloadMeta workloadmeta.Component
Collector option.Option[collector.Component]
DiagnoseSenderManager diagnosesendermanager.Component
Expand All @@ -99,7 +96,6 @@ func newAPIServer(deps dependencies) api.Component {
taggerComp: deps.Tagger,
cfg: deps.Cfg,
autoConfig: deps.AutoConfig,
logsAgentComp: deps.LogsAgentComp,
wmeta: deps.WorkloadMeta,
collector: deps.Collector,
senderManager: deps.DiagnoseSenderManager,
Expand Down
2 changes: 0 additions & 2 deletions comp/api/api/apiimpl/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap/pidmapimpl"
replaymock "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/fx-mock"
dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server"
logsAgent "github.com/DataDog/datadog-agent/comp/logs/agent"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservice"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservicemrf"

Expand Down Expand Up @@ -85,7 +84,6 @@ func getTestAPIServer(t *testing.T, params config.MockParams) testdeps {
fx.Provide(func(mock autodiscovery.Mock) autodiscovery.Component {
return mock
}),
fx.Supply(option.None[logsAgent.Component]()),
fx.Supply(option.None[collector.Component]()),
pidmapimpl.Module(),
// Ensure we pass a nil endpoint to test that we always filter out nil endpoints
Expand Down
12 changes: 0 additions & 12 deletions comp/api/api/apiimpl/internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

api "github.com/DataDog/datadog-agent/comp/api/api/def"
"github.com/DataDog/datadog-agent/comp/api/api/utils"
streamutils "github.com/DataDog/datadog-agent/comp/api/api/utils/stream"
"github.com/DataDog/datadog-agent/comp/collector/collector"
"github.com/DataDog/datadog-agent/comp/core/autodiscovery"
"github.com/DataDog/datadog-agent/comp/core/secrets"
Expand All @@ -28,7 +27,6 @@ import (
"github.com/DataDog/datadog-agent/pkg/util/option"

workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
logsAgent "github.com/DataDog/datadog-agent/comp/logs/agent"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/diagnose"
"github.com/DataDog/datadog-agent/pkg/diagnose/diagnosis"
Expand All @@ -40,7 +38,6 @@ import (
func SetupHandlers(
r *mux.Router,
wmeta workloadmeta.Component,
logsAgent option.Option[logsAgent.Component],
senderManager sender.DiagnoseSenderManager,
secretResolver secrets.Component,
collector option.Option[collector.Component],
Expand All @@ -63,10 +60,6 @@ func SetupHandlers(
getDiagnose(w, r, diagnoseDeps)
}).Methods("POST")

if logsAgent, ok := logsAgent.Get(); ok {
r.HandleFunc("/stream-logs", streamLogs(logsAgent)).Methods("POST")
}

return r
}

Expand All @@ -92,11 +85,6 @@ func componentStatusHandler(w http.ResponseWriter, r *http.Request) {
}
}

// TODO: logsAgent is a module so have to make the api component a module too
func streamLogs(logsAgent logsAgent.Component) func(w http.ResponseWriter, r *http.Request) {
return streamutils.GetStreamFunc(func() streamutils.MessageReceiver { return logsAgent.GetMessageReceiver() }, "logs", "logs agent")
}

func getHealth(w http.ResponseWriter, _ *http.Request) {
h := health.GetReady()

Expand Down
1 change: 0 additions & 1 deletion comp/api/api/apiimpl/internal/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func setupRoutes(t *testing.T) *mux.Router {
SetupHandlers(
router,
deps.Wmeta,
deps.LogsAgent,
sender,
deps.SecretResolver,
deps.Collector,
Expand Down
1 change: 0 additions & 1 deletion comp/api/api/apiimpl/server_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func (server *apiServer) startCMDServer(
agent.SetupHandlers(
agentMux,
server.wmeta,
server.logsAgentComp,
server.senderManager,
server.secretResolver,
server.collector,
Expand Down
14 changes: 14 additions & 0 deletions comp/logs/agent/agentimpl/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (
"context"
"errors"
"fmt"
"net/http"
"sync"
"time"

"github.com/hashicorp/go-multierror"
"go.uber.org/atomic"
"go.uber.org/fx"

api "github.com/DataDog/datadog-agent/comp/api/api/def"
apiutils "github.com/DataDog/datadog-agent/comp/api/api/utils/stream"
configComponent "github.com/DataDog/datadog-agent/comp/core/config"
flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types"
"github.com/DataDog/datadog-agent/comp/core/hostname"
Expand Down Expand Up @@ -94,6 +97,7 @@ type provides struct {
StatusProvider statusComponent.InformationProvider
RCListener rctypes.ListenerProvider
LogsReciever option.Option[integrations.Component]
APIStreamLogs api.AgentEndpointProvider
}

// logAgent represents the data pipeline that collects, decodes,
Expand Down Expand Up @@ -174,6 +178,10 @@ func newLogsAgent(deps dependencies) provides {
FlareProvider: flaretypes.NewProvider(logsAgent.flarecontroller.FillFlare),
RCListener: rcListener,
LogsReciever: option.New[integrations.Component](integrationsLogs),
APIStreamLogs: api.NewAgentEndpointProvider(streamLogsEvents(logsAgent),
"/stream-logs",
"POST",
),
}
}

Expand Down Expand Up @@ -408,3 +416,9 @@ func (a *logAgent) onUpdateSDS(reconfigType sds.ReconfigureOrderType, updates ma
}
}
}

func streamLogsEvents(logsAgent agent.Component) func(w http.ResponseWriter, r *http.Request) {
return apiutils.GetStreamFunc(func() apiutils.MessageReceiver {
return logsAgent.GetMessageReceiver()
}, "logs", "logs agent")
}
2 changes: 0 additions & 2 deletions pkg/cli/subcommands/check/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import (
"github.com/DataDog/datadog-agent/comp/forwarder/eventplatformreceiver/eventplatformreceiverimpl"
orchestratorForwarderImpl "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator/orchestratorimpl"
haagentfx "github.com/DataDog/datadog-agent/comp/haagent/fx"
logagent "github.com/DataDog/datadog-agent/comp/logs/agent"
integrations "github.com/DataDog/datadog-agent/comp/logs/integrations/def"
"github.com/DataDog/datadog-agent/comp/metadata/inventorychecks"
"github.com/DataDog/datadog-agent/comp/metadata/inventorychecks/inventorychecksimpl"
Expand Down Expand Up @@ -206,7 +205,6 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command {
// in others commands such as run.
fx.Supply(option.None[rcservice.Component]()),
fx.Supply(option.None[rcservicemrf.Component]()),
fx.Supply(option.None[logagent.Component]()),
fx.Supply(option.None[integrations.Component]()),
fx.Provide(func() server.Component { return nil }),
fx.Provide(func() replay.Component { return nil }),
Expand Down