Skip to content

Commit 8d12780

Browse files
committed
[anomalydetection] gate recorder on python build tag (mirror observer)
Move recorder/fx-noop into recorder/fx/fx_noop.go with //go:build !python, and add //go:build python to recorder/fx/fx.go. Same package, mutually exclusive build tags — Go and Bazel rules_go pick the right Module() implementation per flavor. This matches the pattern observer (#50430) and logssource use: the "python" tag is a proxy for "full agent, not IoT agent" — same import path everywhere, build system decides whether arrow-go gets linked. Result by flavor: - agent_* / docker_agent_* (have python): real fx.go, arrow-go linked, recorder operational at runtime when recording.enabled=true. - iot_agent_* / dogstatsd_* / cluster_agent_* (no python): fx_noop.go, empty fx options, no arrow-go in dep closure. Resolves the worst static-quality-gate failures on iot_agent flavors (+37-43% increase becomes 0). agent_* flavors still ship arrow-go and need a size-gate exception filed separately — that is the unavoidable cost of "recorder must run inside the agent at runtime", which is by design (observer #50599 declares Recorder option.Option[Component]). Also removes the now-redundant recorder/fx-noop and recorder/impl-noop directories; cmd/agent's recorderfx import is unchanged.
1 parent b757055 commit 8d12780

9 files changed

Lines changed: 45 additions & 96 deletions

File tree

comp/anomalydetection/observer/AGENTS.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ comp/anomalydetection/
3737
impl/
3838
impl-testbench/
3939
mock/
40-
recorder/ ← parquet recorder for scenario capture
40+
recorder/ ← parquet recorder for live scenario capture
4141
def/
42-
fx/ ← full implementation (parquet, heavy deps)
43-
fx-noop/ ← stub wired in the main agent build
42+
fx/ ← fx.go (//go:build python) + fx_noop.go (//go:build !python)
4443
impl/
45-
impl-noop/
4644
```
4745

48-
The **production agent** wires `reporter/fx-noop` and `recorder/fx-noop` to
49-
keep those heavy dependencies out of the agent binary. The
50-
**testbench** (`internal/qbranch/anomalydetection-testbench/`) wires the full
51-
`fx` + `impl` variants.
46+
The recorder is gated on the `python` build tag, used as a proxy for "full
47+
agent, not IoT agent" — same pattern as `observer/fx`. Full agent and
48+
docker agent flavors compile `recorder/fx/fx.go` and link `apache/arrow-go`;
49+
IoT, dogstatsd-only, cluster-agent, and serverless flavors compile
50+
`recorder/fx/fx_noop.go` and ship no parquet dependencies. The reporter
51+
component still uses a separate `reporter/fx-noop` package for now.
5252

5353
## Architecture
5454

comp/anomalydetection/recorder/fx-noop/BUILD.bazel

Lines changed: 0 additions & 14 deletions
This file was deleted.

comp/anomalydetection/recorder/fx-noop/fx_noop.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

comp/anomalydetection/recorder/fx/BUILD.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ load("@rules_go//go:def.bzl", "go_library")
22

33
go_library(
44
name = "fx",
5-
srcs = ["fx.go"],
5+
srcs = [
6+
"fx.go",
7+
"fx_noop.go",
8+
],
69
importpath = "github.com/DataDog/datadog-agent/comp/anomalydetection/recorder/fx",
710
visibility = ["//visibility:public"],
811
deps = [
912
"//comp/anomalydetection/recorder/def",
1013
"//comp/anomalydetection/recorder/impl",
1114
"//pkg/util/fxutil",
15+
"@org_uber_go_fx//:fx",
1216
],
1317
)

comp/anomalydetection/recorder/fx/fx.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6+
// The `python` build tag is used here as a proxy for "full agent, not IoT agent".
7+
// See comp/anomalydetection/recorder/fx/fx_noop.go for the stub used in IoT agent
8+
// and other size-sensitive builds, which avoids linking apache/arrow-go.
9+
10+
//go:build python
11+
612
// Package fx provides the fx module for the recorder component.
7-
// Wire this module when full parquet recording is needed (e.g. in the testbench).
8-
// For the main agent build, use recorder/fx-noop instead.
913
package fx
1014

1115
import (
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
//go:build !python
7+
8+
// Package fx provides the fx module for the recorder component.
9+
package fx
10+
11+
import (
12+
"go.uber.org/fx"
13+
14+
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
15+
)
16+
17+
// Module is a no-op for builds without Python support (e.g. IoT agent).
18+
// Returning empty fx options avoids linking apache/arrow-go into binaries
19+
// that do not need parquet recording. Consumers of recorder.Component are
20+
// expected to gate on the same `python` tag — see observer/fx for the
21+
// matching shape that ensures observer's optional Recorder dependency is
22+
// only declared when the real recorder Module is wired.
23+
func Module() fxutil.Module {
24+
return fxutil.Module{Option: fx.Options()}
25+
}

comp/anomalydetection/recorder/fx/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/DataDog/datadog-agent/comp/anomalydetection/recorder/def v0.0.0-00010101000000-000000000000
77
github.com/DataDog/datadog-agent/comp/anomalydetection/recorder/impl v0.0.0-00010101000000-000000000000
88
github.com/DataDog/datadog-agent/pkg/util/fxutil v0.73.0-rc.5
9+
go.uber.org/fx v1.24.0
910
)
1011

1112
require (
@@ -90,7 +91,6 @@ require (
9091
go.opentelemetry.io/otel/trace v1.43.0 // indirect
9192
go.uber.org/atomic v1.11.0 // indirect
9293
go.uber.org/dig v1.19.0 // indirect
93-
go.uber.org/fx v1.24.0 // indirect
9494
go.uber.org/multierr v1.11.0 // indirect
9595
go.uber.org/zap v1.28.0 // indirect
9696
go.yaml.in/yaml/v2 v2.4.4 // indirect

comp/anomalydetection/recorder/impl-noop/BUILD.bazel

Lines changed: 0 additions & 12 deletions
This file was deleted.

comp/anomalydetection/recorder/impl-noop/recorder.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)