From a133a111d2d8c6844d318f782dee6a258b5d418c Mon Sep 17 00:00:00 2001 From: Lakshan Perera Date: Fri, 31 May 2024 05:26:32 +1000 Subject: [PATCH] Some updates to Edge Functions guides (#26877) * chore: link to Sentry guide from Debugging section * chore: Change Edge Function Quickstart to Get started This section isn't much of a quickstart. Updated the first guide title to "Create an Edge Function" * chore: moved Edge Functions limits to a separate page * chore: added a page on HTTP Status codes Edge Functions can return --- .../NavigationMenu.constants.ts | 22 ++++++++- .../content/guides/functions/debugging.mdx | 14 +----- apps/docs/content/guides/functions/limits.mdx | 23 ++++++++++ .../content/guides/functions/status-codes.mdx | 46 +++++++++++++++++++ .../guides/platform/http-status-codes.mdx | 4 ++ 5 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 apps/docs/content/guides/functions/limits.mdx create mode 100644 apps/docs/content/guides/functions/status-codes.mdx diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts index 072c95699b6..8146b7d252c 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts @@ -1081,11 +1081,11 @@ export const functions: NavMenuConstant = { url: '/guides/functions', }, { - name: 'Quickstart', + name: 'Getting started', url: undefined, items: [ { - name: 'Getting started', + name: 'Create an Edge Function', url: '/guides/functions/quickstart', }, { @@ -1153,6 +1153,24 @@ export const functions: NavMenuConstant = { name: 'Testing your Edge Functions', url: '/guides/functions/unit-test', }, + { + name: 'Monitoring with Sentry', + url: '/guides/functions/examples/sentry-monitoring', + }, + ], + }, + { + name: 'Platform', + url: undefined, + items: [ + { + name: 'Status codes', + url: '/guides/functions/status-codes', + }, + { + name: 'Limits', + url: '/guides/functions/limits', + }, ], }, { diff --git a/apps/docs/content/guides/functions/debugging.mdx b/apps/docs/content/guides/functions/debugging.mdx index dd609593279..ab889a578ff 100644 --- a/apps/docs/content/guides/functions/debugging.mdx +++ b/apps/docs/content/guides/functions/debugging.mdx @@ -141,10 +141,7 @@ To find the bundle size of a function, run the following command locally: Look for the "size" field in the output which represents the approximate bundle size of the function. You can find the accurate bundle size when you deploy your function via Supabase CLI. If the function is part of a larger application, consider examining the bundle size of the specific function independently. -The source code of a function is subject to size limits: - -- **Free Plan**: Maximum size of 2MB. -- **Pro Plan**: Maximum size of 10MB. +The source code of a function is subject to 10MB site limit. ### Analyze dependencies @@ -171,12 +168,3 @@ For example, if you only need the `Sheets` submodule from the `googleapis` packa ```typescript import { Sheets } from 'npm:@googleapis/sheets' ``` - -## Limitations - -- Outgoing connections to ports `25` and `587` are not allowed. -- Serving of HTML content is not supported (`GET` requests that return `text/html` will be rewritten to `text/plain`). -- Deno and Node file system APIs are not available. -- Memory limit for the function: 256MB -- Wall clock limit: 400 s -- CPU Time: 2 s diff --git a/apps/docs/content/guides/functions/limits.mdx b/apps/docs/content/guides/functions/limits.mdx new file mode 100644 index 00000000000..759e5531ef8 --- /dev/null +++ b/apps/docs/content/guides/functions/limits.mdx @@ -0,0 +1,23 @@ +--- +id: 'functions-limits' +title: 'Limits' +description: "Limits applied Edge Functions in Supabase's hosted platform." +subtitle: "Limits applied Edge Functions in Supabase's hosted platform." +--- + +## Runtime limits + +- Maximum Memory: 256MB +- Maximum Duration (Wall clock limit): 400s (this is the duration an Edge Function worker will stay active. During this period, a worker can serve multiple requests) +- Maximum CPU Time: 2s +- Request idle timeout: 150s (if an Edge Function doesn't send a response before the timeout, 504 Gateway Timeout will be returned) +- Maximum Function Size (after bundling via CLI): 10MB +- Maximum log message length: 10,000 characters +- Log event threshold: 100 events per 10 seconds + +## Other limits & restrictions + +- Outgoing connections to ports `25` and `587` are not allowed. +- Serving of HTML content is not supported (`GET` requests that return `text/html` will be rewritten to `text/plain`). +- Deno and Node file system APIs are not available. +- Web Worker API (or Node `vm` API) are not available. diff --git a/apps/docs/content/guides/functions/status-codes.mdx b/apps/docs/content/guides/functions/status-codes.mdx new file mode 100644 index 00000000000..fe8f32ebf73 --- /dev/null +++ b/apps/docs/content/guides/functions/status-codes.mdx @@ -0,0 +1,46 @@ +--- +id: 'functions-status-codes' +title: 'Status codes' +description: 'Edge Functions can return following status codes.' +subtitle: 'Edge Functions can return following status codes.' +--- + +## 2XX Success + +A successful Edge Function Response + +## 3XX Redirect + +The Edge Function has responded with a `Response.redirect` (API docs)[https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static] + +## 4XX Client Errors + +### 401 Unauthorized + +If the Function has `Verify JWT` option enabled, but the request was made with an invalid JWT. + +### 404 Not Found + +Requested function was not found. + +### 405 Method Not Allowed + +Edge Functions only support these HTTP methods 'POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS' + +## 5XX Server Errors + +### 500 Internal Server Error + +When an Edge Function throws an uncaught exception (`WORKER_ERROR`). Check Edge Function logs to find the cause. + +### 503 Service Unavailable + +Function failed to start (`BOOT_ERROR`). Check Edge Function logs to find the cause. + +### 504 Gateway Timeout + +Function doesn't respond before the [request idle timeout](/guides/functions/limits). + +### 546 Resource Limit (Custom Error Code) + +Function execution was stopped due to a resource limit (`WORKER_LIMIT`). Edge Function logs should provide which [resource limit](/guides/functions/limits) was exceeded. diff --git a/apps/docs/content/guides/platform/http-status-codes.mdx b/apps/docs/content/guides/platform/http-status-codes.mdx index db0d650e33f..fb560070b7c 100644 --- a/apps/docs/content/guides/platform/http-status-codes.mdx +++ b/apps/docs/content/guides/platform/http-status-codes.mdx @@ -39,3 +39,7 @@ Free-plan projects may be paused due to inactivity, on request by the owner, or The request is not completed within the configured time limit. The timeout limit is set to prevent long-running queries which can cause performance issues, increase latency, and potentially even crash the project. + +#### 546 Edge Functions Resource Limit + +Applies only to Edge Functions. Function execution was stopped due to a resource limit (`WORKER_LIMIT`). Edge Function logs should provide which [resource limit](/guides/functions/limits) was exceeded.