Skip to content

Commit 3be142c

Browse files
committed
fix: excude inactive connections from all counts except paused (#16944)
1 parent db26648 commit 3be142c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

airbyte-data/src/main/kotlin/io/airbyte/data/services/impls/jooq/ConnectionServiceJooqImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,11 +1775,11 @@ class ConnectionServiceJooqImpl
17751775
val sql =
17761776
"""
17771777
SELECT
1778-
COALESCE(SUM(CASE WHEN lj.latest_status = 'running' THEN 1 ELSE 0 END), 0) AS running,
1779-
COALESCE(SUM(CASE WHEN lj.latest_status = 'succeeded' THEN 1 ELSE 0 END), 0) AS healthy,
1780-
COALESCE(SUM(CASE WHEN lj.latest_status IN ('failed', 'cancelled', 'incomplete') THEN 1 ELSE 0 END), 0) AS failed,
1778+
COALESCE(SUM(CASE WHEN c.status != 'inactive' AND lj.latest_status = 'running' THEN 1 ELSE 0 END), 0) AS running,
1779+
COALESCE(SUM(CASE WHEN c.status != 'inactive' AND lj.latest_status = 'succeeded' THEN 1 ELSE 0 END), 0) AS healthy,
1780+
COALESCE(SUM(CASE WHEN c.status != 'inactive' AND lj.latest_status IN ('failed', 'cancelled', 'incomplete') THEN 1 ELSE 0 END), 0) AS failed,
17811781
COALESCE(SUM(CASE WHEN c.status = 'inactive' THEN 1 ELSE 0 END), 0) AS paused,
1782-
COALESCE(SUM(CASE WHEN lj.latest_status IS NULL AND c.status != 'inactive' THEN 1 ELSE 0 END), 0) AS not_synced
1782+
COALESCE(SUM(CASE WHEN c.status != 'inactive' AND lj.latest_status IS NULL THEN 1 ELSE 0 END), 0) AS not_synced
17831783
FROM connection c
17841784
JOIN actor a ON c.source_id = a.id
17851785
LEFT JOIN LATERAL (

airbyte-data/src/test/java/io/airbyte/data/services/impls/jooq/ConnectionServiceJooqImplTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ void testGetConnectionStatusCounts() throws IOException, JsonValidationException
364364
.withStatus(StandardSync.Status.ACTIVE);
365365
connectionServiceJooqImpl.writeStandardSync(notSyncedConnection);
366366

367+
// Connection 4: Inactive but last job succeeded
368+
final StandardSync pausedWithJobSucceededConnection = createStandardSync(source, destination, streams)
369+
.withStatus(StandardSync.Status.INACTIVE);
370+
connectionServiceJooqImpl.writeStandardSync(pausedWithJobSucceededConnection);
371+
367372
// Insert job records using raw SQL since we need to work with the jobs database
368373
database.query(ctx -> {
369374
final var now = OffsetDateTime.now();
@@ -452,6 +457,18 @@ void testGetConnectionStatusCounts() throws IOException, JsonValidationException
452457
.set(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS.CONFIG, org.jooq.impl.DSL.field("'{}'::jsonb", org.jooq.JSONB.class))
453458
.execute();
454459

460+
// Job for successful sync but paused connection
461+
ctx.insertInto(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS)
462+
.set(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS.ID, 8L)
463+
.set(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS.CONFIG_TYPE,
464+
io.airbyte.db.instance.jobs.jooq.generated.enums.JobConfigType.sync)
465+
.set(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS.SCOPE, pausedWithJobSucceededConnection.getConnectionId().toString())
466+
.set(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS.STATUS, io.airbyte.db.instance.jobs.jooq.generated.enums.JobStatus.succeeded)
467+
.set(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS.CREATED_AT, now.minusHours(2))
468+
.set(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS.UPDATED_AT, now.minusHours(2))
469+
.set(io.airbyte.db.instance.jobs.jooq.generated.Tables.JOBS.CONFIG, org.jooq.impl.DSL.field("'{}'::jsonb", org.jooq.JSONB.class))
470+
.execute();
471+
455472
return null;
456473
});
457474

@@ -461,7 +478,7 @@ void testGetConnectionStatusCounts() throws IOException, JsonValidationException
461478
assertEquals(1, result.healthy());
462479
// failedConnection + cancelledConnection + incompleteConnection
463480
assertEquals(3, result.failed());
464-
assertEquals(1, result.paused());
481+
assertEquals(2, result.paused());
465482
// notSyncedConnection (active connection with no jobs)
466483
assertEquals(1, result.notSynced());
467484
}

0 commit comments

Comments
 (0)