The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: update truncation detection logic to check all underlying data points provided
TzeYiingfa96ad246a39
diff --git a/studio/components/interfaces/Settings/Logs/Logs.utils.ts b/studio/components/interfaces/Settings/Logs/Logs.utils.tsindex 0759259ff80..bcbe189bb74 100644--- a/studio/components/interfaces/Settings/Logs/Logs.utils.ts+++ b/studio/components/interfaces/Settings/Logs/Logs.utils.ts@@ -379,8 +379,9 @@ export const fillTimeseries = (const maxDate = max ? dayjs.utc(max) : dayjs.utc(Math.max.apply(null, dates as number[]))const minDate = min ? dayjs.utc(min) : dayjs.utc(Math.min.apply(null, dates as number[]))- const truncationSample = timeseriesData.length > 0 ? timeseriesData[0][timestampKey] : min || max- const truncation = getTimestampTruncation(truncationSample)+ // const truncationSample = timeseriesData.length > 0 ? timeseriesData[0][timestampKey] : min || max+ const truncationSamples = timeseriesData.length > 0 ? dates : [minDate, maxDate]+ const truncation = getTimestampTruncation(truncationSamples as Dayjs[])const newData = timeseriesData.map((datum) => {const iso = dayjs.utc(datum[timestampKey]).toISOString()@@ -413,10 +414,30 @@ export const fillTimeseries = (return newData}-export const getTimestampTruncation = (datetime: string): 'second' | 'minute' | 'hour' | 'day' => {- const values = ['second', 'minute', 'hour', 'day'].map((key) =>- dayjs(datetime).get(key as dayjs.UnitType)+export const getTimestampTruncation = (samples: Dayjs[]): 'second' | 'minute' | 'hour' | 'day' => {+ const truncationCounts = samples.reduce(+ (acc, sample) => {+ const truncation = _getTruncation(sample)+ acc[truncation] += 1++ return acc+ },+ {+ second: 0,+ minute: 0,+ hour: 0,+ day: 0,+ })++ const mostLikelyTruncation = (+ Object.keys(truncationCounts) as (keyof typeof truncationCounts)[]+ ).reduce((a, b) => (truncationCounts[a] > truncationCounts[b] ? a : b))+ return mostLikelyTruncation+}++const _getTruncation = (date: Dayjs) => {+ const values = ['second', 'minute', 'hour', 'day'].map((key) => date.get(key as dayjs.UnitType))const zeroCount = values.reduce((acc, value) => {if (value === 0) {acc += 1diff --git a/studio/tests/pages/projects/Logs.utils.test.js b/studio/tests/pages/projects/Logs.utils.test.jsindex 499cb7d8256..321bd97f14a 100644--- a/studio/tests/pages/projects/Logs.utils.test.js+++ b/studio/tests/pages/projects/Logs.utils.test.js@@ -144,9 +144,9 @@ test.each([{ timestamp: '2023-04-26T20:00:00.000Z', count: 0 },],},- // fill multiple keys in one go- {- case: 'fill beyond min/max',+ // fill multiple keys in one go+ {+ case: 'fill multiple keys when both not given',data: [],len: 2,min: '2023-04-26T18:00:00.000Z',@@ -157,6 +157,74 @@ test.each([{ timestamp: '2023-04-26T19:00:00.000Z', count: 0, other: 0 },],},++ {+ case: 'truncation detection should check underlying data',+ data: [+ {+ timestamp: '2023-05-18T00:00:00',+ total_auth_requests: 4,+ total_realtime_requests: 0,+ total_rest_requests: 0,+ total_storage_requests: 0,+ },+ {+ timestamp: '2023-05-18T03:00:00',+ total_auth_requests: 4,+ total_realtime_requests: 0,+ total_rest_requests: 0,+ total_storage_requests: 0,+ },+ {+ timestamp: '2023-05-18T07:00:00',+ total_auth_requests: 4,+ total_realtime_requests: 0,+ total_rest_requests: 0,+ total_storage_requests: 0,+ },+ {+ timestamp: '2023-05-18T08:00:00',+ total_auth_requests: 2,+ total_realtime_requests: 0,+ total_rest_requests: 0,+ total_storage_requests: 0,+ },+ {+ timestamp: '2023-05-18T09:00:00',+ total_auth_requests: 2,+ total_realtime_requests: 0,+ total_rest_requests: 0,+ total_storage_requests: 0,+ },+ {+ timestamp: '2023-05-18T13:00:00',+ total_auth_requests: 0,+ total_realtime_requests: 0,+ total_rest_requests: 0,+ total_storage_requests: 0,+ },+ {+ timestamp: '2023-05-18T16:00:00',+ total_auth_requests: 0,+ total_realtime_requests: 0,+ total_rest_requests: 1,+ total_storage_requests: 0,+ },+ ],+ len: 24,+ min: '2023-05-18T00:00:00',+ max: '2023-05-18T23:00:00',+ valKey: ['total_auth_requests', 'total_realtime_requests', 'total_rest_requests', 'total_storage_requests'],+ includes: [ {+ // timestamp format is with higher precision and with tz+ timestamp: '2023-05-18T14:00:00.000Z',+ total_auth_requests: 0,+ total_realtime_requests: 0,+ total_rest_requests: 0,+ total_storage_requests: 0,+ },+ ],+ },])('fillTimeseries : $case',({ data, len, includes, min, max, tsKey = 'timestamp', valKey = 'count', defaultVal = 0 }) => {