Skip to content

Commit 206512d

Browse files
authored
fix(studio): realtime metrics (supabase#40824)
* Connected clients is now showing the number of connections at the time. * Broadcast events * Presence events * Postgres changes events * Rate of Channel joins (unchanged) * Message payload size : median of payload size * Broadcast From Database Replication Lag: median replication from commit to broadcast * (Read) Private Channel Subscription RLS Execution Time: median time RLS execution to subscribe * (Write) Private Channel Subscription RLS Execution Time: median time RLS execution to publish
1 parent 58a4e73 commit 206512d

File tree

2 files changed

+128
-53
lines changed

2 files changed

+128
-53
lines changed

apps/studio/data/analytics/infra-monitoring-query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export type InfraMonitoringAttribute =
1919
| 'realtime_channel_db_events'
2020
| 'realtime_channel_presence_events'
2121
| 'realtime_channel_joins'
22-
| 'realtime_authorization_rls_execution_time'
22+
| 'realtime_read_authorization_rls_execution_time'
23+
| 'realtime_write_authorization_rls_execution_time'
2324
| 'realtime_payload_size'
2425
| 'realtime_sum_connections_connected'
2526
| 'realtime_replication_connection_lag'

apps/studio/data/reports/v2/realtime.config.ts

Lines changed: 126 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,55 +36,50 @@ export const realtimeReports = ({
3636
databaseIdentifier?: string
3737
}): ReportConfig[] => [
3838
{
39-
id: 'client-to-realtime-connections',
40-
label: 'Connections',
39+
id: 'realtime_sum_connections_connected',
40+
label: 'Connected Clients',
4141
valuePrecision: 0,
4242
hide: false,
43-
showTooltip: false,
43+
showSumAsDefaultHighlight: false,
44+
showNewBadge: true,
45+
showTooltip: true,
4446
showLegend: false,
4547
showMaxValue: false,
4648
hideChartType: false,
4749
defaultChartStyle: 'line',
48-
titleTooltip: '',
50+
titleTooltip: 'Total number of connected realtime clients.',
4951
availableIn: ['free', 'pro', 'team', 'enterprise'],
5052
dataProvider: async () => {
5153
const data = await runInfraMonitoringQuery(
5254
projectRef,
53-
'realtime_connections_connected',
55+
'realtime_sum_connections_connected',
5456
startDate,
5557
endDate,
5658
interval,
5759
databaseIdentifier
5860
)
5961

60-
const transformedData = (data?.data ?? []).map((p) => {
61-
const valueAsNumber = Number(p.realtime_connections_connected)
62-
return {
63-
...p,
64-
realtime_connections_connected: Number.isNaN(valueAsNumber) ? 0 : valueAsNumber,
65-
}
66-
})
67-
6862
const attributes = [
6963
{
70-
attribute: 'realtime_connections_connected',
71-
label: 'Connections',
64+
attribute: 'realtime_sum_connections_connected',
65+
label: 'Connected Clients',
7266
},
7367
]
7468

75-
return { data: transformedData, attributes }
69+
return { data: data?.data || [], attributes }
7670
},
7771
},
7872
{
79-
id: 'channel-events',
80-
label: 'Channel Events',
73+
id: 'broadcast-events',
74+
label: 'Broadcast Events',
8175
valuePrecision: 0,
8276
hide: false,
77+
showNewBadge: true,
8378
showTooltip: true,
8479
showLegend: false,
8580
showMaxValue: false,
8681
hideChartType: false,
87-
defaultChartStyle: 'line',
82+
defaultChartStyle: 'bar',
8883
titleTooltip: '',
8984
availableIn: ['free', 'pro', 'team', 'enterprise'],
9085
dataProvider: async () => {
@@ -112,6 +107,84 @@ export const realtimeReports = ({
112107
return { data: transformedData || [], attributes }
113108
},
114109
},
110+
111+
{
112+
id: 'presence-events',
113+
label: 'Presence Events',
114+
valuePrecision: 0,
115+
hide: false,
116+
showNewBadge: true,
117+
showTooltip: true,
118+
showLegend: false,
119+
showMaxValue: false,
120+
hideChartType: false,
121+
defaultChartStyle: 'bar',
122+
titleTooltip: '',
123+
availableIn: ['free', 'pro', 'team', 'enterprise'],
124+
dataProvider: async () => {
125+
const { data } = await runInfraMonitoringQuery(
126+
projectRef,
127+
'realtime_channel_presence_events',
128+
startDate,
129+
endDate,
130+
interval,
131+
databaseIdentifier
132+
)
133+
134+
const transformedData = data?.map((p) => ({
135+
...p,
136+
realtime_channel_presence_events: Number(p.realtime_channel_presence_events) || 0,
137+
}))
138+
139+
const attributes = [
140+
{
141+
attribute: 'realtime_channel_presence_events',
142+
label: 'Events',
143+
},
144+
]
145+
146+
return { data: transformedData || [], attributes }
147+
},
148+
},
149+
150+
{
151+
id: 'db-events',
152+
label: 'Postgres Changes Events',
153+
valuePrecision: 0,
154+
hide: false,
155+
showNewBadge: true,
156+
showTooltip: true,
157+
showLegend: false,
158+
showMaxValue: false,
159+
hideChartType: false,
160+
defaultChartStyle: 'bar',
161+
titleTooltip: '',
162+
availableIn: ['free', 'pro', 'team', 'enterprise'],
163+
dataProvider: async () => {
164+
const { data } = await runInfraMonitoringQuery(
165+
projectRef,
166+
'realtime_channel_db_events',
167+
startDate,
168+
endDate,
169+
interval,
170+
databaseIdentifier
171+
)
172+
173+
const transformedData = data?.map((p) => ({
174+
...p,
175+
realtime_channel_db_events: Number(p.realtime_channel_db_events) || 0,
176+
}))
177+
178+
const attributes = [
179+
{
180+
attribute: 'realtime_channel_db_events',
181+
label: 'Events',
182+
},
183+
]
184+
185+
return { data: transformedData || [], attributes }
186+
},
187+
},
115188
{
116189
id: 'realtime_rate_of_channel_joins',
117190
label: 'Rate of Channel Joins',
@@ -147,7 +220,7 @@ export const realtimeReports = ({
147220
},
148221
{
149222
id: 'realtime_payload_size',
150-
label: 'Broadcast Payload Size',
223+
label: 'Message Payload Size',
151224
valuePrecision: 2,
152225
showNewBadge: true,
153226
hide: false,
@@ -157,7 +230,7 @@ export const realtimeReports = ({
157230
showMaxValue: false,
158231
hideChartType: false,
159232
defaultChartStyle: 'line',
160-
titleTooltip: 'Size of broadcast payloads sent through realtime.',
233+
titleTooltip: 'Median size of message payloads sent',
161234
availableIn: ['free', 'pro', 'team', 'enterprise'],
162235
YAxisProps: {
163236
width: 50,
@@ -177,57 +250,56 @@ export const realtimeReports = ({
177250
const attributes = [
178251
{
179252
attribute: 'realtime_payload_size',
180-
label: 'Payload Size (bytes)',
253+
label: 'Median Payload Size (bytes)',
181254
},
182255
]
183256

184257
return { data: data?.data || [], attributes }
185258
},
186259
},
187260
{
188-
id: 'realtime_sum_connections_connected',
189-
label: 'Connected Clients',
190-
valuePrecision: 0,
191-
hide: false,
261+
id: 'realtime_replication_connection_lag',
262+
label: 'Broadcast From Database Replication Lag',
263+
valuePrecision: 2,
192264
showNewBadge: true,
265+
hide: false,
266+
showSumAsDefaultHighlight: false,
193267
showTooltip: true,
194268
showLegend: false,
195-
showMaxValue: true,
269+
showMaxValue: false,
196270
hideChartType: false,
197271
defaultChartStyle: 'line',
198-
titleTooltip: 'Total number of connected realtime clients.',
199-
availableIn: ['free', 'pro', 'team', 'enterprise'],
272+
titleTooltip:
273+
'Median time between database commit and broadcast when using broadcast from database.',
274+
availableIn: ['pro', 'team', 'enterprise'],
275+
YAxisProps: {
276+
width: 50,
277+
tickFormatter: (value: number) => `${value}ms`,
278+
},
279+
format: (value: unknown) => `${Number(value).toFixed(2)}ms`,
200280
dataProvider: async () => {
201281
const data = await runInfraMonitoringQuery(
202282
projectRef,
203-
'realtime_sum_connections_connected',
283+
'realtime_replication_connection_lag',
204284
startDate,
205285
endDate,
206286
interval,
207287
databaseIdentifier
208288
)
209289

210-
const transformedData = (data?.data ?? []).map((p) => {
211-
const valueAsNumber = Number(p.realtime_sum_connections_connected)
212-
return {
213-
...p,
214-
realtime_sum_connections_connected: Number.isNaN(valueAsNumber) ? 0 : valueAsNumber,
215-
}
216-
})
217-
218290
const attributes = [
219291
{
220-
attribute: 'realtime_sum_connections_connected',
221-
label: 'Connected Clients',
292+
attribute: 'realtime_replication_connection_lag',
293+
label: 'Median Replication Lag (ms)',
222294
},
223295
]
224296

225-
return { data: transformedData, attributes }
297+
return { data: data?.data || [], attributes }
226298
},
227299
},
228300
{
229-
id: 'realtime_replication_connection_lag',
230-
label: 'Replication Connection Lag',
301+
id: 'realtime_read_authorization_rls_execution_time',
302+
label: '(Read) Private Channel Subscription RLS Execution Time',
231303
valuePrecision: 2,
232304
showNewBadge: true,
233305
hide: false,
@@ -237,7 +309,8 @@ export const realtimeReports = ({
237309
showMaxValue: false,
238310
hideChartType: false,
239311
defaultChartStyle: 'line',
240-
titleTooltip: 'Time between database commit and broadcast when using broadcast from database.',
312+
titleTooltip:
313+
'Execution median time of RLS (Row Level Security) to subscribe to a private channel',
241314
availableIn: ['pro', 'team', 'enterprise'],
242315
YAxisProps: {
243316
width: 50,
@@ -247,7 +320,7 @@ export const realtimeReports = ({
247320
dataProvider: async () => {
248321
const data = await runInfraMonitoringQuery(
249322
projectRef,
250-
'realtime_replication_connection_lag',
323+
'realtime_read_authorization_rls_execution_time',
251324
startDate,
252325
endDate,
253326
interval,
@@ -256,17 +329,17 @@ export const realtimeReports = ({
256329

257330
const attributes = [
258331
{
259-
attribute: 'realtime_replication_connection_lag',
260-
label: 'Replication Lag (ms)',
332+
attribute: 'realtime_read_authorization_rls_execution_time',
333+
label: 'RLS Execution Time (ms)',
261334
},
262335
]
263336

264337
return { data: data?.data || [], attributes }
265338
},
266339
},
267340
{
268-
id: 'realtime_authorization_rls_execution_time',
269-
label: 'RLS Execution Time',
341+
id: 'realtime_write_authorization_rls_execution_time',
342+
label: '(Write) Private Channel Subscription RLS Execution Time',
270343
valuePrecision: 2,
271344
showNewBadge: true,
272345
hide: false,
@@ -276,7 +349,8 @@ export const realtimeReports = ({
276349
showMaxValue: false,
277350
hideChartType: false,
278351
defaultChartStyle: 'line',
279-
titleTooltip: 'Execution time of RLS (Row Level Security) checks for realtime authorization.',
352+
titleTooltip:
353+
'Execution median time of RLS (Row Level Security) to publish to a private channel',
280354
availableIn: ['pro', 'team', 'enterprise'],
281355
YAxisProps: {
282356
width: 50,
@@ -286,7 +360,7 @@ export const realtimeReports = ({
286360
dataProvider: async () => {
287361
const data = await runInfraMonitoringQuery(
288362
projectRef,
289-
'realtime_authorization_rls_execution_time',
363+
'realtime_write_authorization_rls_execution_time',
290364
startDate,
291365
endDate,
292366
interval,
@@ -295,7 +369,7 @@ export const realtimeReports = ({
295369

296370
const attributes = [
297371
{
298-
attribute: 'realtime_authorization_rls_execution_time',
372+
attribute: 'realtime_write_authorization_rls_execution_time',
299373
label: 'RLS Execution Time (ms)',
300374
},
301375
]

0 commit comments

Comments
 (0)