From e6b5b66edf00237044428aa1574e1d99e1469c57 Mon Sep 17 00:00:00 2001 From: Sooraj Date: Fri, 21 May 2021 14:36:35 +0530 Subject: [PATCH] console: add pagination on event logs & fix data mismatch on event logs table GitOrigin-RevId: 5643a0357dd11963cde53a148911844e4c754510 --- .../components/Common/FilterQuery/state.ts | 63 +- .../Common/Components/EventsSubTable.tsx | 55 +- .../Events/Common/Components/EventsTable.tsx | 8 +- .../PendingEvents/PendingEvents.tsx | 1 + .../ProcessedEvents/ProcessedEvents.tsx | 1 + .../__snapshots__/utils.test.ts.snap | 761 ++++++++++++++++++ .../Events/__tests__/fixtures/events.json | 86 ++ .../__tests__/fixtures/invocations.json | 222 +++++ .../Services/Events/__tests__/utils.test.ts | 26 + .../src/components/Services/Events/utils.ts | 30 + .../metadataTableUtils.test.ts.snap | 111 +++ .../__tests__/metadataTableUtils.test.ts | 176 ++++ console/src/metadata/metadataTableUtils.ts | 99 ++- console/src/metadata/queryUtils.ts | 2 +- 14 files changed, 1575 insertions(+), 66 deletions(-) create mode 100644 console/src/components/Services/Events/__tests__/__snapshots__/utils.test.ts.snap create mode 100644 console/src/components/Services/Events/__tests__/fixtures/events.json create mode 100644 console/src/components/Services/Events/__tests__/fixtures/invocations.json create mode 100644 console/src/components/Services/Events/__tests__/utils.test.ts create mode 100644 console/src/metadata/__tests__/__snapshots__/metadataTableUtils.test.ts.snap create mode 100644 console/src/metadata/__tests__/metadataTableUtils.test.ts diff --git a/console/src/components/Common/FilterQuery/state.ts b/console/src/components/Common/FilterQuery/state.ts index e2d2b9e8216..014af0867a8 100644 --- a/console/src/components/Common/FilterQuery/state.ts +++ b/console/src/components/Common/FilterQuery/state.ts @@ -20,7 +20,11 @@ import { } from '../../../metadata/queryUtils'; import { EventKind } from '../../Services/Events/types'; import { isNotDefined } from '../utils/jsUtils'; -import { getDataTriggerLogsQuery } from '../../../metadata/metadataTableUtils'; +import { + getDataTriggerLogsCountQuery, + getDataTriggerLogsQuery, +} from '../../../metadata/metadataTableUtils'; +import { parseEventsSQLResp } from '../../Services/Events/utils'; const defaultFilter = makeValueFilter('', null, ''); const defaultSort = makeOrderBy('', 'asc'); @@ -94,13 +98,20 @@ export const useFilterQuery = ( } else if (triggerType === 'data') { endpoint = endpoints.query; if (triggerName) { - query = getDataTriggerLogsQuery( - triggerOp, - currentSource || 'default', - triggerName, - limitValue, - offsetValue - ); + query = { + args: [ + getDataTriggerLogsCountQuery(triggerName, triggerOp, currentSource), + getDataTriggerLogsQuery( + triggerOp, + currentSource ?? 'default', + triggerName, + limitValue, + offsetValue + ), + ], + source: currentSource ?? 'default', + type: 'bulk', + }; } else { return; // fixme: this should just be an error saying that there's no trigger name provided } @@ -116,38 +127,12 @@ export const useFilterQuery = ( ).then( (data: any) => { if (triggerType === 'data') { + setCount(Number(data?.[0].result?.[1]?.[0])); // formatting of the data - const allKeys = data.result[0]; - const resultsData = data.result.slice(1); - const formattedData: Record[] = []; - resultsData.forEach((values: string[]) => { - const dataObj: Record = {}; - allKeys.forEach((key: string, idx: number) => { - if (!dataObj[key]) { - // to avoid duplicate keys in the results - if (triggerOp !== 'invocation' && key === 'event_id') { - dataObj.invocation_id = dataObj.id; - dataObj.id = values[idx]; - } else if (key === 'request' || key === 'response') { - try { - dataObj[key] = JSON.parse(values[idx]); - } catch { - dataObj[key] = values[idx]; - } - } else { - dataObj[key] = values[idx]; - } - } - }); - formattedData.push(dataObj); - }); - - if (limitValue && offsetValue) { - setRows(formattedData.slice(offsetValue, offsetValue + limitValue)); - } else { - setRows(formattedData); - } - setCount(formattedData.length); + const formattedData: Record[] = parseEventsSQLResp( + data?.[1]?.result ?? [] + ); + setRows(formattedData); } else if (triggerOp !== 'invocation') { setRows(data?.events ?? []); } else { diff --git a/console/src/components/Services/Events/Common/Components/EventsSubTable.tsx b/console/src/components/Services/Events/Common/Components/EventsSubTable.tsx index 9c38a9c2758..2e11d30ca2f 100644 --- a/console/src/components/Services/Events/Common/Components/EventsSubTable.tsx +++ b/console/src/components/Services/Events/Common/Components/EventsSubTable.tsx @@ -9,10 +9,12 @@ import { SupportedEvents, getEventInvocationsLogByID, } from '../../../../../metadata/queryUtils'; -import { sanitiseRow } from '../../utils'; +import { parseEventsSQLResp, sanitiseRow } from '../../utils'; import { Dispatch, ReduxState } from '../../../../../types'; import requestAction from '../../../../../utils/requestAction'; import Endpoints from '../../../../../Endpoints'; +import { getDataTriggerInvocations } from '../../../../../metadata/metadataTableUtils'; +import { Spinner } from '../../../../UIKit/atoms'; interface Props extends InjectedReduxProps { rows: any[]; @@ -101,14 +103,43 @@ const EventsSubTable: React.FC = ({ triggerType, ...props }) => { - const [inv, setInvocations] = React.useState([]); + const [inv, setInvocations] = React.useState< + Record[] + >([]); const [errInfo, setErrInfo] = React.useState(null); + const [loading, setLoading] = React.useState(false); React.useEffect(() => { if (!triggerType || !props.event.id) { return; } - // TODO: handle a "loading" state + if (triggerType === 'data' && props.event.id) { + const url = Endpoints.query; + const payload = getDataTriggerInvocations(props.event.id); + const options = { + method: 'POST', + body: JSON.stringify(payload), + headers: props.headers, + }; + setLoading(true); + props + .getEventInvocationData(url, options) + .then(data => { + setLoading(false); + const parsed = parseEventsSQLResp(data?.result); + if (parsed) setInvocations(parsed); + if (data && data?.invocations && !data.error) { + setInvocations(data.invocations); + return; + } + setErrInfo(data.error); + }) + .catch(err => { + setErrInfo(err); + setLoading(false); + }); + return; + } const url = Endpoints.metadata; const payload = getEventInvocationsLogByID(triggerType, props.event.id); const options = { @@ -116,18 +147,34 @@ const EventsSubTable: React.FC = ({ body: JSON.stringify(payload), headers: props.headers, }; + setLoading(true); + props .getEventInvocationData(url, options) .then(data => { + setLoading(false); if (data && data?.invocations && !data.error) { setInvocations(data.invocations); return; } setErrInfo(data.error); }) - .catch(err => setErrInfo(err)); + .catch(err => { + setLoading(false); + setErrInfo(err); + }); }, []); + if (loading) { + return ( +
+
+ Recent Invocations: +
+ +
+ ); + } if (!makeAPICall || !triggerType) { return ; } diff --git a/console/src/components/Services/Events/Common/Components/EventsTable.tsx b/console/src/components/Services/Events/Common/Components/EventsTable.tsx index 95d5feda978..09922e4559c 100644 --- a/console/src/components/Services/Events/Common/Components/EventsTable.tsx +++ b/console/src/components/Services/Events/Common/Components/EventsTable.tsx @@ -149,12 +149,8 @@ const EventsTable: React.FC = props => { } }); - const invocationColumns = ['status', 'invoid', 'created_at']; - const invocationDataTriggerColumns = [ - 'status', - 'invocation_id', - 'created_at', - ]; + const invocationColumns = ['status', 'id', 'created_at']; + const invocationDataTriggerColumns = ['status', 'id', 'created_at']; const invocationGridHeadings: GridHeadingProps[] = [expanderActions]; const addToGridHeadings = (headAccArr: string[]) => { diff --git a/console/src/components/Services/Events/EventTriggers/PendingEvents/PendingEvents.tsx b/console/src/components/Services/Events/EventTriggers/PendingEvents/PendingEvents.tsx index 154fa1a428f..37a4626a658 100644 --- a/console/src/components/Services/Events/EventTriggers/PendingEvents/PendingEvents.tsx +++ b/console/src/components/Services/Events/EventTriggers/PendingEvents/PendingEvents.tsx @@ -33,6 +33,7 @@ const PendingEvents: React.FC = props => { runQuery={runQuery} columns={['id', 'delivered', 'created_at', 'tries']} identifier={triggerName} + triggerType="data" /> ); diff --git a/console/src/components/Services/Events/EventTriggers/ProcessedEvents/ProcessedEvents.tsx b/console/src/components/Services/Events/EventTriggers/ProcessedEvents/ProcessedEvents.tsx index 3f1a590deb0..9b6c4887325 100644 --- a/console/src/components/Services/Events/EventTriggers/ProcessedEvents/ProcessedEvents.tsx +++ b/console/src/components/Services/Events/EventTriggers/ProcessedEvents/ProcessedEvents.tsx @@ -34,6 +34,7 @@ const ProcessedEvents: React.FC = props => { runQuery={runQuery} columns={['id', 'delivered', 'created_at', 'tries']} identifier={triggerName} + triggerType="data" /> ); diff --git a/console/src/components/Services/Events/__tests__/__snapshots__/utils.test.ts.snap b/console/src/components/Services/Events/__tests__/__snapshots__/utils.test.ts.snap new file mode 100644 index 00000000000..f77bf0dc779 --- /dev/null +++ b/console/src/components/Services/Events/__tests__/__snapshots__/utils.test.ts.snap @@ -0,0 +1,761 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Events_Utils.ts parseEventsSQLResp should parse event invocations 1`] = ` +Array [ + Object { + "archived": false, + "created_at": "2021-05-18 07:40:32.81592", + "delivered": false, + "error": true, + "event_id": "7bc7b398-f1cd-4761-839d-44971e01be48", + "id": "31b4c28c-954d-4871-ba95-a6d7da8d6988", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 8, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"455d47a2c5d8f40e\\", \\"trace_id\\": \\"04415c5c0870f8f6\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.658771Z", + "delivery_info": Object { + "current_retry": 4, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 8, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "455d47a2c5d8f40e", + "trace_id": "04415c5c0870f8f6", + }, + }, + "id": "7bc7b398-f1cd-4761-839d-44971e01be48", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"04415c5c0870f8f6\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"d1260fcdfe50945e\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"de05cf247e935b7a\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:32.815484", + "delivered": false, + "error": true, + "event_id": "c3ac48be-a569-4d87-8c52-cb84309002ed", + "id": "bf1760ee-c628-4b94-b535-1d5453675958", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 6, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"5a75ae38fccf4473\\", \\"trace_id\\": \\"ecba73bac1b4601a\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.332379Z", + "delivery_info": Object { + "current_retry": 4, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 6, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "5a75ae38fccf4473", + "trace_id": "ecba73bac1b4601a", + }, + }, + "id": "c3ac48be-a569-4d87-8c52-cb84309002ed", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"ecba73bac1b4601a\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"1c3c460b36da4a0e\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"f309dbf4632da6a5\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:32.81517", + "delivered": false, + "error": true, + "event_id": "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "id": "5836823f-9104-489e-b339-946b45e266a9", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 9, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"77150de9d725e5df\\", \\"trace_id\\": \\"ea970ad818f358cf\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.831182Z", + "delivery_info": Object { + "current_retry": 4, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 9, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "77150de9d725e5df", + "trace_id": "ea970ad818f358cf", + }, + }, + "id": "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"ea970ad818f358cf\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"332c2f49df1cb4d2\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"3668323420f67bb1\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:32.815118", + "delivered": false, + "error": true, + "event_id": "423e5a24-d4e0-493a-83df-ecff0eca2398", + "id": "7b314fa3-fa10-4d1d-9c7b-0799e2a2345c", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 7, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"5e088982a14f9bdd\\", \\"trace_id\\": \\"da0635bf4fb444b1\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.490999Z", + "delivery_info": Object { + "current_retry": 4, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 7, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "5e088982a14f9bdd", + "trace_id": "da0635bf4fb444b1", + }, + }, + "id": "423e5a24-d4e0-493a-83df-ecff0eca2398", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"da0635bf4fb444b1\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"f92c4fac3a66595a\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"b3a34f8a72e89980\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:22.736277", + "delivered": false, + "error": true, + "event_id": "7bc7b398-f1cd-4761-839d-44971e01be48", + "id": "c6ec4304-3848-4c4c-a188-ff91ebe61ea0", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 8, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"455d47a2c5d8f40e\\", \\"trace_id\\": \\"04415c5c0870f8f6\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.658771Z", + "delivery_info": Object { + "current_retry": 3, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 8, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "455d47a2c5d8f40e", + "trace_id": "04415c5c0870f8f6", + }, + }, + "id": "7bc7b398-f1cd-4761-839d-44971e01be48", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"04415c5c0870f8f6\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"f520ea1624695587\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"2dc1b4d86426e316\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:22.736095", + "delivered": false, + "error": true, + "event_id": "423e5a24-d4e0-493a-83df-ecff0eca2398", + "id": "8c88c745-29eb-4637-ad2d-85f3d6ba82c4", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 7, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"5e088982a14f9bdd\\", \\"trace_id\\": \\"da0635bf4fb444b1\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.490999Z", + "delivery_info": Object { + "current_retry": 3, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 7, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "5e088982a14f9bdd", + "trace_id": "da0635bf4fb444b1", + }, + }, + "id": "423e5a24-d4e0-493a-83df-ecff0eca2398", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"da0635bf4fb444b1\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"d6bdb95ec116b8ff\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"01b61664322a458b\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:22.736039", + "delivered": false, + "error": true, + "event_id": "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "id": "48532d4d-ee73-4245-a8f6-378b034eb4f0", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 9, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"77150de9d725e5df\\", \\"trace_id\\": \\"ea970ad818f358cf\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.831182Z", + "delivery_info": Object { + "current_retry": 3, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 9, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "77150de9d725e5df", + "trace_id": "ea970ad818f358cf", + }, + }, + "id": "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"ea970ad818f358cf\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"4d8d92209b40eab3\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"876f35924d13168e\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:22.735757", + "delivered": false, + "error": true, + "event_id": "c3ac48be-a569-4d87-8c52-cb84309002ed", + "id": "33105396-99dc-446c-ac7f-d93c38ceb686", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 6, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"5a75ae38fccf4473\\", \\"trace_id\\": \\"ecba73bac1b4601a\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.332379Z", + "delivery_info": Object { + "current_retry": 3, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 6, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "5a75ae38fccf4473", + "trace_id": "ecba73bac1b4601a", + }, + }, + "id": "c3ac48be-a569-4d87-8c52-cb84309002ed", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"ecba73bac1b4601a\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"4fa95afd2b803b9c\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"de923514252481ca\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:11.704173", + "delivered": false, + "error": true, + "event_id": "423e5a24-d4e0-493a-83df-ecff0eca2398", + "id": "f7980cf5-7520-489a-87f1-f658773f9e60", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 7, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"5e088982a14f9bdd\\", \\"trace_id\\": \\"da0635bf4fb444b1\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.490999Z", + "delivery_info": Object { + "current_retry": 2, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 7, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "5e088982a14f9bdd", + "trace_id": "da0635bf4fb444b1", + }, + }, + "id": "423e5a24-d4e0-493a-83df-ecff0eca2398", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"da0635bf4fb444b1\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"2fbf0361df48ccc7\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"ebc5dd9ef22f9543\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:40:11.704093", + "delivered": false, + "error": true, + "event_id": "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "id": "18e6a7de-c38d-4f56-90f5-d0cc1298ea97", + "locked": "NULL", + "next_retry_at": "NULL", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 9, \\"name\\": \\"safs\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"77150de9d725e5df\\", \\"trace_id\\": \\"ea970ad818f358cf\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "request": Object { + "headers": Array [ + Object { + "name": "Content-Type", + "value": "application/json", + }, + Object { + "name": "User-Agent", + "value": "hasura-graphql-engine/v2.0.0-alpha.9", + }, + ], + "payload": Object { + "created_at": "2021-05-18T07:39:50.831182Z", + "delivery_info": Object { + "current_retry": 2, + "max_retries": 4, + }, + "event": Object { + "data": Object { + "new": Object { + "id": 9, + "name": "safs", + }, + "old": null, + }, + "op": "INSERT", + "session_variables": Object { + "x-hasura-role": "admin", + }, + "trace_context": Object { + "span_id": "77150de9d725e5df", + "trace_id": "ea970ad818f358cf", + }, + }, + "id": "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "table": Object { + "name": "users", + "schema": "public", + }, + "trigger": Object { + "name": "new_user", + }, + }, + "version": "2", + }, + "response": Object { + "data": Object { + "message": "\\"HttpExceptionRequest Request {\\\\n host = \\\\\\"httsssp.org\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\"X-B3-TraceId\\\\\\",\\\\\\"ea970ad818f358cf\\\\\\"),(\\\\\\"X-B3-SpanId\\\\\\",\\\\\\"18ac4aa73874b52d\\\\\\"),(\\\\\\"X-B3-ParentSpanId\\\\\\",\\\\\\"705e55f29e621be4\\\\\\"),(\\\\\\"Content-Type\\\\\\",\\\\\\"application/json\\\\\\"),(\\\\\\"User-Agent\\\\\\",\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\")]\\\\n path = \\\\\\"/post\\\\\\"\\\\n queryString = \\\\\\"\\\\\\"\\\\n method = \\\\\\"POST\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\"httsssp.org\\\\\\", service name: Just \\\\\\"80\\\\\\"): does not exist (Name or service not known))\\"", + }, + "type": "client_error", + "version": "2", + }, + "schema_name": "public", + "status": "1000", + "table_name": "users", + "tries": "5", + "trigger_name": "new_user", + }, +] +`; + +exports[`Events_Utils.ts parseEventsSQLResp should parse events 1`] = ` +Array [ + Object { + "archived": false, + "created_at": "2021-05-18 07:14:07.941913", + "delivered": false, + "error": false, + "id": "298f6a71-f503-46f1-814c-45daef0afe4d", + "locked": "NULL", + "next_retry_at": "2021-05-18 07:14:19.19469", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 5, \\"name\\": \\"dasds\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"28ff1f534abe461e\\", \\"trace_id\\": \\"8bb43c3d49b2c073\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "schema_name": "public", + "table_name": "users", + "tries": "1", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:14:07.778957", + "delivered": false, + "error": false, + "id": "b8fbfb81-3a13-4cc8-a4b4-1e97fade667a", + "locked": "NULL", + "next_retry_at": "2021-05-18 07:14:19.17979", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 4, \\"name\\": \\"dasds\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"e098ccedce27b446\\", \\"trace_id\\": \\"2d1eff74089d2ad5\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "schema_name": "public", + "table_name": "users", + "tries": "1", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:14:07.632082", + "delivered": false, + "error": false, + "id": "474d035b-8163-42c0-a240-9b9031452206", + "locked": "NULL", + "next_retry_at": "2021-05-18 07:14:19.192695", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 3, \\"name\\": \\"dasds\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"e5d2c45c9436a01f\\", \\"trace_id\\": \\"5ebb62f875d02dd3\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "schema_name": "public", + "table_name": "users", + "tries": "1", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:14:07.366513", + "delivered": false, + "error": false, + "id": "4671fb2b-1bdc-4615-9a0f-d384ef82e73a", + "locked": "NULL", + "next_retry_at": "2021-05-18 07:14:19.180674", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 2, \\"name\\": \\"dasds\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"ba9c5129d081a540\\", \\"trace_id\\": \\"5ab0b030acf37a3f\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "schema_name": "public", + "table_name": "users", + "tries": "1", + "trigger_name": "new_user", + }, + Object { + "archived": false, + "created_at": "2021-05-18 07:14:06.784375", + "delivered": false, + "error": false, + "id": "a9fe39f6-3d9e-49c9-941c-09b84274dc87", + "locked": "NULL", + "next_retry_at": "2021-05-18 07:14:19.196511", + "payload": "{\\"op\\": \\"INSERT\\", \\"data\\": {\\"new\\": {\\"id\\": 1, \\"name\\": \\"dasds\\"}, \\"old\\": null}, \\"trace_context\\": {\\"span_id\\": \\"d4939311aad3a0bc\\", \\"trace_id\\": \\"65c31bf94eb7f656\\"}, \\"session_variables\\": {\\"x-hasura-role\\": \\"admin\\"}}", + "schema_name": "public", + "table_name": "users", + "tries": "1", + "trigger_name": "new_user", + }, +] +`; diff --git a/console/src/components/Services/Events/__tests__/fixtures/events.json b/console/src/components/Services/Events/__tests__/fixtures/events.json new file mode 100644 index 00000000000..9a2dceaa447 --- /dev/null +++ b/console/src/components/Services/Events/__tests__/fixtures/events.json @@ -0,0 +1,86 @@ +[ + [ + "id", + "schema_name", + "table_name", + "trigger_name", + "payload", + "delivered", + "error", + "tries", + "created_at", + "locked", + "next_retry_at", + "archived" + ], + [ + "298f6a71-f503-46f1-814c-45daef0afe4d", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 5, \"name\": \"dasds\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"28ff1f534abe461e\", \"trace_id\": \"8bb43c3d49b2c073\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "f", + "1", + "2021-05-18 07:14:07.941913", + "NULL", + "2021-05-18 07:14:19.19469", + "f" + ], + [ + "b8fbfb81-3a13-4cc8-a4b4-1e97fade667a", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 4, \"name\": \"dasds\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"e098ccedce27b446\", \"trace_id\": \"2d1eff74089d2ad5\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "f", + "1", + "2021-05-18 07:14:07.778957", + "NULL", + "2021-05-18 07:14:19.17979", + "f" + ], + [ + "474d035b-8163-42c0-a240-9b9031452206", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 3, \"name\": \"dasds\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"e5d2c45c9436a01f\", \"trace_id\": \"5ebb62f875d02dd3\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "f", + "1", + "2021-05-18 07:14:07.632082", + "NULL", + "2021-05-18 07:14:19.192695", + "f" + ], + [ + "4671fb2b-1bdc-4615-9a0f-d384ef82e73a", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 2, \"name\": \"dasds\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"ba9c5129d081a540\", \"trace_id\": \"5ab0b030acf37a3f\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "f", + "1", + "2021-05-18 07:14:07.366513", + "NULL", + "2021-05-18 07:14:19.180674", + "f" + ], + [ + "a9fe39f6-3d9e-49c9-941c-09b84274dc87", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 1, \"name\": \"dasds\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"d4939311aad3a0bc\", \"trace_id\": \"65c31bf94eb7f656\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "f", + "1", + "2021-05-18 07:14:06.784375", + "NULL", + "2021-05-18 07:14:19.196511", + "f" + ] +] \ No newline at end of file diff --git a/console/src/components/Services/Events/__tests__/fixtures/invocations.json b/console/src/components/Services/Events/__tests__/fixtures/invocations.json new file mode 100644 index 00000000000..dd5af7cdef3 --- /dev/null +++ b/console/src/components/Services/Events/__tests__/fixtures/invocations.json @@ -0,0 +1,222 @@ +[ + [ + "id", + "event_id", + "status", + "request", + "response", + "created_at", + "id", + "schema_name", + "table_name", + "trigger_name", + "payload", + "delivered", + "error", + "tries", + "created_at", + "locked", + "next_retry_at", + "archived" + ], + [ + "31b4c28c-954d-4871-ba95-a6d7da8d6988", + "7bc7b398-f1cd-4761-839d-44971e01be48", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":8}},\"trace_context\":{\"trace_id\":\"04415c5c0870f8f6\",\"span_id\":\"455d47a2c5d8f40e\"}},\"created_at\":\"2021-05-18T07:39:50.658771Z\",\"id\":\"7bc7b398-f1cd-4761-839d-44971e01be48\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":4},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"04415c5c0870f8f6\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"d1260fcdfe50945e\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"de05cf247e935b7a\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:32.81592", + "7bc7b398-f1cd-4761-839d-44971e01be48", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 8, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"455d47a2c5d8f40e\", \"trace_id\": \"04415c5c0870f8f6\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.658771", + "NULL", + "NULL", + "f" + ], + [ + "bf1760ee-c628-4b94-b535-1d5453675958", + "c3ac48be-a569-4d87-8c52-cb84309002ed", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":6}},\"trace_context\":{\"trace_id\":\"ecba73bac1b4601a\",\"span_id\":\"5a75ae38fccf4473\"}},\"created_at\":\"2021-05-18T07:39:50.332379Z\",\"id\":\"c3ac48be-a569-4d87-8c52-cb84309002ed\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":4},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"ecba73bac1b4601a\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"1c3c460b36da4a0e\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"f309dbf4632da6a5\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:32.815484", + "c3ac48be-a569-4d87-8c52-cb84309002ed", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 6, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"5a75ae38fccf4473\", \"trace_id\": \"ecba73bac1b4601a\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.332379", + "NULL", + "NULL", + "f" + ], + [ + "5836823f-9104-489e-b339-946b45e266a9", + "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":9}},\"trace_context\":{\"trace_id\":\"ea970ad818f358cf\",\"span_id\":\"77150de9d725e5df\"}},\"created_at\":\"2021-05-18T07:39:50.831182Z\",\"id\":\"338eec2d-0c1f-4358-ae12-05d3f73a85c6\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":4},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"ea970ad818f358cf\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"332c2f49df1cb4d2\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"3668323420f67bb1\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:32.81517", + "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 9, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"77150de9d725e5df\", \"trace_id\": \"ea970ad818f358cf\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.831182", + "NULL", + "NULL", + "f" + ], + [ + "7b314fa3-fa10-4d1d-9c7b-0799e2a2345c", + "423e5a24-d4e0-493a-83df-ecff0eca2398", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":7}},\"trace_context\":{\"trace_id\":\"da0635bf4fb444b1\",\"span_id\":\"5e088982a14f9bdd\"}},\"created_at\":\"2021-05-18T07:39:50.490999Z\",\"id\":\"423e5a24-d4e0-493a-83df-ecff0eca2398\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":4},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"da0635bf4fb444b1\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"f92c4fac3a66595a\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"b3a34f8a72e89980\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:32.815118", + "423e5a24-d4e0-493a-83df-ecff0eca2398", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 7, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"5e088982a14f9bdd\", \"trace_id\": \"da0635bf4fb444b1\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.490999", + "NULL", + "NULL", + "f" + ], + [ + "c6ec4304-3848-4c4c-a188-ff91ebe61ea0", + "7bc7b398-f1cd-4761-839d-44971e01be48", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":8}},\"trace_context\":{\"trace_id\":\"04415c5c0870f8f6\",\"span_id\":\"455d47a2c5d8f40e\"}},\"created_at\":\"2021-05-18T07:39:50.658771Z\",\"id\":\"7bc7b398-f1cd-4761-839d-44971e01be48\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":3},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"04415c5c0870f8f6\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"f520ea1624695587\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"2dc1b4d86426e316\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:22.736277", + "7bc7b398-f1cd-4761-839d-44971e01be48", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 8, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"455d47a2c5d8f40e\", \"trace_id\": \"04415c5c0870f8f6\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.658771", + "NULL", + "NULL", + "f" + ], + [ + "8c88c745-29eb-4637-ad2d-85f3d6ba82c4", + "423e5a24-d4e0-493a-83df-ecff0eca2398", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":7}},\"trace_context\":{\"trace_id\":\"da0635bf4fb444b1\",\"span_id\":\"5e088982a14f9bdd\"}},\"created_at\":\"2021-05-18T07:39:50.490999Z\",\"id\":\"423e5a24-d4e0-493a-83df-ecff0eca2398\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":3},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"da0635bf4fb444b1\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"d6bdb95ec116b8ff\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"01b61664322a458b\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:22.736095", + "423e5a24-d4e0-493a-83df-ecff0eca2398", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 7, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"5e088982a14f9bdd\", \"trace_id\": \"da0635bf4fb444b1\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.490999", + "NULL", + "NULL", + "f" + ], + [ + "48532d4d-ee73-4245-a8f6-378b034eb4f0", + "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":9}},\"trace_context\":{\"trace_id\":\"ea970ad818f358cf\",\"span_id\":\"77150de9d725e5df\"}},\"created_at\":\"2021-05-18T07:39:50.831182Z\",\"id\":\"338eec2d-0c1f-4358-ae12-05d3f73a85c6\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":3},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"ea970ad818f358cf\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"4d8d92209b40eab3\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"876f35924d13168e\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:22.736039", + "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 9, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"77150de9d725e5df\", \"trace_id\": \"ea970ad818f358cf\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.831182", + "NULL", + "NULL", + "f" + ], + [ + "33105396-99dc-446c-ac7f-d93c38ceb686", + "c3ac48be-a569-4d87-8c52-cb84309002ed", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":6}},\"trace_context\":{\"trace_id\":\"ecba73bac1b4601a\",\"span_id\":\"5a75ae38fccf4473\"}},\"created_at\":\"2021-05-18T07:39:50.332379Z\",\"id\":\"c3ac48be-a569-4d87-8c52-cb84309002ed\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":3},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"ecba73bac1b4601a\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"4fa95afd2b803b9c\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"de923514252481ca\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:22.735757", + "c3ac48be-a569-4d87-8c52-cb84309002ed", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 6, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"5a75ae38fccf4473\", \"trace_id\": \"ecba73bac1b4601a\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.332379", + "NULL", + "NULL", + "f" + ], + [ + "f7980cf5-7520-489a-87f1-f658773f9e60", + "423e5a24-d4e0-493a-83df-ecff0eca2398", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":7}},\"trace_context\":{\"trace_id\":\"da0635bf4fb444b1\",\"span_id\":\"5e088982a14f9bdd\"}},\"created_at\":\"2021-05-18T07:39:50.490999Z\",\"id\":\"423e5a24-d4e0-493a-83df-ecff0eca2398\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":2},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"da0635bf4fb444b1\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"2fbf0361df48ccc7\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"ebc5dd9ef22f9543\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:11.704173", + "423e5a24-d4e0-493a-83df-ecff0eca2398", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 7, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"5e088982a14f9bdd\", \"trace_id\": \"da0635bf4fb444b1\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.490999", + "NULL", + "NULL", + "f" + ], + [ + "18e6a7de-c38d-4f56-90f5-d0cc1298ea97", + "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "1000", + "{\"payload\":{\"event\":{\"session_variables\":{\"x-hasura-role\":\"admin\"},\"op\":\"INSERT\",\"data\":{\"old\":null,\"new\":{\"name\":\"safs\",\"id\":9}},\"trace_context\":{\"trace_id\":\"ea970ad818f358cf\",\"span_id\":\"77150de9d725e5df\"}},\"created_at\":\"2021-05-18T07:39:50.831182Z\",\"id\":\"338eec2d-0c1f-4358-ae12-05d3f73a85c6\",\"delivery_info\":{\"max_retries\":4,\"current_retry\":2},\"trigger\":{\"name\":\"new_user\"},\"table\":{\"schema\":\"public\",\"name\":\"users\"}},\"headers\":[{\"value\":\"application/json\",\"name\":\"Content-Type\"},{\"value\":\"hasura-graphql-engine/v2.0.0-alpha.9\",\"name\":\"User-Agent\"}],\"version\":\"2\"}", + "{\"data\":{\"message\":\"\\\"HttpExceptionRequest Request {\\\\n host = \\\\\\\"httsssp.org\\\\\\\"\\\\n port = 80\\\\n secure = False\\\\n requestHeaders = [(\\\\\\\"X-B3-TraceId\\\\\\\",\\\\\\\"ea970ad818f358cf\\\\\\\"),(\\\\\\\"X-B3-SpanId\\\\\\\",\\\\\\\"18ac4aa73874b52d\\\\\\\"),(\\\\\\\"X-B3-ParentSpanId\\\\\\\",\\\\\\\"705e55f29e621be4\\\\\\\"),(\\\\\\\"Content-Type\\\\\\\",\\\\\\\"application/json\\\\\\\"),(\\\\\\\"User-Agent\\\\\\\",\\\\\\\"hasura-graphql-engine/v2.0.0-alpha.9\\\\\\\")]\\\\n path = \\\\\\\"/post\\\\\\\"\\\\n queryString = \\\\\\\"\\\\\\\"\\\\n method = \\\\\\\"POST\\\\\\\"\\\\n proxy = Nothing\\\\n rawBody = False\\\\n redirectCount = 10\\\\n responseTimeout = ResponseTimeoutMicro 60000000\\\\n requestVersion = HTTP/1.1\\\\n proxySecureMode = ProxySecureWithConnect\\\\n}\\\\n (ConnectionFailure Network.Socket.getAddrInfo (called with preferred socket type/protocol: AddrInfo {addrFlags = [], addrFamily = AF_UNSPEC, addrSocketType = Stream, addrProtocol = 0, addrAddress = 0.0.0.0:0, addrCanonName = Nothing}, host name: Just \\\\\\\"httsssp.org\\\\\\\", service name: Just \\\\\\\"80\\\\\\\"): does not exist (Name or service not known))\\\"\"},\"version\":\"2\",\"type\":\"client_error\"}", + "2021-05-18 07:40:11.704093", + "338eec2d-0c1f-4358-ae12-05d3f73a85c6", + "public", + "users", + "new_user", + "{\"op\": \"INSERT\", \"data\": {\"new\": {\"id\": 9, \"name\": \"safs\"}, \"old\": null}, \"trace_context\": {\"span_id\": \"77150de9d725e5df\", \"trace_id\": \"ea970ad818f358cf\"}, \"session_variables\": {\"x-hasura-role\": \"admin\"}}", + "f", + "t", + "5", + "2021-05-18 07:39:50.831182", + "NULL", + "NULL", + "f" + ] +] \ No newline at end of file diff --git a/console/src/components/Services/Events/__tests__/utils.test.ts b/console/src/components/Services/Events/__tests__/utils.test.ts new file mode 100644 index 00000000000..a0cf197d37f --- /dev/null +++ b/console/src/components/Services/Events/__tests__/utils.test.ts @@ -0,0 +1,26 @@ +import { parseEventsSQLResp } from '../utils'; +import events from './fixtures/events.json'; +import invocations from './fixtures/invocations.json'; + +describe('Events_Utils.ts', () => { + describe('parseEventsSQLResp', () => { + it('should parse events', () => { + const parsedEvents = parseEventsSQLResp(events); + expect(parsedEvents.length).toBe(5); + expect(parsedEvents?.[0]?.error).toBe(false); + expect(parsedEvents?.[0]?.archived).toBe(false); + expect(parsedEvents?.[0]?.delivered).toBe(false); + expect(parsedEvents).toMatchSnapshot(); + }); + + it('should parse event invocations', () => { + const parsedInvocations = parseEventsSQLResp(invocations); + expect(parsedInvocations?.[0]?.error).toBe(true); + expect(parsedInvocations?.[0]?.archived).toBe(false); + expect(parsedInvocations?.[0]?.delivered).toBe(false); + expect(typeof parsedInvocations?.[0]?.request).toBe('object'); + expect(parsedInvocations.length).toBe(10); + expect(parsedInvocations).toMatchSnapshot(); + }); + }); +}); diff --git a/console/src/components/Services/Events/utils.ts b/console/src/components/Services/Events/utils.ts index 7de619b5da1..c565f97bf93 100644 --- a/console/src/components/Services/Events/utils.ts +++ b/console/src/components/Services/Events/utils.ts @@ -95,3 +95,33 @@ export const getLogsTableDef = (kind: EventKind): QualifiedTable => { } return generateTableDef(tableName, 'hdb_catalog'); }; + +const sanitiseValue = (value?: string | number) => { + if (value === 'f') return false; + if (value === 't') return true; + return value; +}; + +export const parseEventsSQLResp = ( + result: string[][] = [] +): Record[] => { + const allKeys: string[] = result?.[0]; + const resultsData: string[][] = result?.slice(1); + const formattedData: Record[] = []; + resultsData.forEach((values: string[]) => { + const dataObj: Record = {}; + allKeys.forEach((key: string, idx: number) => { + if (!dataObj[key]) { + if (key === 'request' || key === 'response') { + try { + dataObj[key] = JSON.parse(values[idx]); + } catch { + dataObj[key] = values[idx]; + } + } else dataObj[key] = sanitiseValue(values[idx]); + } + }); + formattedData.push(dataObj); + }); + return formattedData; +}; diff --git a/console/src/metadata/__tests__/__snapshots__/metadataTableUtils.test.ts.snap b/console/src/metadata/__tests__/__snapshots__/metadataTableUtils.test.ts.snap new file mode 100644 index 00000000000..d1d8c6987ff --- /dev/null +++ b/console/src/metadata/__tests__/__snapshots__/metadataTableUtils.test.ts.snap @@ -0,0 +1,111 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MetadatTable_Utils_getDataTriggerInvocations() should generate SQL to fetch invocations for an event 1`] = ` +Object { + "args": Object { + "cascade": false, + "read_only": false, + "source": "db2", + "sql": "SELECT + * + FROM + \\"hdb_catalog\\".\\"event_invocation_logs\\" + WHERE + event_id = '298f6a71-f503-46f1-814c-45daef0afe4d' + ORDER BY + created_at DESC NULLS LAST;", + }, + "type": "run_sql", +} +`; + +exports[`MetadatTable_Utils_getDataTriggerLogsCountQuery() should generate SQL query for invocation event count 1`] = ` +Object { + "args": Object { + "cascade": false, + "read_only": false, + "source": "default", + "sql": "SELECT + COUNT(*) + FROM \\"hdb_catalog\\".\\"event_invocation_logs\\" original_table JOIN \\"hdb_catalog\\".\\"event_log\\" data_table + ON original_table.event_id = data_table.id + WHERE data_table.trigger_name = 'test_event';", + }, + "type": "run_sql", +} +`; + +exports[`MetadatTable_Utils_getDataTriggerLogsCountQuery() should generate SQL query for pending event count 1`] = ` +Object { + "args": Object { + "cascade": false, + "read_only": false, + "source": "default", + "sql": "SELECT + COUNT(*) + FROM \\"hdb_catalog\\".\\"event_log\\" data_table + WHERE data_table.trigger_name = 'new_user' AND delivered=false AND error=false AND archived=false;", + }, + "type": "run_sql", +} +`; + +exports[`MetadatTable_Utils_getDataTriggerLogsCountQuery() should generate SQL query for processed event count 1`] = ` +Object { + "args": Object { + "cascade": false, + "read_only": false, + "source": "db2", + "sql": "SELECT + COUNT(*) + FROM \\"hdb_catalog\\".\\"event_log\\" data_table + WHERE data_table.trigger_name = 'new_user' AND (delivered=true OR error=true) AND archived=false;", + }, + "type": "run_sql", +} +`; + +exports[`MetadatTable_Utils_getDataTriggerLogsQuery() should generate SQL query for event invocation logs 1`] = ` +Object { + "args": Object { + "cascade": false, + "read_only": false, + "source": "db2", + "sql": "SELECT * + FROM \\"hdb_catalog\\".\\"event_log\\" data_table + WHERE data_table.trigger_name = 'test_event' + AND (delivered=true OR error=true) AND archived=false ORDER BY created_at DESC LIMIT 100 OFFSET 0;", + }, + "type": "run_sql", +} +`; + +exports[`MetadatTable_Utils_getDataTriggerLogsQuery() should generate SQL query for pending event logs 1`] = ` +Object { + "args": Object { + "cascade": false, + "read_only": false, + "source": "default", + "sql": "SELECT * + FROM \\"hdb_catalog\\".\\"event_log\\" data_table + WHERE data_table.trigger_name = 'new_user' + AND delivered=false AND error=false AND archived=false ORDER BY created_at DESC LIMIT 10 OFFSET 10;", + }, + "type": "run_sql", +} +`; + +exports[`MetadatTable_Utils_getDataTriggerLogsQuery() should generate SQL query for processed event logs 1`] = ` +Object { + "args": Object { + "cascade": false, + "read_only": false, + "source": "db2", + "sql": "SELECT * + FROM \\"hdb_catalog\\".\\"event_log\\" data_table + WHERE data_table.trigger_name = 'test_event' + AND (delivered=true OR error=true) AND archived=false ORDER BY created_at DESC LIMIT 100 OFFSET 0;", + }, + "type": "run_sql", +} +`; diff --git a/console/src/metadata/__tests__/metadataTableUtils.test.ts b/console/src/metadata/__tests__/metadataTableUtils.test.ts new file mode 100644 index 00000000000..736f4a6b7a4 --- /dev/null +++ b/console/src/metadata/__tests__/metadataTableUtils.test.ts @@ -0,0 +1,176 @@ +import { + getDataTriggerLogsCountQuery, + getDataTriggerLogsQuery, + getDataTriggerInvocations, +} from '../metadataTableUtils'; + +describe('MetadatTable_Utils_getDataTriggerLogsCountQuery()', () => { + it('should generate SQL query for pending event count ', () => { + const pendingCountQuery = getDataTriggerLogsCountQuery( + 'new_user', + 'pending', + 'default' + ); + expect(pendingCountQuery?.args?.sql).toBeTruthy(); + expect(pendingCountQuery?.args?.source).toEqual('default'); + expect(pendingCountQuery?.args?.sql).toContain( + 'delivered=false AND error=false AND archived=false' + ); + expect(pendingCountQuery?.args?.sql).toContain( + "data_table.trigger_name = 'new_user'" + ); + expect(pendingCountQuery?.args?.sql).toContain( + 'FROM "hdb_catalog"."event_log"' + ); + expect(pendingCountQuery).toMatchSnapshot(); + }); + + it('should generate SQL query for processed event count', () => { + const processedCountQuery = getDataTriggerLogsCountQuery( + 'new_user', + 'processed', + 'db2' + ); + expect(processedCountQuery?.args?.sql).toBeTruthy(); + expect(processedCountQuery?.args?.sql).toContain( + 'AND (delivered=true OR error=true) AND archived=false' + ); + expect(processedCountQuery?.args?.source).toEqual('db2'); + + expect(processedCountQuery?.args?.sql).toContain( + "data_table.trigger_name = 'new_user'" + ); + expect(processedCountQuery?.args?.sql).toContain( + 'FROM "hdb_catalog"."event_log"' + ); + + expect(processedCountQuery).toMatchSnapshot(); + }); + + it('should generate SQL query for invocation event count', () => { + const invocationCountQuery = getDataTriggerLogsCountQuery( + 'test_event', + 'invocation', + 'default' + ); + expect(invocationCountQuery?.args?.sql).toBeTruthy(); + expect(invocationCountQuery?.args?.sql).toContain( + "data_table.trigger_name = 'test_event'" + ); + expect(invocationCountQuery?.args?.source).toEqual('default'); + + expect(invocationCountQuery?.args?.sql).toContain( + 'FROM "hdb_catalog"."event_invocation_logs"' + ); + expect(invocationCountQuery).toMatchSnapshot(); + }); +}); +describe('MetadatTable_Utils_getDataTriggerLogsQuery()', () => { + it('should generate SQL query for pending event logs', () => { + // pending + const pendingLogsQuery = getDataTriggerLogsQuery( + 'pending', + 'default', + 'new_user', + 10, + 10 + ); + expect(pendingLogsQuery?.args?.sql).toBeTruthy(); + expect(pendingLogsQuery?.args?.sql).toContain( + 'delivered=false AND error=false AND archived=false' + ); + expect(pendingLogsQuery?.args?.source).toEqual('default'); + + expect(pendingLogsQuery?.args?.sql).toContain( + "data_table.trigger_name = 'new_user'" + ); + expect(pendingLogsQuery?.args?.sql).toContain( + 'FROM "hdb_catalog"."event_log"' + ); + expect(pendingLogsQuery?.args?.sql).toContain('LIMIT 10'); + expect(pendingLogsQuery?.args?.sql).toContain('OFFSET 10'); + expect(pendingLogsQuery).toMatchSnapshot(); + }); + it('should generate SQL query for processed event logs', () => { + // Processed + const processedLogsQuery = getDataTriggerLogsQuery( + 'processed', + 'db2', + 'test_event', + 100, + 0 + ); + expect(processedLogsQuery?.args?.sql).toBeTruthy(); + expect(processedLogsQuery?.args?.source).toEqual('db2'); + + expect(processedLogsQuery?.args?.sql).toContain( + 'AND (delivered=true OR error=true) AND archived=false' + ); + expect(processedLogsQuery?.args?.sql).toContain( + "data_table.trigger_name = 'test_event'" + ); + expect(processedLogsQuery?.args?.sql).toContain( + 'FROM "hdb_catalog"."event_log"' + ); + expect(processedLogsQuery?.args?.sql).toContain('LIMIT 100'); + expect(processedLogsQuery?.args?.sql).toContain('OFFSET 0'); + expect(processedLogsQuery).toMatchSnapshot(); + }); + it('should generate SQL query for event invocation logs', () => { + // Invocation + const invocationLogsQuery = getDataTriggerLogsQuery( + 'processed', + 'db2', + 'test_event', + 100, + 0 + ); + expect(invocationLogsQuery?.args?.sql).toBeTruthy(); + expect(invocationLogsQuery?.args?.source).toEqual('db2'); + + expect(invocationLogsQuery?.args?.sql).toContain( + 'AND (delivered=true OR error=true) AND archived=false' + ); + expect(invocationLogsQuery?.args?.sql).toContain( + "data_table.trigger_name = 'test_event'" + ); + expect(invocationLogsQuery?.args?.sql).toContain( + 'FROM "hdb_catalog"."event_log"' + ); + expect(invocationLogsQuery?.args?.sql).toContain('LIMIT 100'); + expect(invocationLogsQuery?.args?.sql).toContain('OFFSET 0'); + expect(invocationLogsQuery).toMatchSnapshot(); + }); +}); +describe('MetadatTable_Utils_getDataTriggerInvocations()', () => { + it('should generate SQL to fetch invocations for an event', () => { + // pending + const pendingLogsQuery = getDataTriggerInvocations( + '298f6a71-f503-46f1-814c-45daef0afe4d', + 'db2' + ); + expect(pendingLogsQuery?.args?.sql).toBeTruthy(); + expect(pendingLogsQuery?.args?.sql).toContain( + "event_id = '298f6a71-f503-46f1-814c-45daef0afe4d'" + ); + expect(pendingLogsQuery?.args?.source).toEqual('db2'); + + expect(pendingLogsQuery?.args?.sql).toContain('created_at DESC NULLS LAST'); + expect(pendingLogsQuery?.args?.sql).toContain( + `FROM + "hdb_catalog"."event_invocation_logs"` + ); + expect(pendingLogsQuery).toMatchSnapshot(); + }); + it('should generate SQL to fetch invocations for an event with default source', () => { + // pending + const pendingLogsQuery = getDataTriggerInvocations( + '298f6a71-f503-46f1-814c-45daef0afe4d' + ); + expect(pendingLogsQuery?.args?.sql).toBeTruthy(); + expect(pendingLogsQuery?.args?.sql).toContain( + "event_id = '298f6a71-f503-46f1-814c-45daef0afe4d'" + ); + expect(pendingLogsQuery?.args?.source).toEqual('default'); + }); +}); diff --git a/console/src/metadata/metadataTableUtils.ts b/console/src/metadata/metadataTableUtils.ts index e58706314cb..912795ecdb8 100644 --- a/console/src/metadata/metadataTableUtils.ts +++ b/console/src/metadata/metadataTableUtils.ts @@ -4,31 +4,83 @@ import { TriggerOperation } from '../components/Common/FilterQuery/state'; const eventRelTable = `"hdb_catalog"."event_log"`; const eventInvTable = `"hdb_catalog"."event_invocation_logs"`; +const triggerTypes = { + pending: 'pending', + processed: 'processed', + invocation: 'invocation', +}; + +export interface RunSQLQueryType { + type: string; + args: { + source: string; + sql: string; + cascade: boolean; + read_only: boolean; + }; +} + +export const getDataTriggerLogsCountQuery = ( + triggerName: string, + triggerOp: TriggerOperation, + currentSource?: string +): RunSQLQueryType => { + let qry = `SELECT + COUNT(*) + FROM ${eventRelTable} data_table + WHERE data_table.trigger_name = '${triggerName}' `; + + switch (triggerOp) { + case triggerTypes.pending: + qry += `AND delivered=false AND error=false AND archived=false;`; + break; + + case triggerTypes.processed: + qry += `AND (delivered=true OR error=true) AND archived=false;`; + break; + case triggerTypes.invocation: + qry = `SELECT + COUNT(*) + FROM ${eventInvTable} original_table JOIN ${eventRelTable} data_table + ON original_table.event_id = data_table.id + WHERE data_table.trigger_name = '${triggerName}' `; + break; + default: + break; + } + return getRunSqlQuery(qry, currentSource ?? 'default'); +}; export const getDataTriggerLogsQuery = ( triggerOp: TriggerOperation, currentSource: string, triggerName: string, limit?: number, offset?: number -) => { +): RunSQLQueryType => { let sql = ''; - if (triggerOp === 'pending') { - sql = `SELECT original_table.*, data_table.* - FROM ${eventInvTable} original_table JOIN ${eventRelTable} data_table - ON original_table.event_id = data_table.id - WHERE data_table.trigger_name = '${triggerName}' AND - data_table.delivered = FALSE - ORDER BY original_table.created_at DESC NULLS LAST`; - } + switch (triggerOp) { + case triggerTypes.pending: + sql = `SELECT * + FROM ${eventRelTable} data_table + WHERE data_table.trigger_name = '${triggerName}' + AND delivered=false AND error=false AND archived=false ORDER BY created_at DESC `; + break; - if (triggerOp === 'invocation' || triggerOp === 'processed') { - // fixme: unsure of this, to check again. - sql = `SELECT original_table.*, data_table.* - FROM ${eventInvTable} original_table JOIN ${eventRelTable} data_table - ON original_table.event_id = data_table.id - WHERE data_table.trigger_name = '${triggerName}' - ORDER BY original_table.created_at DESC NULLS LAST`; + case triggerTypes.processed: + sql = `SELECT * + FROM ${eventRelTable} data_table + WHERE data_table.trigger_name = '${triggerName}' + AND (delivered=true OR error=true) AND archived=false ORDER BY created_at DESC `; + break; + case triggerTypes.invocation: + sql = `SELECT original_table.*, data_table.* + FROM ${eventInvTable} original_table JOIN ${eventRelTable} data_table ON original_table.event_id = data_table.id + WHERE data_table.trigger_name = '${triggerName}' + ORDER BY original_table.created_at DESC NULLS LAST`; + break; + default: + break; } if (limit) { @@ -45,3 +97,18 @@ export const getDataTriggerLogsQuery = ( return getRunSqlQuery(sql, currentSource); }; +export const getDataTriggerInvocations = ( + eventId: string, + currentSource = 'default' +): RunSQLQueryType => { + const sql = `SELECT + * + FROM + ${eventInvTable} + WHERE + event_id = '${eventId}' + ORDER BY + created_at DESC NULLS LAST;`; + + return getRunSqlQuery(sql, currentSource); +}; diff --git a/console/src/metadata/queryUtils.ts b/console/src/metadata/queryUtils.ts index be6fb99710f..fbf9e2439e7 100644 --- a/console/src/metadata/queryUtils.ts +++ b/console/src/metadata/queryUtils.ts @@ -688,7 +688,7 @@ export const getConsoleStateQuery = { args: {}, }; -export type SupportedEvents = 'cron' | 'one_off'; +export type SupportedEvents = 'cron' | 'one_off' | 'data'; export const getEventInvocationsLogByID = ( type: SupportedEvents,