Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(compute): filter logs on the subservice attribute (#50562)

Matt Johnston29878860a979
diff --git a/apps/studio/components/interfaces/UnifiedLogs/ServiceFlowPanel.test.ts b/apps/studio/components/interfaces/UnifiedLogs/ServiceFlowPanel.test.ts
index 2c414219d60..597889b4c1e 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/ServiceFlowPanel.test.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/ServiceFlowPanel.test.ts
@@ -5,7 +5,7 @@ import { getLogDataForMetadataVisibility } from './ServiceFlowPanel.utils'
describe('getLogDataForMetadataVisibility', () => {
const logData = {
id: 'worker-log',
- metadata: { source: 'worker_guest_logs', worker: 'api' },
+ metadata: { subservice: 'worker_guest_logs', worker: 'api' },
raw_log_data: {
event_message: 'Worker failed',
metadata: { request_id: 'request-id' },
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.test.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.test.ts
index a83a982d03c..92cde3cf321 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.test.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.test.ts
@@ -50,7 +50,7 @@ describe('UnifiedLogs.queries (OTEL flat)', () => {
const sql = getUnifiedLogsQuery(withFilters('log_type:eq:compute'))
const where = sql.split(/\bWHERE\b/)[1] ?? ''
expect(where).toContain(
- `log_attributes['source'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs')`
+ `log_attributes['subservice'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs')`
)
expect(where).not.toContain(`source = 'compute'`)
})
@@ -58,7 +58,7 @@ describe('UnifiedLogs.queries (OTEL flat)', () => {
it('classifies every worker OTEL stream as compute in the projected log type', () => {
const sql = getUnifiedLogsQuery(baseSearch)
expect(sql).toContain(
- `WHEN log_attributes['source'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs') THEN 'compute'`
+ `WHEN log_attributes['subservice'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs') THEN 'compute'`
)
})
@@ -66,14 +66,14 @@ describe('UnifiedLogs.queries (OTEL flat)', () => {
const sql = getUnifiedLogsQuery(withFilters('log_type:neq:compute'))
const where = sql.split(/\bWHERE\b/)[1] ?? ''
expect(where).toContain(
- `NOT (log_attributes['source'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs'))`
+ `NOT (log_attributes['subservice'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs'))`
)
})
it('projects only Compute fields that exist on worker logs', () => {
const sql = getUnifiedLogsQuery(withFilters('log_type:eq:compute'))
const workerCondition =
- "log_attributes['source'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs')"
+ "log_attributes['subservice'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs')"
expect(sql).toContain(`WHEN ${workerCondition} THEN null`)
expect(sql).toContain(
@@ -372,7 +372,7 @@ describe('UnifiedLogs.queries (OTEL flat)', () => {
it('does not classify Compute rows into a severity bucket', () => {
const sql = getLogsChartQuery(withFilters('log_type:eq:compute'))
const workerCondition =
- "log_attributes['source'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs')"
+ "log_attributes['subservice'] IN ('worker_ingress_logs','worker_guest_logs','worker_api_logs')"
expect(sql).toContain(`WHEN ${workerCondition} THEN null`)
expect(sql).not.toContain(`WHEN ${workerCondition} THEN 'success'`)
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
index 33dddd8285c..3d117e0762c 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
@@ -14,7 +14,7 @@ import {
safeSql,
type SafeLogSqlFragment,
} from '@/data/logs/safe-analytics-sql'
-import { WORKER_LOG_SOURCES } from '@/lib/constants/compute'
+import { COMPUTE_LOG_SUBSERVICES } from '@/lib/constants/compute'
// Operator fragments for SQL emission. `safeSql` rejects plain strings, so we
// pre-brand the keywords we want to switch between.
@@ -66,9 +66,13 @@ const HTTP_PATH_EXPR: SafeLogSqlFragment = safeSql`if(source = 'storage_logs', l
* logs from postgREST / storage-api and are intentionally not part of unified
* logs; the UI surfaces gateway HTTP traffic for those buckets.
*/
-const WORKER_LOG_SOURCE_VALUES = Object.values(WORKER_LOG_SOURCES)
-const WORKER_LOG_SOURCE_CONDITION = safeSql`log_attributes['source'] IN (${joinSqlFragments(
- WORKER_LOG_SOURCE_VALUES.map((source) => lit(source)),
+// Compute rows are matched on their stream names rather than a source: the mapping does
+// not classify them, so `source` is empty and the backend's top-level `subservice` lands
+// in `log_attributes`. The stream names are product-prefixed, which is what makes this
+// list a product filter as well as a stream one.
+const COMPUTE_SUBSERVICE_VALUES = Object.values(COMPUTE_LOG_SUBSERVICES)
+const COMPUTE_SUBSERVICE_CONDITION = safeSql`log_attributes['subservice'] IN (${joinSqlFragments(
+ COMPUTE_SUBSERVICE_VALUES.map((subservice) => lit(subservice)),
','
)})`
@@ -79,7 +83,7 @@ const LOG_TYPE_CONDITION: Record<string, SafeLogSqlFragment> = {
safeSql`source = ${lit(source)}`,
])
),
- compute: WORKER_LOG_SOURCE_CONDITION,
+ compute: COMPUTE_SUBSERVICE_CONDITION,
}
// Derived `log_type` column for SELECT / GROUP BY / countIf use.
@@ -96,7 +100,7 @@ const LOG_TYPE_EXPR: SafeLogSqlFragment = safeSql`CASE
WHEN source = 'supavisor_logs' THEN 'supavisor'
WHEN source = 'pgbouncer_logs' THEN 'pgbouncer'
WHEN source = 'multigres_logs' THEN 'multigres'
- WHEN ${WORKER_LOG_SOURCE_CONDITION} THEN 'compute'
+ WHEN ${COMPUTE_SUBSERVICE_CONDITION} THEN 'compute'
ELSE source
END`
@@ -104,14 +108,14 @@ const LOG_TYPE_EXPR: SafeLogSqlFragment = safeSql`CASE
// auth-service `status` attribute for auth rows, and the Postgres
// `parsed.sql_state_code` (e.g. `42P01`) for postgres rows.
const STATUS_EXPR: SafeLogSqlFragment = safeSql`CASE
- WHEN ${WORKER_LOG_SOURCE_CONDITION} THEN null
+ WHEN ${COMPUTE_SUBSERVICE_CONDITION} THEN null
WHEN source = 'postgres_logs' THEN toString(log_attributes['parsed.sql_state_code'])
ELSE toString((${HTTP_STATUS_EXPR}))
END`
-const METHOD_EXPR: SafeLogSqlFragment = safeSql`if(${WORKER_LOG_SOURCE_CONDITION}, null, ${HTTP_METHOD_EXPR})`
-const PATHNAME_EXPR: SafeLogSqlFragment = safeSql`if(${WORKER_LOG_SOURCE_CONDITION}, null, ${HTTP_PATH_EXPR})`
-const METADATA_EXPR: SafeLogSqlFragment = safeSql`if(${WORKER_LOG_SOURCE_CONDITION}, log_attributes, map())`
+const METHOD_EXPR: SafeLogSqlFragment = safeSql`if(${COMPUTE_SUBSERVICE_CONDITION}, null, ${HTTP_METHOD_EXPR})`
+const PATHNAME_EXPR: SafeLogSqlFragment = safeSql`if(${COMPUTE_SUBSERVICE_CONDITION}, null, ${HTTP_PATH_EXPR})`
+const METADATA_EXPR: SafeLogSqlFragment = safeSql`if(${COMPUTE_SUBSERVICE_CONDITION}, log_attributes, map())`
// SQL expression for derived `level`. Used inline (not as alias reference)
// because the OTEL endpoint can't resolve aliases inside countIf when the
@@ -122,7 +126,7 @@ const METADATA_EXPR: SafeLogSqlFragment = safeSql`if(${WORKER_LOG_SOURCE_CONDITI
// success/warning/error by status. Postgres-style severity is the
// fallback for rows without a status code.
const LEVEL_EXPR: SafeLogSqlFragment = safeSql`CASE
- WHEN ${WORKER_LOG_SOURCE_CONDITION} THEN null
+ WHEN ${COMPUTE_SUBSERVICE_CONDITION} THEN null
WHEN (${HTTP_STATUS_EXPR}) != '' AND toInt32OrZero((${HTTP_STATUS_EXPR})) >= 500 THEN 'error'
WHEN (${HTTP_STATUS_EXPR}) != '' AND toInt32OrZero((${HTTP_STATUS_EXPR})) BETWEEN 400 AND 499 THEN 'warning'
WHEN (${HTTP_STATUS_EXPR}) != '' AND toInt32OrZero((${HTTP_STATUS_EXPR})) BETWEEN 200 AND 299 THEN 'success'
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.utils.test.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.utils.test.ts
index 96e55493dac..6b8e3d1aa85 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.utils.test.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.utils.test.ts
@@ -108,7 +108,7 @@ describe('getRawLogData', () => {
launch_id: '1788424715503435269',
log_group: '/aws/lambda-microvms/workers/cxkpapyhaaywrtudnqpl/api',
log_stream: 'launch-1788424715503435269',
- source: 'worker_guest_logs',
+ subservice: 'worker_guest_logs',
worker: 'api',
},
project: 'cxkpapyhaaywrtudnqpl',
diff --git a/apps/studio/data/compute/compute-instance-logs-query.test.ts b/apps/studio/data/compute/compute-instance-logs-query.test.ts
index fce8529771d..d95f290794b 100644
--- a/apps/studio/data/compute/compute-instance-logs-query.test.ts
+++ b/apps/studio/data/compute/compute-instance-logs-query.test.ts
@@ -6,13 +6,13 @@ import { computeKeys } from './keys'
describe('computeInstanceLogsSql', () => {
it('reads one instance stream, newest first', () => {
expect(computeInstanceLogsSql('embed', 'output')).toBe(
- "select id, timestamp, severity_text as severity, event_message as message from logs where log_attributes['worker'] = 'embed' and log_attributes['source'] = 'worker_guest_logs' order by timestamp desc limit 100"
+ "select id, timestamp, severity_text as severity, event_message as message from logs where log_attributes['worker'] = 'embed' and log_attributes['subservice'] = 'worker_guest_logs' order by timestamp desc limit 100"
)
})
it('filters by event message before applying the limit', () => {
expect(computeInstanceLogsSql('embed', 'requests', { message: 'timeout' })).toBe(
- "select id, timestamp, severity_text as severity, event_message as message from logs where log_attributes['worker'] = 'embed' and log_attributes['source'] = 'worker_ingress_logs' and event_message ilike '%timeout%' order by timestamp desc limit 100"
+ "select id, timestamp, severity_text as severity, event_message as message from logs where log_attributes['worker'] = 'embed' and log_attributes['subservice'] = 'worker_ingress_logs' and event_message ilike '%timeout%' order by timestamp desc limit 100"
)
})
diff --git a/apps/studio/data/compute/compute-instance-logs-query.ts b/apps/studio/data/compute/compute-instance-logs-query.ts
index e84c6a9a7ab..e5a67fb6f77 100644
--- a/apps/studio/data/compute/compute-instance-logs-query.ts
+++ b/apps/studio/data/compute/compute-instance-logs-query.ts
@@ -8,9 +8,9 @@ import { executeAnalyticsSql } from '@/data/logs/execute-analytics-sql'
import { logsAllEndpointUrl } from '@/data/logs/logs-endpoint'
import { analyticsLiteral, safeSql } from '@/data/logs/safe-analytics-sql'
import { IS_PLATFORM } from '@/lib/constants'
-import { WORKER_LOG_SOURCES } from '@/lib/constants/compute'
+import { COMPUTE_LOG_SUBSERVICES } from '@/lib/constants/compute'
-export type ComputeInstanceLogStream = keyof typeof WORKER_LOG_SOURCES
+export type ComputeInstanceLogStream = keyof typeof COMPUTE_LOG_SUBSERVICES
export const COMPUTE_INSTANCE_LOG_STREAM_LABEL: Record<ComputeInstanceLogStream, string> = {
requests: 'Invocations',
@@ -18,11 +18,12 @@ export const COMPUTE_INSTANCE_LOG_STREAM_LABEL: Record<ComputeInstanceLogStream,
builds: 'Activity',
}
-// Both are read from `log_attributes` rather than the endpoint's own `source` column:
-// that column is derived from a mapping which does not currently classify these rows.
-// The key itself is still the pre-rename "worker" attribute the backend emits.
+// Both are read from `log_attributes` rather than the endpoint's own columns: that
+// mapping does not currently classify these rows, so `source` is empty on one and every
+// key the backend publishes — the top-level `subservice` included — lands in the
+// attribute map. The name key is still the pre-rename "worker" attribute.
const WORKER_NAME_KEY = 'worker'
-const STREAM_KEY = 'source'
+const STREAM_KEY = 'subservice'
const LOG_LIMIT = 100
@@ -51,7 +52,7 @@ export const computeInstanceLogsSql = (
? safeSql` and event_message ilike ${analyticsLiteral(`%${message}%`)}`
: safeSql``
- return safeSql`select id, timestamp, severity_text as severity, event_message as message from logs where log_attributes[${analyticsLiteral(WORKER_NAME_KEY)}] = ${analyticsLiteral(name)} and log_attributes[${analyticsLiteral(STREAM_KEY)}] = ${analyticsLiteral(WORKER_LOG_SOURCES[stream])}${messageFilter} order by timestamp desc limit ${analyticsLiteral(LOG_LIMIT)}`
+ return safeSql`select id, timestamp, severity_text as severity, event_message as message from logs where log_attributes[${analyticsLiteral(WORKER_NAME_KEY)}] = ${analyticsLiteral(name)} and log_attributes[${analyticsLiteral(STREAM_KEY)}] = ${analyticsLiteral(COMPUTE_LOG_SUBSERVICES[stream])}${messageFilter} order by timestamp desc limit ${analyticsLiteral(LOG_LIMIT)}`
}
export const parseComputeInstanceLogRows = (result: unknown): LogData[] =>
diff --git a/apps/studio/data/logs/unified-logs.utils.test.ts b/apps/studio/data/logs/unified-logs.utils.test.ts
index 10d679b250a..514d6b44255 100644
--- a/apps/studio/data/logs/unified-logs.utils.test.ts
+++ b/apps/studio/data/logs/unified-logs.utils.test.ts
@@ -182,7 +182,7 @@ describe('extractLogMetadata', () => {
launch_id: '1788424715503435269',
log_group: '/aws/lambda-microvms/workers/cxkpapyhaaywrtudnqpl/api',
log_stream: 'launch-1788424715503435269',
- source: 'worker_guest_logs',
+ subservice: 'worker_guest_logs',
worker: 'api',
},
project: 'cxkpapyhaaywrtudnqpl',
@@ -198,7 +198,7 @@ describe('extractLogMetadata', () => {
launch_id: '1788424715503435269',
log_group: '/aws/lambda-microvms/workers/cxkpapyhaaywrtudnqpl/api',
log_stream: 'launch-1788424715503435269',
- source: 'worker_guest_logs',
+ subservice: 'worker_guest_logs',
worker: 'api',
}
const mapped = mapUnifiedLogRow({
@@ -260,7 +260,7 @@ describe('parseUnifiedLogsQueryRows', () => {
launch_id: '1788424715503435269',
log_group: '/aws/lambda-microvms/workers/cxkpapyhaaywrtudnqpl/api',
log_stream: 'launch-1788424715503435269',
- source: 'worker_guest_logs',
+ subservice: 'worker_guest_logs',
worker: 'api',
},
project: 'cxkpapyhaaywrtudnqpl',
diff --git a/apps/studio/lib/constants/compute.ts b/apps/studio/lib/constants/compute.ts
index e333d00f430..f94f73124d7 100644
--- a/apps/studio/lib/constants/compute.ts
+++ b/apps/studio/lib/constants/compute.ts
@@ -1,9 +1,9 @@
export const PRODUCT_NAME = 'Compute'
export const CLI_NAME = 'compute'
-// The backend still tags these rows' `log_attributes` with the pre-rename "worker" source
-// names, so these values must stay as-is until the backend renames its log sources too.
-export const WORKER_LOG_SOURCES = {
+// The stream each row belongs to, as the backend publishes it. The values keep the
+// pre-rename "worker" spelling until the backend renames its log streams too.
+export const COMPUTE_LOG_SUBSERVICES = {
requests: 'worker_ingress_logs',
output: 'worker_guest_logs',
builds: 'worker_api_logs',