Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions comp/logs/agent/agentimpl/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
statusComponent "github.com/DataDog/datadog-agent/comp/core/status"
tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
healthplatform "github.com/DataDog/datadog-agent/comp/healthplatform/def"
"github.com/DataDog/datadog-agent/comp/logs/agent"
"github.com/DataDog/datadog-agent/comp/logs/agent/config"
flareController "github.com/DataDog/datadog-agent/comp/logs/agent/flare"
Expand Down Expand Up @@ -86,7 +85,6 @@ type dependencies struct {
SchedulerProviders []schedulers.Scheduler `group:"log-agent-scheduler"`
Tagger tagger.Component
Compression logscompression.Component
HealthPlatform option.Option[healthplatform.Component]
}

type provides struct {
Expand Down Expand Up @@ -124,7 +122,6 @@ type logAgent struct {
schedulerProviders []schedulers.Scheduler
integrationsLogs integrations.Component
compression logscompression.Component
healthPlatform option.Option[healthplatform.Component]

// make sure this is done only once, when we're ready
prepareSchedulers sync.Once
Expand Down Expand Up @@ -165,7 +162,6 @@ func newLogsAgent(deps dependencies) provides {
integrationsLogs: integrationsLogs,
tagger: deps.Tagger,
compression: deps.Compression,
healthPlatform: deps.HealthPlatform,
}
deps.Lc.Append(fx.Hook{
OnStart: logsAgent.start,
Expand Down
2 changes: 1 addition & 1 deletion comp/logs/agent/agentimpl/agent_core_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (a *logAgent) addLauncherInstances(lnchrs *launchers.Launchers, wmeta optio
lnchrs.AddLauncher(listener.NewLauncher(a.config.GetInt("logs_config.frame_size")))
lnchrs.AddLauncher(journald.NewLauncher(a.flarecontroller, a.tagger))
lnchrs.AddLauncher(windowsevent.NewLauncher())
lnchrs.AddLauncher(container.NewLauncher(a.sources, wmeta, a.tagger, a.healthPlatform))
lnchrs.AddLauncher(container.NewLauncher(a.sources, wmeta, a.tagger))
lnchrs.AddLauncher(integrationLauncher.NewLauncher(
afero.NewOsFs(),
a.sources, integrationsLogs))
Expand Down
6 changes: 0 additions & 6 deletions comp/logs/agent/agentimpl/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (
taggerfxmock "github.com/DataDog/datadog-agent/comp/core/tagger/fx-mock"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock"
healthplatform "github.com/DataDog/datadog-agent/comp/healthplatform/def"
healthplatformmock "github.com/DataDog/datadog-agent/comp/healthplatform/mock"
"github.com/DataDog/datadog-agent/comp/logs/agent/config"
auditor "github.com/DataDog/datadog-agent/comp/logs/auditor/def"
auditorfx "github.com/DataDog/datadog-agent/comp/logs/auditor/fx"
Expand All @@ -55,7 +53,6 @@ import (
logsStatus "github.com/DataDog/datadog-agent/pkg/logs/status"
"github.com/DataDog/datadog-agent/pkg/logs/tailers"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/DataDog/datadog-agent/pkg/util/option"
"github.com/DataDog/datadog-agent/pkg/util/testutil"
)

Expand Down Expand Up @@ -513,9 +510,6 @@ func (suite *AgentTestSuite) createDeps() dependencies {
}),
auditorfx.Module(),
fx.Provide(kubehealthmock.NewProvides),
fx.Provide(func() option.Option[healthplatform.Component] {
return option.New[healthplatform.Component](healthplatformmock.Mock(suite.T()))
}),
))
}

Expand Down
4 changes: 1 addition & 3 deletions comp/logs/agent/agentimpl/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"go.uber.org/fx"

healthplatform "github.com/DataDog/datadog-agent/comp/healthplatform/def"
"github.com/DataDog/datadog-agent/comp/logs/agent"
"github.com/DataDog/datadog-agent/pkg/logs/diagnostic"
"github.com/DataDog/datadog-agent/pkg/logs/pipeline"
Expand All @@ -27,8 +26,7 @@ import (
func MockModule() fxutil.Module {
return fxutil.Component(
fx.Provide(newMock),
fx.Provide(func(m agent.Mock) agent.Component { return m }),
fx.Supply(option.None[healthplatform.Component]()))
fx.Provide(func(m agent.Mock) agent.Component { return m }))
}

type mockLogsAgent struct {
Expand Down
16 changes: 6 additions & 10 deletions pkg/logs/launchers/container/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
healthplatform "github.com/DataDog/datadog-agent/comp/healthplatform/def"
auditor "github.com/DataDog/datadog-agent/comp/logs/auditor/def"
"github.com/DataDog/datadog-agent/pkg/logs/launchers"
"github.com/DataDog/datadog-agent/pkg/logs/launchers/container/tailerfactory"
Expand Down Expand Up @@ -61,18 +60,15 @@ type Launcher struct {
wmeta option.Option[workloadmeta.Component]

tagger tagger.Component

healthPlatform option.Option[healthplatform.Component]
}

// NewLauncher returns a new launcher
func NewLauncher(sources *sourcesPkg.LogSources, wmeta option.Option[workloadmeta.Component], tagger tagger.Component, healthPlatform option.Option[healthplatform.Component]) *Launcher {
func NewLauncher(sources *sourcesPkg.LogSources, wmeta option.Option[workloadmeta.Component], tagger tagger.Component) *Launcher {
launcher := &Launcher{
sources: sources,
tailers: make(map[*sourcesPkg.LogSource]tailerfactory.Tailer),
wmeta: wmeta,
tagger: tagger,
healthPlatform: healthPlatform,
sources: sources,
tailers: make(map[*sourcesPkg.LogSource]tailerfactory.Tailer),
wmeta: wmeta,
tagger: tagger,
}
return launcher
}
Expand All @@ -84,7 +80,7 @@ func (l *Launcher) Start(sourceProvider launchers.SourceProvider, pipelineProvid
l.cancel = cancel
l.stopped = make(chan struct{})

l.tailerFactory = tailerfactory.New(l.sources, pipelineProvider, registry, l.wmeta, l.tagger, l.healthPlatform)
l.tailerFactory = tailerfactory.New(l.sources, pipelineProvider, registry, l.wmeta, l.tagger)
go l.run(ctx, sourceProvider)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package container
import (
tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
healthplatform "github.com/DataDog/datadog-agent/comp/healthplatform/def"
auditor "github.com/DataDog/datadog-agent/comp/logs/auditor/def"
"github.com/DataDog/datadog-agent/pkg/logs/launchers"
"github.com/DataDog/datadog-agent/pkg/logs/pipeline"
Expand All @@ -26,7 +25,7 @@ import (
type Launcher struct{}

// NewLauncher returns a new launcher
func NewLauncher(_ *sourcesPkg.LogSources, _ option.Option[workloadmeta.Component], _ tagger.Component, _ option.Option[healthplatform.Component]) *Launcher {
func NewLauncher(_ *sourcesPkg.LogSources, _ option.Option[workloadmeta.Component], _ tagger.Component) *Launcher {
return &Launcher{}
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/logs/launchers/container/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

taggerfxmock "github.com/DataDog/datadog-agent/comp/core/tagger/fx-mock"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
healthplatform "github.com/DataDog/datadog-agent/comp/healthplatform/def"
"github.com/DataDog/datadog-agent/comp/logs/agent/config"
auditorMock "github.com/DataDog/datadog-agent/comp/logs/auditor/mock"
"github.com/DataDog/datadog-agent/pkg/logs/launchers"
Expand All @@ -41,7 +40,7 @@ func (tf *testFactory) MakeTailer(source *sources.LogSource) (tailerfactory.Tail
func TestStartStop(t *testing.T) {
fakeTagger := taggerfxmock.SetupFakeTagger(t)

l := NewLauncher(nil, option.None[workloadmeta.Component](), fakeTagger, option.None[healthplatform.Component]())
l := NewLauncher(nil, option.None[workloadmeta.Component](), fakeTagger)

sp := launchers.NewMockSourceProvider()
pl := pipeline.NewMockProvider()
Expand All @@ -61,7 +60,7 @@ func TestStartStop(t *testing.T) {
func TestAddsRemovesSource(t *testing.T) {
fakeTagger := taggerfxmock.SetupFakeTagger(t)

l := NewLauncher(nil, option.None[workloadmeta.Component](), fakeTagger, option.None[healthplatform.Component]())
l := NewLauncher(nil, option.None[workloadmeta.Component](), fakeTagger)
l.tailerFactory = &testFactory{
makeTailer: func(source *sources.LogSource) (tailerfactory.Tailer, error) {
return &tailerfactory.TestTailer{Name: source.Name}, nil
Expand Down Expand Up @@ -92,7 +91,7 @@ func TestAddsRemovesSource(t *testing.T) {
func TestCannotMakeTailer(t *testing.T) {
fakeTagger := taggerfxmock.SetupFakeTagger(t)

l := NewLauncher(nil, option.None[workloadmeta.Component](), fakeTagger, option.None[healthplatform.Component]())
l := NewLauncher(nil, option.None[workloadmeta.Component](), fakeTagger)
l.tailerFactory = &testFactory{
makeTailer: func(_ *sources.LogSource) (tailerfactory.Tailer, error) {
return nil, errors.New("uhoh")
Expand All @@ -115,7 +114,7 @@ func TestCannotMakeTailer(t *testing.T) {
func TestCannotStartTailer(t *testing.T) {
fakeTagger := taggerfxmock.SetupFakeTagger(t)

l := NewLauncher(nil, option.None[workloadmeta.Component](), fakeTagger, option.None[healthplatform.Component]())
l := NewLauncher(nil, option.None[workloadmeta.Component](), fakeTagger)
l.tailerFactory = &testFactory{
makeTailer: func(source *sources.LogSource) (tailerfactory.Tailer, error) {
return &tailerfactory.TestTailer{Name: source.Name, StartError: true}, nil
Expand Down
7 changes: 1 addition & 6 deletions pkg/logs/launchers/container/tailerfactory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package tailerfactory
import (
tagger "github.com/DataDog/datadog-agent/comp/core/tagger/def"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
healthplatform "github.com/DataDog/datadog-agent/comp/healthplatform/def"
auditor "github.com/DataDog/datadog-agent/comp/logs/auditor/def"
"github.com/DataDog/datadog-agent/pkg/logs/internal/util/containersorpods"
"github.com/DataDog/datadog-agent/pkg/logs/pipeline"
Expand Down Expand Up @@ -63,15 +62,12 @@ type factory struct {
dockerUtilGetter dockerUtilGetter

tagger tagger.Component

// healthPlatform is the health platform component for reporting issues
healthPlatform option.Option[healthplatform.Component]
}

var _ Factory = (*factory)(nil)

// New creates a new Factory.
func New(sources *sources.LogSources, pipelineProvider pipeline.Provider, registry auditor.Registry, workloadmetaStore option.Option[workloadmeta.Component], tagger tagger.Component, healthPlatform option.Option[healthplatform.Component]) Factory {
func New(sources *sources.LogSources, pipelineProvider pipeline.Provider, registry auditor.Registry, workloadmetaStore option.Option[workloadmeta.Component], tagger tagger.Component) Factory {
return &factory{
sources: sources,
pipelineProvider: pipelineProvider,
Expand All @@ -80,7 +76,6 @@ func New(sources *sources.LogSources, pipelineProvider pipeline.Provider, regist
cop: containersorpods.NewChooser(),
dockerUtilGetter: &dockerUtilGetterImpl{},
tagger: tagger,
healthPlatform: healthPlatform,
}
}

Expand Down
51 changes: 0 additions & 51 deletions pkg/logs/launchers/container/tailerfactory/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ import (
"context"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"runtime"
"syscall"

"github.com/DataDog/agent-payload/v5/healthplatform"

workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/comp/logs/agent/config"
Expand Down Expand Up @@ -127,19 +123,6 @@ func (tf *factory) makeDockerFileSource(source *sources.LogSource) (*sources.Log
// try to fall back to reading from a socket.
f, err := opener.OpenLogFile(path)
if err != nil {
// Check if this is a permission error and report to health platform
if isPermissionError(err) {
// Extract the base docker directory from the path
dockerDir := dockerLogsBasePathNix
if overridePath := pkgconfigsetup.Datadog().GetString("logs_config.docker_path_override"); len(overridePath) > 0 {
dockerDir = overridePath
} else if runtime.GOOS == "windows" {
dockerDir = dockerLogsBasePathWin
}

// Report the issue to health platform
tf.reportDockerPermissionIssue(dockerDir)
}
// (this error already has the form 'open <path>: ..' so needs no further embellishment)
return nil, err
}
Expand Down Expand Up @@ -339,37 +322,3 @@ func findK8sLogPath(pod *workloadmeta.KubernetesPod, containerName string) strin
log.Debugf("Using the latest kubernetes logs path for container %s", containerName)
return filepath.Join(podLogsBasePath, getPodDirectorySince1_14(pod), containerName, anyLogFile)
}

// isPermissionError checks if an error is permission-related using proper error type checking
func isPermissionError(err error) bool {
return errors.Is(err, fs.ErrPermission) ||
errors.Is(err, syscall.EACCES) ||
errors.Is(err, syscall.EPERM)
}

// reportDockerPermissionIssue reports a Docker file tailing permission issue to the health platform
func (tf *factory) reportDockerPermissionIssue(dockerDir string) {
hp, exists := tf.healthPlatform.Get()
if !exists {
return
}

// Report the issue with minimal context - health platform registry provides all metadata and remediation
err := hp.ReportIssue(
"logs-docker-file-permissions",
"Docker File Tailing Permissions",
&healthplatform.IssueReport{
IssueId: "docker-file-tailing-disabled",
Context: map[string]string{
"dockerDir": dockerDir,
"os": runtime.GOOS,
},
},
)

if err != nil {
log.Warnf("Failed to report Docker permission issue to health platform: %v", err)
} else {
log.Infof("Reported Docker file tailing permission issue to health platform")
}
}