Repository navigation
Conversation
|
This pull request does not have a backport label. Could you fix it @swiatekm? 🙏
|
This comment has been minimized.
This comment has been minimized.
|
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
| Snapshot: agentInfo.Snapshot(), | ||
| } | ||
| // The hostname the agent reports to Fleet, which honours ELASTIC_AGENT_HOSTNAME and the FQDN feature. | ||
| if ecsMeta, err := agentInfo.ECSMetadata(logger); err == nil { |
There was a problem hiding this comment.
I think this does a hostname lookup for every call, it might be better to do this once and then pass it in.
There was a problem hiding this comment.
It's a hostname lookup when generating otel collector configuration, which I think is roughly what we want? I'll see if I can centralize this more.
There was a problem hiding this comment.
Config changes are not that frequent, if we aren't worry about this blocking for 1m (I think that's the timeout) this is fine.
There was a problem hiding this comment.
I think the bigger question is actually whether a FQDN change should trigger a config reload, or if it should wait until the next one. Beats processes do the former, effectively, so this should probably be wired into the coordinator, which is the component in charge of when config is reloaded.
There was a problem hiding this comment.
I implemented it this way, but it adds some complexity to the coordinator. Notably, we need to know the hostname on the first configuration load, so the call blocking blocks that too. I gave the first call a 5s deadline and otherwise made the whole thing asynchronous.
Possible effects are delaying data collection by 5s if fetching the hostname is slow for some reason. This mostly affects FQDN, which already suffers from similar issues in beats, but it's still a larger change than I would've liked here.
This comment has been minimized.
This comment has been minimized.
| firstLookupDone = nil | ||
| } | ||
| select { | ||
| case <-fqdnChanged: |
There was a problem hiding this comment.
The hostname can change on its own can't it, shouldn't we periodically refresh it? I believe beats will pick up hostname changes, so this means the agent hostname would be out of sync with the one on the events.
There was a problem hiding this comment.
This is also what the host provider does, not sure there's a way to reuse it here, it seems kind of clunky because it's disabled unless a variable in the policy references.
Possibly another instance of it used here, not tied to vars? It even has the FQDN callback part of this already.
There was a problem hiding this comment.
In an ideal world, we'd have a singleton for this, but you can configure the check interval in the host provider, so the best we can probably do is a shared package containing the update logic. Then the coordinator could just use that. I'll open a new PR for that, it's only tangentially related to this change.
| } | ||
|
|
||
| statements := []any{ | ||
| fmt.Sprintf(`set(log.body["agent"], {%s}) where log.body["agent"] == nil`, strings.Join(agent, ", ")), |
There was a problem hiding this comment.
I think we still miss agent.id, agent.version and agent.type for Akamai here. The integration already sets agent.name (template), so the agent map exists before this processor runs. We would add elastic_agent.* but skip the missing agent fields too.
There was a problem hiding this comment.
In this case, I think Akamai will simply need to stop doing it after this change ships. In general, it's not clear what we should set if some of the fields already exist. There's a chance of producing nonsense.
| if features.IncludeTagsInEvents() { | ||
| tags = agentInfo.GetTags() | ||
| } |
There was a problem hiding this comment.
The coordinator can change the tags while the otel manager reads them here. I think this can race with AgentInfo.SetTags when include_tags_in_events is enabled. GetTags copies the slice, but it doesn't protect the read of i.tags.
|
This pull request is now in conflicts. Could you fix it? 🙏 |
|
This pull request is a draft, so it cannot be queued yet. Mark it as ready for review to get the box back. |
5e47808 to
9d55ef4
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The monitoring connector emits bodymap logs, so the agent metadata processor now adds agent.* and elastic_agent.* to the monitoring documents written by the test pipeline. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the agent and elastic_agent sections to bodymap log bodies as a whole, and only if the body doesn't have them yet, instead of setting individual fields. Identity set earlier, for example by another Elastic Agent before forwarding the logs, is kept as is. In TestHybridAgentE2E, the fbreceiver sets the agent section itself, so agent.id is ignored again and elastic_agent.* is compared instead. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Append the agent's tags to the tags of bodymap logs, the way Beats inputs do with add_tags, and under the same include_tags_in_events feature flag. Tags are added together with the elastic_agent section, so logs already handled by an Elastic Agent don't get tags from another one. AgentMetadata now embeds client.AgentInfo, and is built from the manager's agent info. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
The OTel manager adds the hostname from the shared host information as agent.name to bodymap logs. Watch the host information in the coordinator, and refresh the component model when the hostname changes, so the collector configuration uses the new hostname immediately, like Beats processes do. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
The agent metadata processor test in the EDOT module makes the elastic-agent-client, collector client and processortest modules direct dependencies. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
…s on all platforms staticcheck reports SA4006 for this test on some platforms only, so on the others nolintlint reported the directive as unused. The lint runs with --whole-files, so this fails any change to otel_test.go on Windows. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
9d55ef4 to
fb89d70
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Tests must restore the global paths with the pathstest helpers. Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
TL;DRThis failure is most likely a checkout/dependency-state issue (not a PR logic regression): Remediation
Investigation detailsRoot CauseConfiguration/infra state drift is indicated by two linked signals in the same build:
This pattern is consistent with building against an inconsistent Beats checkout/dependency state during CI. Evidence
Verification
Follow-up
What is this? | From workflow: Observability Agentic Workflow — Status Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
💚 Build Succeeded
History
cc @swiatekm |
Elastic Agent now injects a
transform/_agent-metadataprocessor at the end of everylogspipeline in the collector config that comes from the policy. The processor writes the agent's identity into the log body for logs in thebodymapmapping mode:The mapping mode is resolved the way the Elasticsearch exporter does it. The
elastic.mapping.modescope attribute wins, then theX-Elastic-Mapping-Modeclient metadata, compared case-insensitively. Logs in other mapping modes are not modified. Pipelines for beat receivers are not touched, because they already set this metadata via a beat processor.We need a hostname for this to work, and the hostname can change at runtime if the FQDN feature is on, so I added tracking this to the coordinator. Determining the hostname also blocks the coordinator for up to 5s at startup - we've seen similar things happen in beats. If the deadline is exceeded, we collect data without the hostname metadata attached.
Related issues
Risk
Rationale
Events from OTel-native receivers configured by Fleet policies (for example
akamai_siemandentityanalytics) have no Elastic Agent identity. Packages cannot add it themselves. Inbodymapmode the exporter writes only the log body, so resource attributes are dropped. Without these fields, Fleet's final pipeline setsevent.agent_id_statustomissing, and users cannot tell which agent collected a document.This is a partial fix for the issue: it covers logs in
bodymapmode only. Other mapping modes and signals are not covered.Rollout and safety
The processor uses
error_mode: ignore, so statement errors do not drop data. Downgrade should be safe because no persisted state or on-disk format changes. The diagnostics bundle should already include the merged collector config, which shows the injected processor.Testing
Tests added in this PR:
internal/pkg/otel/manager/agent_metadata_test.go. They cover the injected processor, idempotency, a missing hostname, no logs pipelines, andbuildMergedConfigskipping beat receiver pipelines.internal/edot/otelcol/agent_metadata_test.go. They run the real transform processor across mapping mode cases (scope attribute, request metadata, precedence, case-insensitivity, string and map bodies).testing/integration/ess/otel_test.gonow comparesagent.idandelastic_agent.*between the fbreceiver and beat documents.