mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Update HA topology grouping for the Multigres JSON field rename from `shardKey` to `shardRef`, so separate shards retain their own primaries and replicas. **Changed:** - Normalize pooler responses to `shardRef`, falling back to legacy `shardKey` and preferring `shardRef` when both exist. - Use `shardRef` in the topology selector and shard grouping. **Added:** - Regression coverage from response parsing through diagram node/edge generation for new, legacy, mixed, and conflicting key formats, plus omitted shard identity fields. Addresses https://linear.app/supabase/issue/FE-4809/update-studio-ha-topology-grouping-to-use-shardref ## To test - Open Settings → Infrastructure on a multi-shard HA project returning `shardRef`. Confirm one group per shard, each primary shown as Primary Database, and replicas connected only to their own shard's primary. - Check the same topology on Database → Pipelines. - Confirm legacy `shardKey` responses still render correctly and single-shard projects remain unchanged. ## Validation - Passed: 33 targeted utility tests, ESLint on all changed files, Studio TypeScript check, and diff whitespace checks. - Local browser: login and non-HA infrastructure passed. HA grouping remains unverified because local poolers/gateways endpoints returned 404; browser response mocking was blocked by cross-origin/CORS limitations. - Upstream multigres/multigres#1608 merged October 29; deployment of the renamed field remains unconfirmed. Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com> Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
79 lines
3.2 KiB
TypeScript
79 lines
3.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { generateHaNodesAndEdges } from './HaInstanceConfiguration.utils'
|
|
import { buildHaTopology, selectTopologyPoolers } from './HaTopology.utils'
|
|
import { haClusterPoolersResponseSchema } from '@/data/ha-admin/ha-cluster-poolers-query'
|
|
|
|
describe('generateHaNodesAndEdges', () => {
|
|
it.each(['shardRef', 'shardKey', 'mixed', 'both'])(
|
|
'preserves shard groups and primary/replica nodes through the %s response pipeline',
|
|
(format) => {
|
|
const poolers = ['0', '1'].flatMap((shard) =>
|
|
['PRIMARY', 'REPLICA'].map((role, index) => {
|
|
const shardRef = { database: 'postgres', tableGroup: 'default', shard }
|
|
const usesLegacyKey = format === 'shardKey' || (format === 'mixed' && index === 1)
|
|
return {
|
|
id: { cell: `cell-${index}`, name: `p-${shard}-${role}` },
|
|
...(usesLegacyKey ? { shardKey: shardRef } : { shardRef }),
|
|
...(format === 'both' ? { shardKey: { ...shardRef, shard: 'stale' } } : {}),
|
|
routingState: { role: `ROUTING_ROLE_${role}` },
|
|
}
|
|
})
|
|
)
|
|
const data = haClusterPoolersResponseSchema.parse({ poolers })
|
|
const topology = buildHaTopology({ gateways: [], poolers: selectTopologyPoolers(data) })
|
|
|
|
expect(topology.shards.map(({ id, name }) => ({ id, name }))).toEqual([
|
|
{ id: 'postgres/default/0', name: 'Shard 1' },
|
|
{ id: 'postgres/default/1', name: 'Shard 2' },
|
|
])
|
|
const { nodes, edges } = generateHaNodesAndEdges(topology)
|
|
for (const shard of ['0', '1']) {
|
|
expect(nodes.filter((node) => node.data.shardId === `postgres/default/${shard}`)).toEqual([
|
|
expect.objectContaining({
|
|
type: 'HA_PRIMARY',
|
|
data: expect.objectContaining({ name: `p-${shard}-PRIMARY` }),
|
|
}),
|
|
expect.objectContaining({
|
|
type: 'HA_REPLICA',
|
|
data: expect.objectContaining({ name: `p-${shard}-REPLICA` }),
|
|
}),
|
|
])
|
|
expect(edges).toContainEqual(
|
|
expect.objectContaining({
|
|
source: `pooler-cell-0-p-${shard}-PRIMARY`,
|
|
target: `pooler-cell-1-p-${shard}-REPLICA`,
|
|
})
|
|
)
|
|
}
|
|
expect(edges).toHaveLength(2)
|
|
}
|
|
)
|
|
|
|
it('gives every pooler a unique node id even when identities are omitted', () => {
|
|
const topology = buildHaTopology({
|
|
gateways: [],
|
|
poolers: [
|
|
{
|
|
id: { cell: 'cell-1', name: 'p-1' },
|
|
shardRef: { shard: '0' },
|
|
routingState: { role: 'ROUTING_ROLE_PRIMARY' },
|
|
},
|
|
{ shardRef: { shard: '0' }, routingState: { role: 'ROUTING_ROLE_REPLICA' } },
|
|
{ shardRef: { shard: '0' }, routingState: { role: 'ROUTING_ROLE_REPLICA' } },
|
|
],
|
|
})
|
|
|
|
const { nodes, edges } = generateHaNodesAndEdges(topology)
|
|
const poolerNodeIds = nodes
|
|
.filter((node) => node.type === 'HA_PRIMARY' || node.type === 'HA_REPLICA')
|
|
.map((node) => node.id)
|
|
|
|
expect(poolerNodeIds).toHaveLength(3)
|
|
expect(new Set(poolerNodeIds).size).toBe(3)
|
|
// Each replica still gets its own edge from the primary.
|
|
expect(edges).toHaveLength(2)
|
|
expect(new Set(edges.map((edge) => edge.id)).size).toBe(2)
|
|
})
|
|
})
|