Skip to content

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

remove WHERE querying from logging dashboard

TzeYiing95652aca41be
diff --git a/studio/components/interfaces/Settings/Logs/Logs.constants.ts b/studio/components/interfaces/Settings/Logs/Logs.constants.ts
index 6418f5066cc..bf641972f53 100644
--- a/studio/components/interfaces/Settings/Logs/Logs.constants.ts
+++ b/studio/components/interfaces/Settings/Logs/Logs.constants.ts
@@ -13,13 +13,6 @@ export const TEMPLATES: LogTemplate[] = [
searchString: 'COMMIT',
for: ['database'],
},
-
- {
- label: '10 Minutes Ago',
- mode: 'custom',
- searchString: 'timestamp < TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 10 MINUTE)',
- for: ['database', 'api'],
- },
{
label: 'Commits By User',
mode: 'custom',
@@ -70,10 +63,11 @@ export const LOG_TYPE_LABEL_MAPPING: { [k: string]: string } = {
database: 'Database',
}
-export const genDefaultQuery = (table: string, where: string = ''): string => `SELECT
+export const genDefaultQuery = (table: string): string => `SELECT
id, timestamp, event_message, metadata
FROM
- ${table}${where ? '\nWHERE ' + where : ''}
+ ${table}
+LIMIT 100
`
export const genCountQuery = (table: string): string => `SELECT count(*) as count FROM ${table}`
diff --git a/studio/pages/project/[ref]/settings/logs/[type].tsx b/studio/pages/project/[ref]/settings/logs/[type].tsx
index 8247c3aa927..37d626c33d1 100644
--- a/studio/pages/project/[ref]/settings/logs/[type].tsx
+++ b/studio/pages/project/[ref]/settings/logs/[type].tsx
@@ -11,7 +11,6 @@ import {
Button,
IconInfo,
Card,
- Loading,
Input,
} from '@supabase/ui'
@@ -63,14 +62,12 @@ export const LogPage: NextPage = () => {
type: '',
search_query: '',
sql: '',
- where: '',
timestamp_start: '',
timestamp_end: '',
})
const title = `Logs - ${LOG_TYPE_LABEL_MAPPING[type as keyof typeof LOG_TYPE_LABEL_MAPPING]}`
const checkIfSelectQuery = (value: string) =>
value.toLowerCase().includes('select') ? true : false
- const isSelectQuery = checkIfSelectQuery(editorValue)
const table = type === 'api' ? 'edge_logs' : 'postgres_logs'
useEffect(() => {
setParams({ ...params, type: type as string })
@@ -182,17 +179,12 @@ export const LogPage: NextPage = () => {
const onSelectTemplate = (template: LogTemplate) => {
setMode(template.mode)
if (template.mode === 'simple') {
- setParams((prev) => ({ ...prev, search_query: template.searchString, sql: '', where: '' }))
+ setParams((prev) => ({ ...prev, search_query: template.searchString, sql: '' }))
} else {
setEditorValue(template.searchString)
setParams((prev) => ({
...prev,
- where: checkIfSelectQuery(template.searchString)
- ? ''
- : cleanEditorValue(template.searchString),
- sql: checkIfSelectQuery(template.searchString)
- ? cleanEditorValue(template.searchString)
- : '',
+ sql: template.searchString,
search_query: '',
timestamp_end: '',
}))
@@ -200,11 +192,7 @@ export const LogPage: NextPage = () => {
}
}
const handleEditorSubmit = () => {
- setParams((prev) => ({
- ...prev,
- sql: checkIfSelectQuery(editorValue) ? editorValue : genDefaultQuery(table, editorValue),
- search_query: '',
- }))
+ setParams((prev) => ({ ...prev, sql: editorValue, search_query: '' }))
router.push({
pathname: router.pathname,
query: {
@@ -221,7 +209,6 @@ export const LogPage: NextPage = () => {
...prev,
search_query: query || '',
timestamp_end: unixMicro ? String(unixMicro) : '',
- where: '',
sql: '',
}))
router.push({
@@ -270,7 +257,7 @@ export const LogPage: NextPage = () => {
/>
</div>
<div className="flex flex-row justify-end items-center px-2 py-1 w-full">
- {isSelectQuery && (
+ {mode === 'custom' && (
<InformationBox
className="shrink mr-auto"
block={false}
@@ -321,9 +308,8 @@ export const LogPage: NextPage = () => {
)}
<LogTable data={logData} isCustomQuery={mode === 'custom'} />
- {/* Footer section of log ui, appears below table */}
<div className="p-2">
- {!isSelectQuery && (
+ {mode === 'simple' && (
<Button onClick={() => setSize(size + 1)} icon={<IconRewind />} type="default">
Load older
</Button>
diff --git a/studio/tests/pages/projects/logs.test.js b/studio/tests/pages/projects/logs.test.js
index 30c3f750904..519dc6d24ad 100644
--- a/studio/tests/pages/projects/logs.test.js
+++ b/studio/tests/pages/projects/logs.test.js
@@ -170,61 +170,6 @@ test('poll count for new messages', async () => {
await waitFor(() => screen.getByText(/happened/))
})
-test('where clause will build an sql query', async () => {
- get.mockImplementation((url) => {
- if (url.includes('sql') && url.includes('something')) {
- return {
- result: [logDataFixture({ event_message: 'some event happened' })],
- }
- }
- return { result: [] }
- })
- const { container } = render(<LogPage />)
- // fill search bar with some value, should be ignored when in custom mode
- userEvent.type(screen.getByPlaceholderText(/Search/), 'search_value')
- userEvent.click(screen.getByTitle('Go'))
- // clear mock calls, for clean assertions
- get.mockClear()
-
- let editor = container.querySelector('.monaco-editor')
- expect(editor).toBeFalsy()
- // TODO: abstract this out into a toggle selection helper
- const toggle = getToggleByText(/via query/)
- expect(toggle).toBeTruthy()
- userEvent.click(toggle)
- await waitFor(() => {
- editor = container.querySelector('.monaco-editor')
- expect(editor).toBeTruthy()
- })
- editor = container.querySelector('.monaco-editor')
- // clear the default query
- userEvent.type(editor, '{backspace}'.repeat(100))
- // type where clause
- userEvent.type(editor, 'metadata.field = something')
- userEvent.click(screen.getByText('Run'))
- await waitFor(
- () => {
- expect(get).toHaveBeenCalledWith(expect.stringContaining('where'))
- expect(get).toHaveBeenCalledWith(expect.stringContaining('metadata.field'))
-
- // updates router query params
- const router = useRouter()
- expect(router.push).toHaveBeenCalledWith(
- expect.objectContaining({
- pathname: expect.any(String),
- query: expect.objectContaining({
- q: expect.stringContaining('something'),
- }),
- })
- )
-
- // should ignore search bar value
- expect(get).not.toHaveBeenCalledWith(expect.stringContaining('search_value'))
- })
-
- await screen.findByText(/happened/)
-})
-
test('s= query param will populate the search bar', async () => {
const router = defaultRouterMock()
router.query = { ...router.query, type: 'api', s: 'someSearch' }
@@ -242,7 +187,7 @@ test('q= query param will populate the query input', async () => {
render(<LogPage />)
// should populate editor with the query param
await waitFor(() => {
- expect(get).toHaveBeenCalledWith(expect.stringContaining('where=some_query'))
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('sql=some_query'))
})
// query takes precedence of search queryparam
@@ -375,7 +320,7 @@ test('bug: load older btn does not error out when previous page is empty', async
})
test('bug: log selection gets hidden when custom query is run', async () => {
- const data = [
+ const result = [
logDataFixture({
event_message: 'some event happened',
metadata: {
@@ -383,9 +328,9 @@ test('bug: log selection gets hidden when custom query is run', async () => {
},
}),
]
- get.mockResolvedValue({ data })
+ get.mockResolvedValue({ result })
const {container} =render(<LogPage />)
- fireEvent.click(await screen.findByText(/happened/))
+ userEvent.click(await screen.findByText(/happened/))
await screen.findByDisplayValue(/something_value/)
get.mockResolvedValue({ data: [] })
diff --git a/web/docs/guides/platform/logs.mdx b/web/docs/guides/platform/logs.mdx
index de9f87acafb..e40ac2a8a8d 100644
--- a/web/docs/guides/platform/logs.mdx
+++ b/web/docs/guides/platform/logs.mdx
@@ -28,23 +28,9 @@ To access advanced querying features, you will need to enable **custom queries**
![Enabling query mode](/img/guides/platform/logs/query-mode.png)
-Advanced queries can take two forms, **WHERE queries** and **SELECT queries**.
-### WHERE Queries
-To perform advanced filtering, you add in additional `WHERE` filters into the query editor. These will be inserted and combined with the existing query. Doing so will allow you to access chronological features such as **loading older logs** and **metadata viewing**.
-
-For example, you may query the API event messages as well as the timestamp field simultaneously:
-
-```sql
-REGEXP_CONTAINS(event_message, "/auth") AND REGEXP_CONTAINS(event_message, "400") AND timestamp < TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 10 MINUTE)
-```
-
-![WHERE filter example](/img/guides/platform/logs/where-filter.png)
-
-### SELECT Queries
-
-`SELECT` queries allow for much more complex and powerful aggregated result sets, that would allow more in-depth analysis of log data.
+`SELECT` queries allow complex and powerful aggregated result sets, letting you to perform in-depth analysis of your log data.
For example, you may enter the following into the API logs dashboard to query for each user's IP address:
@@ -64,7 +50,7 @@ You may notice that the table name reference, `edge_logs`, is required in order
The table references are as follows:
-- API - `edge_logs`
+- API Edge - `edge_logs`
- Database - `postgres_logs`
Note that cross-table joining is currently not supported.
diff --git a/web/static/img/guides/platform/logs/where-filter.png b/web/static/img/guides/platform/logs/where-filter.png
deleted file mode 100644
index 24bf4b5552a..00000000000
Binary files a/web/static/img/guides/platform/logs/where-filter.png and /dev/null differ