Commit 64d2167
authored
[EXP-704] ecs: v1 metadata is not required for daemon mode on Managed Instances (#54174)
### What does this PR do?
Makes the ECS Metadata v1 introspection endpoint a best-effort dependency for ECS **Managed Instances** daemon mode instead of a hard startup requirement, and adds a task-metadata fallback for ECS cluster metadata.
Two changes:
1. `comp/core/workloadmeta/collectors/internal/ecs/daemon_parser.go` — `initializeDaemonMode` no longer returns early when `ecsmeta.V1()` or `GetInstance` fails. When v1 is unusable and the launch type is Managed Instances with a working v4 client, it routes to `parseTasksFromV4TasksEndpoint`. EC2 still fails, because both of its daemon parsers read the task list from `metaV1.GetTasks` — but it now fails with a retriable error so the collector is retried rather than dropped.
2. `pkg/util/ecs/ecs.go` — `newECSMeta` falls back from `getECSInstanceMetadata` (v1) to `getECSTaskMetadata` (v3/v4) on error, instead of only using task metadata on Fargate.
### Motivation
On Managed Instances, `initializeDaemonMode` called `ecsmeta.V1()` unconditionally before daemon mode could start, but the parser that actually runs there never consumes what v1 provides:
- **ClusterName / ClusterARN** — derived from each v4 task's own `Cluster` field in `util.ParseV4Task`
- **ContainerInstanceARN** — never set by `ParseV4Task` for any launch type, so it is already empty on this path
- **instance.Version** — only drives parser selection, and Managed Instances already has a fallback that keys off `ECS_CONTAINER_METADATA_URI_V4`
So a v1 failure blocked startup entirely, producing zero `ECSTask` entities and no `task_arn`, `task_family`, `task_version`, `ecs_cluster_name` or `ecs_container_name` tags on `container.*` metrics for the whole host — even though the v4 `/tasks` path works fine.
The second change fixes `GetClusterMeta()` which separate v1 call site that the collector fix does not touch, so the orchestrator ECS check stayed gated off:
```
Failed to get ECS meta: temporary failure in ecsutil-meta-v1 ...
Orchestrator ECS check is missing required information, region: , awsAccountID: , clusterName: , clusterID:
```
All four required values are available from the v4 task payload, and `initClusterID` is a pure `md5(account/region/cluster)` derivation, so the cluster ID is identical either way. This also unblocks the container lifecycle check's cluster ID and the flare's ECS section.
### Describe how you validated your changes
Unit tests (run in the Linux dev container, since the `docker` build tag is excluded on macOS by `DARWIN_EXCLUDED_TAGS`):
- `TestInitializeDaemonModeV1Unavailable` — Managed Instances starts and selects the v4 `/tasks` parser both when the v1 client fails to initialize and when `GetInstance` fails; EC2 fails in both cases; Managed Instances also fails when task collection is disabled or no v4 client is available. Asserts `taskCollectionParser` is never nil when `Start` succeeds, and that every error return satisfies `retry.IsErrWillRetry`.
- `TestInitializeDaemonModeV1Available` — a reachable v1 endpoint still populates `clusterName`/`containerInstanceARN` and selects the per-task v4 parser, unchanged for EC2.
- `TestNewECSMetaTaskMetadataFallback` — instance metadata used when available; falls back to task metadata on failure and produces the same cluster ID; surfaces the original v1 error when both fail.
```
dda inv test --targets=./comp/core/workloadmeta/collectors/internal/ecs # 69 tests pass
dda inv test --targets=./pkg/util/ecs # 47 tests pass
dda inv test --targets=./pkg/collector/corechecks/orchestrator/ecs,./pkg/collector/corechecks/containerlifecycle,./comp/core/tagger/collectors # 177 tests pass
dda inv linter.go --targets=./pkg/util/ecs,./comp/core/workloadmeta/collectors/internal/ecs # 0 issues
```
### Additional Notes
**The daemon-mode startup error has to be a `*retry.Error`.** `workloadmeta.startCandidates` keeps a collector in its candidate set only when `retry.IsErrWillRetry(err)` is true, and `retry.IsRetryError` type-asserts to `*retry.Error` instead of unwrapping. So wrapping with `fmt.Errorf("%w")` makes the error look non-retriable, and the collector is deleted from the candidate set — ECS task collection would then stay off until the Agent restarts. `initializeDaemonMode` returns a `*retry.Error` with `FailWillRetry`, keeping the original error as `LogicError` for context. This also makes the `GetInstance`-failure path retriable, where it previously returned `nil` and left a nil task parser that would be invoked on the first `Pull`. `TestInitializeDaemonModeV1Unavailable` asserts the retriable contract on every error path so it cannot regress silently.
**Launch types other than MI daemon are unaffected.** `metaV1` is referenced in exactly four places in the collector package: `daemon_parser.go` (init) and `v1parser.go` / `v4parser.go` (`GetTasks`). Sidecar mode uses `metaV2` and `metaV4` and never touches v1, so Fargate (always sidecar) and MI sidecar are untouched. EC2 daemon keeps its existing v1 requirement.
Co-authored-by: steve.zou <steve.zou@datadoghq.com>1 parent d38e9d0 commit 64d2167
7 files changed
Lines changed: 379 additions & 22 deletions
File tree
- comp/core/workloadmeta/collectors/internal/ecs
- pkg/util/ecs
- releasenotes/notes
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
Lines changed: 58 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
25 | 38 | | |
26 | 39 | | |
27 | 40 | | |
28 | | - | |
| 41 | + | |
29 | 42 | | |
30 | 43 | | |
31 | 44 | | |
| |||
36 | 49 | | |
37 | 50 | | |
38 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
39 | 58 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 59 | | |
49 | 60 | | |
50 | 61 | | |
| |||
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
59 | | - | |
| 70 | + | |
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
65 | | - | |
| 76 | + | |
66 | 77 | | |
67 | 78 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
73 | 85 | | |
74 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
75 | 107 | | |
76 | 108 | | |
77 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
78 | 118 | | |
79 | 119 | | |
80 | 120 | | |
| |||
Lines changed: 169 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| 21 | + | |
19 | 22 | | |
| 23 | + | |
20 | 24 | | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
| |||
166 | 171 | | |
167 | 172 | | |
168 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
24 | 31 | | |
25 | 32 | | |
26 | 33 | | |
| |||
80 | 87 | | |
81 | 88 | | |
82 | 89 | | |
83 | | - | |
| 90 | + | |
84 | 91 | | |
85 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
86 | 119 | | |
87 | 120 | | |
88 | 121 | | |
| |||
0 commit comments