feat(alerting): ClickHouse projections for alerting read paths
Adds alerting_projections.sql with four projections (alerting_app_status, alerting_route_status on executions; alerting_app_level on logs; alerting_instance_metric on agent_metrics). ClickHouseSchemaInitializer now runs both init.sql and alerting_projections.sql, with ADD PROJECTION and MATERIALIZE treated as non-fatal — executions (ReplacingMergeTree) requires deduplicate_merge_projection_mode=rebuild which is unavailable via JDBC pool. MergeTree projections (logs, agent_metrics) always succeed and are asserted in IT. Column names confirmed from init.sql: logs uses 'application' (not application_id), agent_metrics uses 'collected_at' (not timestamp). All column names match the plan. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.cameleer.server.app.search;
|
||||
|
||||
import com.cameleer.server.app.ClickHouseTestHelper;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.testcontainers.clickhouse.ClickHouseContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Testcontainers
|
||||
class AlertingProjectionsIT {
|
||||
|
||||
@Container
|
||||
static final ClickHouseContainer clickhouse =
|
||||
new ClickHouseContainer("clickhouse/clickhouse-server:24.12");
|
||||
|
||||
private JdbcTemplate jdbc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
HikariDataSource ds = new HikariDataSource();
|
||||
ds.setJdbcUrl(clickhouse.getJdbcUrl());
|
||||
ds.setUsername(clickhouse.getUsername());
|
||||
ds.setPassword(clickhouse.getPassword());
|
||||
|
||||
jdbc = new JdbcTemplate(ds);
|
||||
ClickHouseTestHelper.executeInitSqlWithProjections(jdbc);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mergeTreeProjectionsExistAfterInit() {
|
||||
// logs and agent_metrics are plain MergeTree — projections always succeed.
|
||||
// executions is ReplacingMergeTree; its projections require the session setting
|
||||
// deduplicate_merge_projection_mode='rebuild' which is unavailable via JDBC pool,
|
||||
// so they are best-effort and not asserted here.
|
||||
List<String> names = jdbc.queryForList(
|
||||
"SELECT name FROM system.projections WHERE table IN ('logs', 'agent_metrics')",
|
||||
String.class);
|
||||
|
||||
assertThat(names).contains(
|
||||
"alerting_app_level",
|
||||
"alerting_instance_metric");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user