Skip to content

Commit efe6fa4

Browse files
committed
device-health-oracle: fix ClickHouse integration test authentication
Use explicit credentials and the testcontainers ClickHouse module options (WithUsername, WithPassword, WithDatabase) to match the pattern used by other integration tests in the repo. Switch to 23.3.8.21-alpine image which is consistent with the rest of the codebase. Add CHANGELOG entry.
1 parent 69220ae commit efe6fa4

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
88

99
### Changes
1010

11+
- Controlplane
12+
- Add `controller_success` activation criterion to device-health-oracle that verifies devices have consistent controller call coverage over a configurable burn-in period by querying ClickHouse
1113
- Client
1214
- Rank devices and tunnel endpoints by minimum observed latency (`min_latency_ns`) instead of average when selecting a connection target, preferring paths with the best achievable round-trip time
1315
- Tools

controlplane/device-health-oracle/internal/worker/clickhouse_test.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,55 @@ import (
1111
"github.com/ClickHouse/clickhouse-go/v2"
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
14+
"github.com/testcontainers/testcontainers-go"
15+
)
16+
17+
const (
18+
chTestUser = "default"
19+
chTestPassword = "testpass"
20+
chTestDatabase = "default"
1421
)
1522

1623
func setupClickHouseContainer(t *testing.T) (clickhouse.Conn, func()) {
1724
t.Helper()
1825
ctx := context.Background()
1926

2027
container, err := chmodule.Run(ctx,
21-
"clickhouse/clickhouse-server:24.3",
28+
"clickhouse/clickhouse-server:23.3.8.21-alpine",
29+
chmodule.WithUsername(chTestUser),
30+
chmodule.WithPassword(chTestPassword),
31+
chmodule.WithDatabase(chTestDatabase),
2232
)
2333
require.NoError(t, err)
34+
testcontainers.CleanupContainer(t, container)
2435

25-
host, err := container.Host(ctx)
26-
require.NoError(t, err)
27-
28-
port, err := container.MappedPort(ctx, "9000/tcp")
36+
connStr, err := container.ConnectionHost(ctx)
2937
require.NoError(t, err)
3038

3139
conn, err := clickhouse.Open(&clickhouse.Options{
32-
Addr: []string{fmt.Sprintf("%s:%s", host, port.Port())},
40+
Addr: []string{connStr},
3341
Auth: clickhouse.Auth{
34-
Database: "default",
35-
Username: "default",
42+
Database: chTestDatabase,
43+
Username: chTestUser,
44+
Password: chTestPassword,
3645
},
3746
})
3847
require.NoError(t, err)
3948
require.NoError(t, conn.Ping(ctx))
4049

4150
// Create the table
42-
err = conn.Exec(ctx, `
43-
CREATE TABLE IF NOT EXISTS "default".controller_grpc_getconfig_success (
51+
err = conn.Exec(ctx, fmt.Sprintf(`
52+
CREATE TABLE IF NOT EXISTS "%s".controller_grpc_getconfig_success (
4453
timestamp DateTime64(3),
4554
device_pubkey LowCardinality(String)
4655
) ENGINE = MergeTree
4756
PARTITION BY toYYYYMM(timestamp)
4857
ORDER BY (timestamp, device_pubkey)
49-
`)
58+
`, chTestDatabase))
5059
require.NoError(t, err)
5160

5261
cleanup := func() {
5362
_ = conn.Close()
54-
_ = container.Terminate(ctx)
5563
}
5664

5765
return conn, cleanup
@@ -66,7 +74,7 @@ func TestClickHouseClient_ControllerCallCoverage(t *testing.T) {
6674
defer cleanup()
6775

6876
ctx := context.Background()
69-
client := &ClickHouseClient{conn: conn, db: "default"}
77+
client := &ClickHouseClient{conn: conn, db: chTestDatabase}
7078

7179
devicePubkey := "TestDevice123"
7280
now := time.Now().Truncate(time.Second)
@@ -75,7 +83,7 @@ func TestClickHouseClient_ControllerCallCoverage(t *testing.T) {
7583
for i := 0; i < 10; i++ {
7684
ts := now.Add(-time.Duration(10-i) * time.Minute)
7785
err := conn.Exec(ctx, fmt.Sprintf(
78-
`INSERT INTO "default".controller_grpc_getconfig_success (timestamp, device_pubkey) VALUES (?, ?)`,
86+
`INSERT INTO "%s".controller_grpc_getconfig_success (timestamp, device_pubkey) VALUES (?, ?)`, chTestDatabase,
7987
), ts, devicePubkey)
8088
require.NoError(t, err)
8189
}
@@ -123,7 +131,7 @@ func TestClickHouseClient_ControllerCallCoverage_WithGaps(t *testing.T) {
123131
defer cleanup()
124132

125133
ctx := context.Background()
126-
client := &ClickHouseClient{conn: conn, db: "default"}
134+
client := &ClickHouseClient{conn: conn, db: chTestDatabase}
127135

128136
devicePubkey := "GappyDevice789"
129137
now := time.Now().Truncate(time.Second)
@@ -133,7 +141,7 @@ func TestClickHouseClient_ControllerCallCoverage_WithGaps(t *testing.T) {
133141
for _, m := range gapMinutes {
134142
ts := now.Add(-time.Duration(m) * time.Minute)
135143
err := conn.Exec(ctx, fmt.Sprintf(
136-
`INSERT INTO "default".controller_grpc_getconfig_success (timestamp, device_pubkey) VALUES (?, ?)`,
144+
`INSERT INTO "%s".controller_grpc_getconfig_success (timestamp, device_pubkey) VALUES (?, ?)`, chTestDatabase,
137145
), ts, devicePubkey)
138146
require.NoError(t, err)
139147
}

0 commit comments

Comments
 (0)