mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
Added in even more query templates, added template filtering
This commit is contained in:
1 parent
fc67028ac5
commit
b4e0fbbf27
6 files changed
+65
-29
No files matched your search
@@ -64,9 +64,9 @@ const ProjectUsage: FC<Props> = ({ project }) => {
|
||||
if (timestampDigits < 16) {
|
||||
// pad unix timestamp with additional 0 and then forward
|
||||
const paddedTimestamp = String(timestamp) + '0'.repeat(16 - timestampDigits)
|
||||
router.push(`/project/${ref}/settings/logs/rest?te=${paddedTimestamp}&s=${search}`)
|
||||
router.push(`/project/${ref}/settings/logs/api?te=${paddedTimestamp}`)
|
||||
} else {
|
||||
router.push(`/project/${ref}/settings/logs/rest?te=${timestamp}&s=${search}`)
|
||||
router.push(`/project/${ref}/settings/logs/api?te=${timestamp}`)
|
||||
}
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -1,25 +1,63 @@
|
||||
import { LogTemplate } from '.'
|
||||
import { LogTemplate, LogType } from '.'
|
||||
|
||||
export const TEMPLATES: LogTemplate[] = [
|
||||
{ label: 'Recent Errors', mode: 'simple', searchString: '[Ee]rror|\\s[45][0-9][0-9]\\s' },
|
||||
{
|
||||
label: 'Recent Errors',
|
||||
mode: 'simple',
|
||||
searchString: '[Ee]rror|\\s[45][0-9][0-9]\\s',
|
||||
for: ['api'],
|
||||
},
|
||||
{
|
||||
label: 'Commits',
|
||||
mode: 'simple',
|
||||
searchString: 'COMMIT',
|
||||
for: ['database'],
|
||||
},
|
||||
|
||||
{
|
||||
label: '10 Minutes Ago',
|
||||
mode: 'simple',
|
||||
searchString: 'timestamp < TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 10 MINUTE)',
|
||||
for: ['database', 'api'],
|
||||
},
|
||||
{
|
||||
label: 'POST or PATCH',
|
||||
mode: 'custom',
|
||||
searchString:
|
||||
"REGEXP_CONTAINS(event_message, 'POST') OR REGEXP_CONTAINS(event_message, 'PATCH')",
|
||||
for: ['api'],
|
||||
},
|
||||
{
|
||||
label: 'Metadata IP',
|
||||
mode: 'custom',
|
||||
searchString:
|
||||
`SELECT timestamp, h.x_real_ip
|
||||
searchString: `SELECT timestamp, h.x_real_ip
|
||||
FROM edge_logs
|
||||
LEFT JOIN UNNEST(metadata) as m ON TRUE
|
||||
LEFT JOIN UNNEST(m.request) AS r ON TRUE
|
||||
LEFT JOIN UNNEST(r.headers) AS h ON TRUE
|
||||
WHERE h.x_real_ip IS NOT NULL
|
||||
`,
|
||||
for: ['database'],
|
||||
},
|
||||
{
|
||||
label: 'Requests by Country',
|
||||
mode: 'custom',
|
||||
searchString: `SELECT
|
||||
cf.country, count(*) as count
|
||||
FROM edge_logs
|
||||
LEFT JOIN UNNEST(metadata) as m ON TRUE
|
||||
LEFT JOIN UNNEST(m.request) AS r ON TRUE
|
||||
LEFT JOIN UNNEST(r.cf) AS cf ON TRUE
|
||||
GROUP BY
|
||||
cf.country
|
||||
ORDER BY
|
||||
DESC count
|
||||
`,
|
||||
for: ['api'],
|
||||
},
|
||||
]
|
||||
|
||||
export const DEFAULT_QUERY = 'SELECT timestamp, event_message FROM postgres_logs;'
|
||||
export const LOG_TYPE_LABEL_MAPPING: { [k: LogType]: string } = {
|
||||
api: 'API',
|
||||
database: 'Database',
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
interface Metadata {
|
||||
[key: string]: string | number | Object | Object[]
|
||||
}
|
||||
export type LogSearchCallback = (filters: { query: string; from?: string, fromMicro?: number }) => void
|
||||
export type LogSearchCallback = (filters: {
|
||||
query: string
|
||||
from?: string
|
||||
fromMicro?: number
|
||||
}) => void
|
||||
export interface LogData {
|
||||
id: string
|
||||
timestamp: number
|
||||
@@ -12,6 +16,7 @@ export interface LogData {
|
||||
export interface LogTemplate {
|
||||
label?: string
|
||||
mode: 'custom' | 'simple'
|
||||
for?: LogType[]
|
||||
searchString: string
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { LogType, LOG_TYPE_LABEL_MAPPING } from 'components/interfaces/Settings/Logs'
|
||||
import { ProductMenuGroup } from 'components/ui/ProductMenu/ProductMenu.types'
|
||||
import { LOG_TYPE_LABEL_MAPPING } from 'lib/constants'
|
||||
|
||||
export const generateSettingsMenu = (ref: string): ProductMenuGroup[] => {
|
||||
const logTypes: LogType[] = ['database', 'api']
|
||||
|
||||
return [
|
||||
{
|
||||
title: 'Project settings',
|
||||
@@ -20,15 +22,12 @@ export const generateSettingsMenu = (ref: string): ProductMenuGroup[] => {
|
||||
},
|
||||
{
|
||||
title: 'Logs',
|
||||
// items: ['database', 'auth', 'realtime', 'rest', 'storage'].map((type: string) => {
|
||||
items: ['database', 'rest'].map((type: string) => {
|
||||
return {
|
||||
name: LOG_TYPE_LABEL_MAPPING[type],
|
||||
key: `logs-${type}`,
|
||||
url: `/project/${ref}/settings/logs/${type}`,
|
||||
items: [],
|
||||
}
|
||||
}),
|
||||
items: logTypes.map((type: string) => ({
|
||||
name: LOG_TYPE_LABEL_MAPPING[type],
|
||||
key: `logs-${type}`,
|
||||
url: `/project/${ref}/settings/logs/${type}`,
|
||||
items: [],
|
||||
})),
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -88,14 +88,6 @@ export const POLICY_MODAL_VIEWS = {
|
||||
REVIEW: 'REVIEW',
|
||||
}
|
||||
|
||||
export const LOG_TYPE_LABEL_MAPPING: { [k: string]: string } = {
|
||||
rest: 'API',
|
||||
realtime: 'Realtime',
|
||||
auth: 'Auth',
|
||||
storage: 'Storage',
|
||||
database: 'Database',
|
||||
}
|
||||
|
||||
export const GOTRUE_ERRORS = {
|
||||
UNVERIFIED_GITHUB_USER: 'Error sending confirmation mail',
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
|
||||
import { withAuth } from 'hooks'
|
||||
import { get } from 'lib/common/fetch'
|
||||
import { API_URL, LOG_TYPE_LABEL_MAPPING } from 'lib/constants'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { SettingsLayout } from 'components/layouts/'
|
||||
import CodeEditor from 'components/ui/CodeEditor'
|
||||
import {
|
||||
@@ -28,6 +28,8 @@ import {
|
||||
TEMPLATES,
|
||||
LogData,
|
||||
LogSearchCallback,
|
||||
LogType,
|
||||
LOG_TYPE_LABEL_MAPPING,
|
||||
} from 'components/interfaces/Settings/Logs'
|
||||
import { uuidv4 } from 'lib/helpers'
|
||||
import useSWRInfinite from 'swr/infinite'
|
||||
@@ -64,7 +66,7 @@ export const LogPage: NextPage = () => {
|
||||
timestamp_start: '',
|
||||
timestamp_end: '',
|
||||
})
|
||||
const title = `Logs - ${LOG_TYPE_LABEL_MAPPING[type as string]}`
|
||||
const title = `Logs - ${LOG_TYPE_LABEL_MAPPING[type as LogType]}`
|
||||
const checkIfSelectQuery = (value: string) =>
|
||||
value.toLowerCase().includes('select') ? true : false
|
||||
const isSelectQuery = checkIfSelectQuery(editorValue)
|
||||
@@ -246,7 +248,7 @@ export const LogPage: NextPage = () => {
|
||||
isCustomQuery={mode === 'custom'}
|
||||
isLoading={isValidating}
|
||||
newCount={newCount}
|
||||
templates={TEMPLATES}
|
||||
templates={TEMPLATES.filter((template) => template.for?.includes(type as LogType))}
|
||||
onRefresh={handleRefresh}
|
||||
onSearch={handleSearch}
|
||||
defaultSearchValue={params.search_query}
|
||||
|
||||
Reference in new issue
Block a user