Skip to content

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

chore: observability dashboard entitlements (#43502)

Ignacio Dobronich60a2a5e0929f
diff --git a/apps/studio/components/interfaces/Reports/v2/ReportChartUpsell.tsx b/apps/studio/components/interfaces/Reports/v2/ReportChartUpsell.tsx
index 4077b6548c9..cf826f0a3c5 100644
--- a/apps/studio/components/interfaces/Reports/v2/ReportChartUpsell.tsx
+++ b/apps/studio/components/interfaces/Reports/v2/ReportChartUpsell.tsx
@@ -7,7 +7,7 @@ import { Button, Card, cn } from 'ui'
interface ReportsChartUpsellProps {
report: {
label: string
- availableIn: string[]
+ requiredPlan?: string
}
orgSlug: string
}
@@ -42,13 +42,9 @@ export const ReportChartUpsell = ({ report, orgSlug }: ReportsChartUpsellProps)
<div className="z-10 flex flex-col items-center justify-center space-y-2 h-full absolute top-0 left-0 w-full bg-surface-100/70 backdrop-blur-md">
<h2 className="text-sm">{report.label}</h2>
<p className="text-sm text-foreground-light">
- This chart is available from{' '}
- <span className="capitalize">
- {Array.isArray(report.availableIn) && report.availableIn.length > 0
- ? report.availableIn[0]
- : 'Pro'}
- </span>{' '}
- plan and above
+ {report.requiredPlan
+ ? `Available on the ${report.requiredPlan} Plan and above`
+ : `Your plan does not include access to ${report.label}`}
</p>
<Button
asChild
@@ -58,12 +54,7 @@ export const ReportChartUpsell = ({ report, orgSlug }: ReportsChartUpsellProps)
className="mt-4"
>
<Link href={`/org/${orgSlug || '_'}/billing?panel=subscriptionPlan&source=reports`}>
- Upgrade to{' '}
- <span className="capitalize">
- {Array.isArray(report.availableIn) && report.availableIn.length > 0
- ? report.availableIn[0]
- : 'Pro'}
- </span>
+ {report.requiredPlan ? `Upgrade to ${report.requiredPlan}` : 'Upgrade'}
</Link>
</Button>
</div>
diff --git a/apps/studio/components/interfaces/Reports/v2/ReportChartV2.tsx b/apps/studio/components/interfaces/Reports/v2/ReportChartV2.tsx
index 39633d13047..36f7324977b 100644
--- a/apps/studio/components/interfaces/Reports/v2/ReportChartV2.tsx
+++ b/apps/studio/components/interfaces/Reports/v2/ReportChartV2.tsx
@@ -6,7 +6,7 @@ import { useChartHighlight } from 'components/ui/Charts/useChartHighlight'
import type { AnalyticsInterval } from 'data/analytics/constants'
import type { ReportConfig } from 'data/reports/v2/reports.types'
import { useFillTimeseriesSorted } from 'hooks/analytics/useFillTimeseriesSorted'
-import { useCurrentOrgPlan } from 'hooks/misc/useCurrentOrgPlan'
+import { useCheckEntitlements } from 'hooks/misc/useCheckEntitlements'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { Loader2 } from 'lucide-react'
import { useState } from 'react'
@@ -74,12 +74,16 @@ export const ReportChartV2 = ({
queryGroup,
}: ReportChartV2Props) => {
const { data: org } = useSelectedOrganizationQuery()
- const { plan: orgPlan } = useCurrentOrgPlan()
- const orgPlanId = orgPlan?.id
+ const { getEntitlementSetValues, isLoading: isEntitlementLoading } = useCheckEntitlements(
+ 'observability.dashboard_advanced_metrics',
+ undefined,
+ { enabled: !!report.entitlement }
+ )
- const isAvailable = !report?.availableIn || (orgPlanId && report.availableIn?.includes(orgPlanId))
+ const entitledFeatures = getEntitlementSetValues()
+ const isAvailable = !report.entitlement || entitledFeatures.includes(report.entitlement)
- const canFetch = orgPlanId !== undefined && isAvailable
+ const canFetch = isAvailable
const {
data: queryResult,
@@ -129,7 +133,7 @@ export const ReportChartV2 = ({
const [chartStyle, setChartStyle] = useState<string>(report.defaultChartStyle)
const chartHighlight = useChartHighlight()
- if (!isAvailable) {
+ if (!isAvailable && !isEntitlementLoading) {
return <ReportChartUpsell report={report} orgSlug={org?.slug ?? ''} />
}
diff --git a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
index df848d2d32e..a533099da76 100644
--- a/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
+++ b/apps/studio/components/ui/Charts/ComposedChart.utils.tsx
@@ -14,7 +14,8 @@ export interface ReportAttributes {
attributes?: (MultiAttribute | false)[]
defaultChartStyle?: 'bar' | 'line' | 'stackedAreaLine'
hide?: boolean
- availableIn?: string[]
+ entitlement?: string
+ requiredPlan?: string
hideChartType?: boolean
format?: string
className?: string
diff --git a/apps/studio/data/reports/database-charts.ts b/apps/studio/data/reports/database-charts.ts
index 852be9ae43b..d37aea3a05b 100644
--- a/apps/studio/data/reports/database-charts.ts
+++ b/apps/studio/data/reports/database-charts.ts
@@ -2,29 +2,31 @@ import { compactNumberFormatter, numberFormatter } from 'components/ui/Charts/Ch
import { ReportAttributes } from 'components/ui/Charts/ComposedChart.utils'
import { DOCS_URL } from 'lib/constants'
import { formatBytes } from 'lib/helpers'
-import type { Organization } from 'types'
import { DiskAttributesData } from '../config/disk-attributes-query'
import { MaxConnectionsData } from '../database/max-connections-query'
import { Project } from '../projects/project-detail-query'
export const getReportAttributesV2: (
- org: Organization,
+ entitledFeatures: string[],
project: Project,
diskConfig?: DiskAttributesData,
maxConnections?: MaxConnectionsData,
- pgBouncerMaxConnections?: number
-) => ReportAttributes[] = (org, project, diskConfig, maxConnections, pgBouncerMaxConnections) => {
- const isFreePlan = org?.plan?.id === 'free'
- const isSpendCapEnabled =
- org?.plan.id !== 'free' && !org?.usage_billing_enabled && project?.cloud_provider !== 'FLY'
-
+ pgBouncerMaxConnections?: number,
+ isSpendCapEnabled?: boolean
+) => ReportAttributes[] = (
+ entitledFeatures,
+ project,
+ diskConfig,
+ maxConnections,
+ pgBouncerMaxConnections,
+ isSpendCapEnabled
+) => {
return [
{
id: 'ram-usage',
label: 'Memory usage',
docsUrl: `${DOCS_URL}/guides/telemetry/reports#memory-usage`,
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
hide: false,
showTooltip: true,
showLegend: true,
@@ -69,7 +71,6 @@ export const getReportAttributesV2: (
syncId: 'database-reports',
format: '%',
valuePrecision: 2,
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
hide: false,
showTooltip: true,
showLegend: true,
@@ -140,7 +141,6 @@ export const getReportAttributesV2: (
label: 'Disk Input/Output operations per second (IOPS)',
docsUrl: `${DOCS_URL}/guides/telemetry/reports#disk-inputoutput-operations-per-second-iops`,
syncId: 'database-reports',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
hide: false,
showTooltip: true,
valuePrecision: 0,
@@ -184,7 +184,8 @@ export const getReportAttributesV2: (
label: 'Disk throughput',
docsUrl: `${DOCS_URL}/guides/platform/compute-add-ons#disk-throughput`,
syncId: 'database-reports',
- availableIn: ['team', 'enterprise', 'platform'],
+ entitlement: 'disk_throughput',
+ requiredPlan: 'Team',
hide: false,
showTooltip: true,
format: 'bytes-per-second',
@@ -231,8 +232,7 @@ export const getReportAttributesV2: (
label: 'Database Connections',
syncId: 'database-reports',
valuePrecision: 0,
- availableIn: ['free'],
- hide: !isFreePlan,
+ hide: entitledFeatures.includes('database'),
showTooltip: false,
showLegend: false,
showMaxValue: true,
@@ -264,8 +264,9 @@ export const getReportAttributesV2: (
label: 'Database Connections',
syncId: 'database-reports',
valuePrecision: 0,
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
- hide: isFreePlan,
+ entitlement: 'database',
+ requiredPlan: 'Pro',
+ hide: !entitledFeatures.includes('database'),
showTooltip: true,
showLegend: true,
showMaxValue: true,
@@ -328,8 +329,9 @@ export const getReportAttributesV2: (
label: 'Dedicated Pooler Client Connections',
syncId: 'database-reports',
valuePrecision: 0,
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
- hide: isFreePlan,
+ entitlement: 'database',
+ requiredPlan: 'Pro',
+ hide: !entitledFeatures.includes('database'),
showTooltip: true,
showLegend: true,
showMaxValue: true,
@@ -360,8 +362,9 @@ export const getReportAttributesV2: (
label: 'Shared Pooler (Supavisor) client connections',
syncId: 'database-reports',
valuePrecision: 0,
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
- hide: isFreePlan,
+ entitlement: 'database',
+ requiredPlan: 'Pro',
+ hide: !entitledFeatures.includes('database'),
showTooltip: false,
showLegend: false,
showMaxValue: false,
@@ -383,7 +386,6 @@ export const getReportAttributesV2: (
label: 'Disk Usage',
syncId: 'database-reports',
valuePrecision: 2,
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
hide: false,
showTooltip: true,
showLegend: true,
@@ -427,7 +429,7 @@ export const getReportAttributesV2: (
label: 'Disk Size',
tooltip: 'Disk Size refers to the total space your project occupies on disk',
},
- !isFreePlan &&
+ entitledFeatures.includes('database') &&
(isSpendCapEnabled
? {
attribute: 'pg_database_size_percent_paid_spendCap',
diff --git a/apps/studio/data/reports/v2/auth.config.ts b/apps/studio/data/reports/v2/auth.config.ts
index 43c75f1bc12..bf0c4bc4af7 100644
--- a/apps/studio/data/reports/v2/auth.config.ts
+++ b/apps/studio/data/reports/v2/auth.config.ts
@@ -523,7 +523,6 @@ export const createUsageReportConfig = ({
defaultChartStyle: 'line',
titleTooltip:
"Users who generated any Auth event in this period. This metric tracks authentication activity, not total product usage. Some active users won't appear here if their session stayed valid.",
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const attributes = [
{ attribute: 'ActiveUsers', provider: 'logs', label: 'Auth Activity', enabled: true },
@@ -553,7 +552,6 @@ export const createUsageReportConfig = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'The total number of sign in attempts by type.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const attributes = [
{
@@ -608,7 +606,6 @@ export const createUsageReportConfig = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'The total number of sign ups.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const attributes = [
{
@@ -641,7 +638,6 @@ export const createUsageReportConfig = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'The total number of password reset requests.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const attributes = [
{
@@ -690,7 +686,6 @@ export const createErrorsReportConfig = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'The total number of auth errors by status code from the API Gateway.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const sql = AUTH_REPORT_SQL.ErrorsByStatus(interval, filters)
const rawData = await fetchLogs(projectRef, sql, startDate, endDate)
@@ -716,7 +711,6 @@ export const createErrorsReportConfig = ({
defaultChartStyle: 'line',
titleTooltip:
'The total number of auth errors by Supabase Auth error code from the API Gateway.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const sql = AUTH_REPORT_SQL.ErrorsByAuthCode(interval, filters)
const rawData = await fetchLogs(projectRef, sql, startDate, endDate)
@@ -775,7 +769,6 @@ export const createLatencyReportConfig = ({
defaultChartStyle: 'line',
titleTooltip:
'Basic processing time metrics for sign in operations within the auth server (excludes network latency).',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const attributes = [
{
@@ -816,7 +809,8 @@ export const createLatencyReportConfig = ({
defaultChartStyle: 'line',
titleTooltip:
'Percentile processing time metrics for sign in operations within the auth server (excludes network latency).',
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
+ entitlement: 'auth',
+ requiredPlan: 'Pro',
dataProvider: async () => {
const attributes = [
{
@@ -857,7 +851,6 @@ export const createLatencyReportConfig = ({
defaultChartStyle: 'line',
titleTooltip:
'Basic processing time metrics for sign up operations within the auth server (excludes network latency).',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const attributes = [
{
@@ -898,7 +891,8 @@ export const createLatencyReportConfig = ({
defaultChartStyle: 'line',
titleTooltip:
'Percentile processing time metrics for sign up operations within the auth server (excludes network latency).',
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
+ entitlement: 'auth',
+ requiredPlan: 'Pro',
dataProvider: async () => {
const attributes = [
{
diff --git a/apps/studio/data/reports/v2/edge-functions.config.ts b/apps/studio/data/reports/v2/edge-functions.config.ts
index 6c3ecc828e5..202e09ac1d9 100644
--- a/apps/studio/data/reports/v2/edge-functions.config.ts
+++ b/apps/studio/data/reports/v2/edge-functions.config.ts
@@ -213,7 +213,6 @@ export const edgeFunctionReports = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'The total number of edge function invocations over time.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const sql = METRIC_SQL.TotalInvocations(interval, filters)
const response = await fetchLogs(projectRef, sql, startDate, endDate)
@@ -245,7 +244,6 @@ export const edgeFunctionReports = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'The total number of edge function executions by status code.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const sql = METRIC_SQL.ExecutionStatusCodes(interval, filters)
const rawData = await fetchLogs(projectRef, sql, startDate, endDate)
@@ -277,7 +275,6 @@ export const edgeFunctionReports = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'Average execution time for edge functions.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
YAxisProps: {
width: 50,
tickFormatter: (value: number) => `${value}ms`,
@@ -339,7 +336,8 @@ export const edgeFunctionReports = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'The total number of edge function invocations by region.',
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
+ entitlement: 'edge_functions',
+ requiredPlan: 'Pro',
dataProvider: async () => {
const sql = METRIC_SQL.InvocationsByRegion(interval, filters)
const rawData = await fetchLogs(projectRef, sql, startDate, endDate)
diff --git a/apps/studio/data/reports/v2/realtime.config.ts b/apps/studio/data/reports/v2/realtime.config.ts
index 5901cbf8ac6..d91960b145a 100644
--- a/apps/studio/data/reports/v2/realtime.config.ts
+++ b/apps/studio/data/reports/v2/realtime.config.ts
@@ -62,7 +62,6 @@ export const realtimeReports = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'Total number of connected realtime clients.',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const data = await runInfraMonitoringQuery(
projectRef,
@@ -95,7 +94,6 @@ export const realtimeReports = ({
hideChartType: false,
defaultChartStyle: 'bar',
titleTooltip: '',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const { data } = await runInfraMonitoringQuery(
projectRef,
@@ -134,7 +132,6 @@ export const realtimeReports = ({
hideChartType: false,
defaultChartStyle: 'bar',
titleTooltip: '',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const { data } = await runInfraMonitoringQuery(
projectRef,
@@ -173,7 +170,6 @@ export const realtimeReports = ({
hideChartType: false,
defaultChartStyle: 'bar',
titleTooltip: '',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const { data } = await runInfraMonitoringQuery(
projectRef,
@@ -211,7 +207,6 @@ export const realtimeReports = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: '',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
dataProvider: async () => {
const data = await runInfraMonitoringQuery(
projectRef,
@@ -245,7 +240,6 @@ export const realtimeReports = ({
hideChartType: false,
defaultChartStyle: 'line',
titleTooltip: 'Median size of message payloads sent',
- availableIn: ['free', 'pro', 'team', 'enterprise', 'platform'],
YAxisProps: {
width: 50,
tickFormatter: (value: number) => `${value}B`,
@@ -285,7 +279,8 @@ export const realtimeReports = ({
defaultChartStyle: 'line',
titleTooltip:
'Median time between database commit and broadcast when using broadcast from database.',
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
+ entitlement: 'realtime',
+ requiredPlan: 'Pro',
YAxisProps: {
width: 50,
tickFormatter: (value: number) => `${value}ms`,
@@ -325,7 +320,8 @@ export const realtimeReports = ({
defaultChartStyle: 'line',
titleTooltip:
'Execution median time of RLS (Row Level Security) to subscribe to a private channel',
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
+ entitlement: 'realtime',
+ requiredPlan: 'Pro',
YAxisProps: {
width: 50,
tickFormatter: (value: number) => `${value}ms`,
@@ -365,7 +361,8 @@ export const realtimeReports = ({
defaultChartStyle: 'line',
titleTooltip:
'Execution median time of RLS (Row Level Security) to publish to a private channel',
- availableIn: ['pro', 'team', 'enterprise', 'platform'],
+ entitlement: 'realtime',
+ requiredPlan: 'Pro',
YAxisProps: {
width: 50,
tickFormatter: (value: number) => `${value}ms`,
diff --git a/apps/studio/data/reports/v2/reports.types.ts b/apps/studio/data/reports/v2/reports.types.ts
index 81cbf00036a..4410428a2bf 100644
--- a/apps/studio/data/reports/v2/reports.types.ts
+++ b/apps/studio/data/reports/v2/reports.types.ts
@@ -40,7 +40,9 @@ export interface ReportConfig<FiltersType = any> {
hideChartType: boolean
defaultChartStyle: string
titleTooltip: string
- availableIn: string[]
+ /** Set member value to check against the `observability.dashboard_advanced_metrics` set entitlement. If undefined, chart is available to all plans. */
+ entitlement?: string
+ requiredPlan?: string
format?: (value: unknown) => string
YAxisProps?: YAxisProps
xAxisKey?: string
diff --git a/apps/studio/pages/project/[ref]/observability/database.tsx b/apps/studio/pages/project/[ref]/observability/database.tsx
index da3f9b26c82..cf515da20cf 100644
--- a/apps/studio/pages/project/[ref]/observability/database.tsx
+++ b/apps/studio/pages/project/[ref]/observability/database.tsx
@@ -31,6 +31,7 @@ import { getReportAttributesV2 } from 'data/reports/database-charts'
import { useDatabaseReport } from 'data/reports/database-report-query'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
import dayjs from 'dayjs'
+import { useCheckEntitlements } from 'hooks/misc/useCheckEntitlements'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useRefreshHandler, useReportDateRange } from 'hooks/misc/useReportDateRange'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
@@ -72,7 +73,6 @@ const DatabaseUsage = () => {
updateDateRange,
datePickerValue,
datePickerHelpers,
- orgPlan,
showUpgradePrompt,
setShowUpgradePrompt,
handleDatePickerChange,
@@ -123,12 +123,23 @@ const DatabaseUsage = () => {
}
)
+ const { getEntitlementSetValues, isLoading: isEntitlementLoading } = useCheckEntitlements(
+ 'observability.dashboard_advanced_metrics'
+ )
+ const entitledFeatures = getEntitlementSetValues()
+
+ const isSpendCapEnabled =
+ entitledFeatures.includes('database') &&
+ !org?.usage_billing_enabled &&
+ project?.cloud_provider !== 'FLY'
+
const REPORT_ATTRIBUTES = getReportAttributesV2(
- org!,
+ entitledFeatures,
project!,
diskConfig,
maxConnections,
- defaultMaxClientConn
+ defaultMaxClientConn,
+ isSpendCapEnabled
)
const { isPending: isUpdatingDiskSize } = useProjectDiskResizeMutation({
@@ -245,9 +256,12 @@ const DatabaseUsage = () => {
}
>
{selectedDateRange &&
- orgPlan?.id &&
- REPORT_ATTRIBUTES.filter((chart) => !chart.hide).map((chart) =>
- chart.availableIn?.includes(orgPlan?.id) ? (
+ REPORT_ATTRIBUTES.filter((chart) => !chart.hide).map((chart) => {
+ const chartAvailable =
+ !chart.entitlement ||
+ isEntitlementLoading ||
+ entitledFeatures.includes(chart.entitlement)
+ return chartAvailable ? (
<LazyComposedChartHandler
key={chart.id}
{...chart}
@@ -269,14 +283,11 @@ const DatabaseUsage = () => {
) : (
<ReportChartUpsell
key={chart.id}
- report={{
- label: chart.label,
- availableIn: chart.availableIn ?? [],
- }}
+ report={{ label: chart.label, requiredPlan: chart.requiredPlan }}
orgSlug={org?.slug ?? ''}
/>
)
- )}
+ })}
{selectedDateRange && isReplicaSelected && (
<Panel title="Replica Information">
<Panel.Content>