fix: stamp environment on agent_events rows
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m28s
CI / docker (push) Successful in 1m13s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Successful in 43s

The agent_events table has an `environment` column and AgentEventsController
filters on it, but the INSERT never populated it — every row got the
column default ('default'). Result: Timeline on the Application Runtime
page was empty whenever the user's selected env was anything other than
'default'.

Thread env through the write path:
- AgentEventRepository.insert + AgentEventService.recordEvent gain an
  `environment` param; delete the no-env query overload (unused).
- ClickHouseAgentEventRepository.insert writes the column (falls back to
  'default' on null to match column DEFAULT).
- All 5 callers source env from the agent registry (AgentInfo.environmentId)
  or the registration request body; AgentLifecycleMonitor, deregister,
  command ack, event ingestion, register/re-register.
- Integration test updated for the new signatures.

Pre-existing rows in deployed CH will still report environment='default'.
New events from this build forward will carry the correct env. Backfill
(UPDATE ... FROM apps) is left as a manual DB step if historical timeline
is needed for non-default envs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-17 10:30:56 +02:00
parent 5807cfd807
commit 62dd71b860
8 changed files with 35 additions and 41 deletions

View File

@@ -5,9 +5,7 @@ import java.util.List;
public interface AgentEventRepository {
void insert(String instanceId, String applicationId, String eventType, String detail);
List<AgentEventRecord> query(String applicationId, String instanceId, Instant from, Instant to, int limit);
void insert(String instanceId, String applicationId, String environment, String eventType, String detail);
List<AgentEventRecord> query(String applicationId, String instanceId, String environment, Instant from, Instant to, int limit);
}

View File

@@ -16,13 +16,9 @@ public class AgentEventService {
this.repository = repository;
}
public void recordEvent(String instanceId, String applicationId, String eventType, String detail) {
log.debug("Recording agent event: instance={}, app={}, type={}", instanceId, applicationId, eventType);
repository.insert(instanceId, applicationId, eventType, detail);
}
public List<AgentEventRecord> queryEvents(String applicationId, String instanceId, Instant from, Instant to, int limit) {
return repository.query(applicationId, instanceId, from, to, limit);
public void recordEvent(String instanceId, String applicationId, String environment, String eventType, String detail) {
log.debug("Recording agent event: instance={}, app={}, env={}, type={}", instanceId, applicationId, environment, eventType);
repository.insert(instanceId, applicationId, environment, eventType, detail);
}
public List<AgentEventRecord> queryEvents(String applicationId, String instanceId, String environment, Instant from, Instant to, int limit) {