refactor(events): remove dead non-paginated query path
AgentEventService.queryEvents, AgentEventRepository.query, and the ClickHouse implementation have had no callers since /agents/events became cursor-paginated. Remove them along with their dedicated IT tests. queryPage and its tests remain as the single query path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,30 +40,6 @@ public class ClickHouseAgentEventRepository implements AgentEventRepository {
|
||||
environment != null ? environment : "default", eventType, detail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AgentEventRecord> query(String applicationId, String instanceId, String environment, Instant from, Instant to, int limit) {
|
||||
var sql = new StringBuilder(SELECT_BASE);
|
||||
var params = new ArrayList<Object>();
|
||||
params.add(tenantId);
|
||||
|
||||
if (applicationId != null) { sql.append(" AND application_id = ?"); params.add(applicationId); }
|
||||
if (instanceId != null) { sql.append(" AND instance_id = ?"); params.add(instanceId); }
|
||||
if (environment != null) { sql.append(" AND environment = ?"); params.add(environment); }
|
||||
if (from != null) { sql.append(" AND timestamp >= ?"); params.add(Timestamp.from(from)); }
|
||||
if (to != null) { sql.append(" AND timestamp < ?"); params.add(Timestamp.from(to)); }
|
||||
sql.append(" ORDER BY timestamp DESC LIMIT ?");
|
||||
params.add(limit);
|
||||
|
||||
return jdbc.query(sql.toString(), (rs, rowNum) -> new AgentEventRecord(
|
||||
rs.getLong("id"),
|
||||
rs.getString("instance_id"),
|
||||
rs.getString("application_id"),
|
||||
rs.getString("event_type"),
|
||||
rs.getString("detail"),
|
||||
rs.getTimestamp("timestamp").toInstant()
|
||||
), params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentEventPage queryPage(String applicationId, String instanceId, String environment,
|
||||
Instant from, Instant to, String cursor, int limit) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.cameleer.server.app.storage;
|
||||
|
||||
import com.cameleer.server.core.agent.AgentEventRecord;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -10,10 +9,8 @@ import org.testcontainers.clickhouse.ClickHouseContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -65,95 +62,6 @@ class ClickHouseAgentEventRepositoryIT {
|
||||
assertThat(count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void query_byAppId_filtersCorrectly() {
|
||||
repo.insert("agent-1", "app-x", "default", "CONNECTED", "");
|
||||
repo.insert("agent-2", "app-y", "default", "DISCONNECTED", "");
|
||||
|
||||
List<AgentEventRecord> results = repo.query("app-x", null, null, null, null, 100);
|
||||
|
||||
assertThat(results).hasSize(1);
|
||||
assertThat(results.get(0).applicationId()).isEqualTo("app-x");
|
||||
assertThat(results.get(0).instanceId()).isEqualTo("agent-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void query_byAgentId_filtersCorrectly() {
|
||||
repo.insert("agent-alpha", "app-shared", "default", "CONNECTED", "");
|
||||
repo.insert("agent-beta", "app-shared", "default", "CONNECTED", "");
|
||||
|
||||
List<AgentEventRecord> results = repo.query(null, "agent-alpha", null, null, null, 100);
|
||||
|
||||
assertThat(results).hasSize(1);
|
||||
assertThat(results.get(0).instanceId()).isEqualTo("agent-alpha");
|
||||
}
|
||||
|
||||
@Test
|
||||
void query_byTimeRange_filtersCorrectly() {
|
||||
Instant t1 = Instant.parse("2026-01-01T10:00:00Z");
|
||||
Instant t2 = Instant.parse("2026-01-01T11:00:00Z");
|
||||
Instant t3 = Instant.parse("2026-01-01T12:00:00Z");
|
||||
|
||||
insertAt("agent-1", "app-a", "CONNECTED", "early", t1);
|
||||
insertAt("agent-1", "app-a", "HEARTBEAT", "mid", t2);
|
||||
insertAt("agent-1", "app-a", "DISCONNECTED", "late", t3);
|
||||
|
||||
// Query [t2, t3) — should return only the middle event
|
||||
List<AgentEventRecord> results = repo.query(null, null, null, t2, t3, 100);
|
||||
|
||||
assertThat(results).hasSize(1);
|
||||
assertThat(results.get(0).eventType()).isEqualTo("HEARTBEAT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void query_respectsLimit() {
|
||||
Instant base = Instant.parse("2026-02-01T00:00:00Z");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
insertAt("agent-1", "app-a", "HEARTBEAT", "beat-" + i, base.plusSeconds(i));
|
||||
}
|
||||
|
||||
List<AgentEventRecord> results = repo.query(null, null, null, null, null, 3);
|
||||
|
||||
assertThat(results).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void query_returnsZeroId() {
|
||||
repo.insert("agent-1", "app-a", "default", "CONNECTED", "");
|
||||
|
||||
List<AgentEventRecord> results = repo.query(null, null, null, null, null, 10);
|
||||
|
||||
assertThat(results).hasSize(1);
|
||||
assertThat(results.get(0).id()).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void query_noFilters_returnsAllEvents() {
|
||||
repo.insert("agent-1", "app-a", "default", "CONNECTED", "");
|
||||
repo.insert("agent-2", "app-b", "default", "DISCONNECTED", "");
|
||||
|
||||
List<AgentEventRecord> results = repo.query(null, null, null, null, null, 100);
|
||||
|
||||
assertThat(results).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void query_resultsOrderedByTimestampDesc() {
|
||||
Instant t1 = Instant.parse("2026-03-01T08:00:00Z");
|
||||
Instant t2 = Instant.parse("2026-03-01T09:00:00Z");
|
||||
Instant t3 = Instant.parse("2026-03-01T10:00:00Z");
|
||||
|
||||
insertAt("agent-1", "app-a", "FIRST", "", t1);
|
||||
insertAt("agent-1", "app-a", "SECOND", "", t2);
|
||||
insertAt("agent-1", "app-a", "THIRD", "", t3);
|
||||
|
||||
List<AgentEventRecord> results = repo.query(null, null, null, null, null, 100);
|
||||
|
||||
assertThat(results.get(0).eventType()).isEqualTo("THIRD");
|
||||
assertThat(results.get(1).eventType()).isEqualTo("SECOND");
|
||||
assertThat(results.get(2).eventType()).isEqualTo("FIRST");
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryPage_emptyTable_returnsEmptyPage() {
|
||||
com.cameleer.server.core.agent.AgentEventPage page =
|
||||
|
||||
Reference in New Issue
Block a user