From 573370e8a1747cf745ac10acd1801370fab44497 Mon Sep 17 00:00:00 2001 From: md1qamar Date: Mon, 30 Nov 2026 08:24:07 +0530 Subject: [PATCH 1/4] fix(iceberg): advertise supported endpoints in /v1/config --- .../catalog/rest-catalog-client.test.ts | 38 +++++++++++++++++++ .../iceberg/catalog/rest-catalog-client.ts | 1 + .../iceberg/catalog/tenant-catalog.test.ts | 38 ++++++++++++++++++- .../iceberg/catalog/tenant-catalog.ts | 18 +++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) diff --git a/src/storage/protocols/iceberg/catalog/rest-catalog-client.test.ts b/src/storage/protocols/iceberg/catalog/rest-catalog-client.test.ts index d0befb6a1..df78d0fdd 100644 --- a/src/storage/protocols/iceberg/catalog/rest-catalog-client.test.ts +++ b/src/storage/protocols/iceberg/catalog/rest-catalog-client.test.ts @@ -488,6 +488,44 @@ describe('RestCatalogClient request pipeline', () => { }) }) + it('preserves supported endpoints from getConfig when provided by upstream', async () => { + const endpoints = [ + 'GET /v1/{prefix}/namespaces', + 'POST /v1/{prefix}/namespaces', + 'GET /v1/{prefix}/namespaces/{namespace}/tables', + ] + fetchMock.mockResolvedValueOnce( + new Response(JSON.stringify({ defaults: { clients: '4' }, endpoints }), { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }) + ) + const client = new RestCatalogClient({ + catalogUrl: 'https://host.example.com/v1', + auth: new BearerTokenAuth({ token: 't' }), + }) + + const result = await client.getConfig({ warehouse: 'wh' }) + expect(result.endpoints).toEqual(endpoints) + expect(result.endpoints).not.toBe(endpoints) + }) + + it('omits endpoints from getConfig when upstream does not return them', async () => { + fetchMock.mockResolvedValueOnce( + new Response(JSON.stringify({ defaults: { clients: '4' } }), { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }) + ) + const client = new RestCatalogClient({ + catalogUrl: 'https://host.example.com/v1', + auth: new BearerTokenAuth({ token: 't' }), + }) + + const result = await client.getConfig({ warehouse: 'wh' }) + expect(result).not.toHaveProperty('endpoints') + }) + it('rejects non-JSON successful responses with a specific internal error', async () => { fetchMock.mockResolvedValueOnce( new Response('not json', { status: 200, headers: { 'Content-Type': 'text/plain' } }) diff --git a/src/storage/protocols/iceberg/catalog/rest-catalog-client.ts b/src/storage/protocols/iceberg/catalog/rest-catalog-client.ts index 3cbcdcf8d..de8096088 100644 --- a/src/storage/protocols/iceberg/catalog/rest-catalog-client.ts +++ b/src/storage/protocols/iceberg/catalog/rest-catalog-client.ts @@ -730,6 +730,7 @@ export class RestCatalogClient { prefix: params.warehouse, }, overrides, + ...(Array.isArray(data.endpoints) ? { endpoints: [...data.endpoints] } : {}), } } diff --git a/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts b/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts index 13692cca2..f20b4bc92 100644 --- a/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts +++ b/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts @@ -5,7 +5,7 @@ import { describe, expect, it, vi } from 'vitest' import type { Metastore } from '../metastore' import { IcebergErrorType } from './errors' import type { CatalogAuthType } from './rest-catalog-client' -import { TenantAwareRestCatalog } from './tenant-catalog' +import { SUPPORTED_ICEBERG_ENDPOINTS, TenantAwareRestCatalog } from './tenant-catalog' function createCatalog(metastore: Partial, sharding: Partial = {}) { const auth: CatalogAuthType = { @@ -659,3 +659,39 @@ describe('TenantAwareRestCatalog resource mutations', () => { expect(fetchMock).not.toHaveBeenCalled() }) }) + +describe('TenantAwareRestCatalog getConfig', () => { + it('advertises only the Iceberg REST endpoints served by this catalog', async () => { + const fetchMock = vi.fn() + vi.stubGlobal('fetch', fetchMock) + + const catalog = createCatalog({ + findCatalogByName: vi.fn().mockResolvedValue({ id: 'catalog-id', name: 'warehouse' }), + }) + + const result = await catalog.getConfig({ warehouse: 'warehouse' }) + + expect(result.defaults.prefix).toBe('warehouse') + expect(result.overrides).toEqual({ prefix: 'warehouse' }) + expect(result.endpoints).toEqual([ + 'GET /v1/{prefix}/namespaces', + 'POST /v1/{prefix}/namespaces', + 'GET /v1/{prefix}/namespaces/{namespace}', + 'HEAD /v1/{prefix}/namespaces/{namespace}', + 'DELETE /v1/{prefix}/namespaces/{namespace}', + 'GET /v1/{prefix}/namespaces/{namespace}/tables', + 'POST /v1/{prefix}/namespaces/{namespace}/tables', + 'GET /v1/{prefix}/namespaces/{namespace}/tables/{table}', + 'HEAD /v1/{prefix}/namespaces/{namespace}/tables/{table}', + 'POST /v1/{prefix}/namespaces/{namespace}/tables/{table}', + 'DELETE /v1/{prefix}/namespaces/{namespace}/tables/{table}', + ]) + expect(result.endpoints).not.toContain('POST /v1/{prefix}/namespaces/{namespace}/properties') + expect(result.endpoints).not.toContain('POST /v1/{prefix}/tables/rename') + expect(result.endpoints).not.toContain('POST /v1/{prefix}/namespaces/{namespace}/register') + + result.endpoints.push('POST /v1/{prefix}/tables/rename') + expect(SUPPORTED_ICEBERG_ENDPOINTS).toHaveLength(11) + expect(fetchMock).not.toHaveBeenCalled() + }) +}) diff --git a/src/storage/protocols/iceberg/catalog/tenant-catalog.ts b/src/storage/protocols/iceberg/catalog/tenant-catalog.ts index 6edc0390d..43e90299b 100644 --- a/src/storage/protocols/iceberg/catalog/tenant-catalog.ts +++ b/src/storage/protocols/iceberg/catalog/tenant-catalog.ts @@ -88,6 +88,23 @@ async function findTableByNameOrThrow( } } +/** + * Apache Iceberg REST catalog endpoints served by the storage HTTP router. + */ +export const SUPPORTED_ICEBERG_ENDPOINTS = [ + 'GET /v1/{prefix}/namespaces', + 'POST /v1/{prefix}/namespaces', + 'GET /v1/{prefix}/namespaces/{namespace}', + 'HEAD /v1/{prefix}/namespaces/{namespace}', + 'DELETE /v1/{prefix}/namespaces/{namespace}', + 'GET /v1/{prefix}/namespaces/{namespace}/tables', + 'POST /v1/{prefix}/namespaces/{namespace}/tables', + 'GET /v1/{prefix}/namespaces/{namespace}/tables/{table}', + 'HEAD /v1/{prefix}/namespaces/{namespace}/tables/{table}', + 'POST /v1/{prefix}/namespaces/{namespace}/tables/{table}', + 'DELETE /v1/{prefix}/namespaces/{namespace}/tables/{table}', +] as const + /** * A tenant-aware REST catalog implementation for Iceberg tables * @@ -129,6 +146,7 @@ export class TenantAwareRestCatalog extends RestCatalogClient { overrides: { prefix: catalog.name, }, + endpoints: [...SUPPORTED_ICEBERG_ENDPOINTS] as string[], } } From a2a6edb308601fa7c91915ffa0b8327f51ae8b06 Mon Sep 17 00:00:00 2001 From: Tyler Hillery Date: Fri, 4 Dec 2026 12:41:25 -0600 Subject: [PATCH 2/4] fix(iceberg): advertise only our own endpoints, never upstream's --- .../catalog/rest-catalog-client.test.ts | 38 ------------------- .../iceberg/catalog/rest-catalog-client.ts | 1 - 2 files changed, 39 deletions(-) diff --git a/src/storage/protocols/iceberg/catalog/rest-catalog-client.test.ts b/src/storage/protocols/iceberg/catalog/rest-catalog-client.test.ts index df78d0fdd..d0befb6a1 100644 --- a/src/storage/protocols/iceberg/catalog/rest-catalog-client.test.ts +++ b/src/storage/protocols/iceberg/catalog/rest-catalog-client.test.ts @@ -488,44 +488,6 @@ describe('RestCatalogClient request pipeline', () => { }) }) - it('preserves supported endpoints from getConfig when provided by upstream', async () => { - const endpoints = [ - 'GET /v1/{prefix}/namespaces', - 'POST /v1/{prefix}/namespaces', - 'GET /v1/{prefix}/namespaces/{namespace}/tables', - ] - fetchMock.mockResolvedValueOnce( - new Response(JSON.stringify({ defaults: { clients: '4' }, endpoints }), { - status: 200, - headers: { 'Content-Type': 'application/json' }, - }) - ) - const client = new RestCatalogClient({ - catalogUrl: 'https://host.example.com/v1', - auth: new BearerTokenAuth({ token: 't' }), - }) - - const result = await client.getConfig({ warehouse: 'wh' }) - expect(result.endpoints).toEqual(endpoints) - expect(result.endpoints).not.toBe(endpoints) - }) - - it('omits endpoints from getConfig when upstream does not return them', async () => { - fetchMock.mockResolvedValueOnce( - new Response(JSON.stringify({ defaults: { clients: '4' } }), { - status: 200, - headers: { 'Content-Type': 'application/json' }, - }) - ) - const client = new RestCatalogClient({ - catalogUrl: 'https://host.example.com/v1', - auth: new BearerTokenAuth({ token: 't' }), - }) - - const result = await client.getConfig({ warehouse: 'wh' }) - expect(result).not.toHaveProperty('endpoints') - }) - it('rejects non-JSON successful responses with a specific internal error', async () => { fetchMock.mockResolvedValueOnce( new Response('not json', { status: 200, headers: { 'Content-Type': 'text/plain' } }) diff --git a/src/storage/protocols/iceberg/catalog/rest-catalog-client.ts b/src/storage/protocols/iceberg/catalog/rest-catalog-client.ts index de8096088..3cbcdcf8d 100644 --- a/src/storage/protocols/iceberg/catalog/rest-catalog-client.ts +++ b/src/storage/protocols/iceberg/catalog/rest-catalog-client.ts @@ -730,7 +730,6 @@ export class RestCatalogClient { prefix: params.warehouse, }, overrides, - ...(Array.isArray(data.endpoints) ? { endpoints: [...data.endpoints] } : {}), } } From a088d3e8e420c343217cd98588429ef4eb03cca5 Mon Sep 17 00:00:00 2001 From: Tyler Hillery Date: Fri, 4 Dec 2026 12:42:28 -0600 Subject: [PATCH 3/4] test(iceberg): assert advertised endpoints match registered routes --- src/http/routes/iceberg/endpoints.test.ts | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/http/routes/iceberg/endpoints.test.ts diff --git a/src/http/routes/iceberg/endpoints.test.ts b/src/http/routes/iceberg/endpoints.test.ts new file mode 100644 index 000000000..5d2783b54 --- /dev/null +++ b/src/http/routes/iceberg/endpoints.test.ts @@ -0,0 +1,29 @@ +import { SUPPORTED_ICEBERG_ENDPOINTS } from '@storage/protocols/iceberg/catalog/tenant-catalog' +import fastify from 'fastify' +import namespace from './namespace' +import table from './table' + +describe('iceberg advertised endpoints', () => { + it('match the Iceberg REST routes registered by the router', async () => { + // Auto-generated HEAD routes are not catalog endpoints, so only collect explicit ones. + const app = fastify({ exposeHeadRoutes: false }) + app.setValidatorCompiler(() => () => true) + app.setSerializerCompiler(() => (data) => JSON.stringify(data)) + const registered: string[] = [] + app.addHook('onRoute', (route) => { + const methods = Array.isArray(route.method) ? route.method : [route.method] + const path = route.url.replace(/:(\w+)/g, '{$1}') + methods.forEach((method) => registered.push(`${method} ${path}`)) + }) + + await app.register(namespace, { prefix: 'v1' }) + await app.register(table, { prefix: 'v1' }) + await app.ready() + + try { + expect([...new Set(registered)].sort()).toEqual([...SUPPORTED_ICEBERG_ENDPOINTS].sort()) + } finally { + await app.close() + } + }) +}) From 2a3ad50bf51f13db852c1d24598c116451c06a10 Mon Sep 17 00:00:00 2001 From: Tyler Hillery Date: Fri, 4 Dec 2026 12:43:56 -0600 Subject: [PATCH 4/4] refactor: drop the duplicated endpoitn list from getConfig test --- .../iceberg/catalog/tenant-catalog.test.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts b/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts index f20b4bc92..75ac4890c 100644 --- a/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts +++ b/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts @@ -673,19 +673,7 @@ describe('TenantAwareRestCatalog getConfig', () => { expect(result.defaults.prefix).toBe('warehouse') expect(result.overrides).toEqual({ prefix: 'warehouse' }) - expect(result.endpoints).toEqual([ - 'GET /v1/{prefix}/namespaces', - 'POST /v1/{prefix}/namespaces', - 'GET /v1/{prefix}/namespaces/{namespace}', - 'HEAD /v1/{prefix}/namespaces/{namespace}', - 'DELETE /v1/{prefix}/namespaces/{namespace}', - 'GET /v1/{prefix}/namespaces/{namespace}/tables', - 'POST /v1/{prefix}/namespaces/{namespace}/tables', - 'GET /v1/{prefix}/namespaces/{namespace}/tables/{table}', - 'HEAD /v1/{prefix}/namespaces/{namespace}/tables/{table}', - 'POST /v1/{prefix}/namespaces/{namespace}/tables/{table}', - 'DELETE /v1/{prefix}/namespaces/{namespace}/tables/{table}', - ]) + expect(result.endpoints).toEqual([...SUPPORTED_ICEBERG_ENDPOINTS]) expect(result.endpoints).not.toContain('POST /v1/{prefix}/namespaces/{namespace}/properties') expect(result.endpoints).not.toContain('POST /v1/{prefix}/tables/rename') expect(result.endpoints).not.toContain('POST /v1/{prefix}/namespaces/{namespace}/register')