Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): warn when a bucket URL is not the provider you picked (#105633)

Tom Owers706fdd4f9a7f
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/components/SelfManagedSourceForm.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/components/SelfManagedSourceForm.tsx
index 8f1d7e0e6093..7c2e7dae8b75 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/components/SelfManagedSourceForm.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/components/SelfManagedSourceForm.tsx
@@ -7,6 +7,7 @@ import { LemonField } from 'lib/lemon-ui/LemonField'
import { ManualLinkSourceType } from '~/types'
+import { describeStorageProviderMismatch } from '../../../shared/storageProvider'
import { selfManagedSourceLogic } from '../selfManagedSourceLogic'
import { sourceWizardLogic } from '../sourceWizardLogic'
@@ -59,6 +60,7 @@ export function SelfManagedSourceForm({ onUpdate }: Props): JSX.Element {
const provider = manualLinkingProvider ?? 'aws'
const isCsvFormat = table?.format === 'CSV' || table?.format === 'CSVWithNames'
+ const providerMismatch = describeStorageProviderMismatch(table?.url_pattern, provider)
return (
<Form
@@ -106,6 +108,7 @@ export function SelfManagedSourceForm({ onUpdate }: Props): JSX.Element {
<div className="mb-4 text-xs text-secondary">
You can use <strong>*</strong> to select multiple files.
</div>
+ {providerMismatch && <div className="mb-4 text-xs text-warning">{providerMismatch}</div>}
<LemonField name="format" label="File format" className="mb-4 w-max">
{({ value = '', onChange }) => (
<LemonSelect
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
index 56719f687c05..ed6f00e1ed19 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceWizardLogic.tsx
@@ -51,6 +51,7 @@ import {
import type { WebhookCreateResult } from '../../shared/components/forms/WebhookSetupForm'
import { sourceManagementLogic } from '../../shared/logics/sourceManagementLogic'
import { clonePayloadPreservingFiles, findUploadedFiles, readJsonFile } from '../../shared/sourceFieldFiles'
+import { MANUAL_LINK_SOURCE_LABELS } from '../../shared/storageProvider'
import { shouldShowDestinationStep } from './components/destinationStepUtils'
import { FILE_UPLOAD_SOURCE_CONFIG, FILE_UPLOAD_SOURCE_NAME } from './fileUploadSource'
import { selfManagedSourceLogic } from './selfManagedSourceLogic'
@@ -314,13 +315,6 @@ export function resolveConnectErrorMessage(e: any): string {
return e?.message ?? 'Something went wrong setting up your source. Please try again.'
}
-const manualLinkSourceMap: Record<ManualLinkSourceType, string> = {
- aws: 'S3',
- 'google-cloud': 'Google Cloud Storage',
- 'cloudflare-r2': 'Cloudflare R2',
- azure: 'Azure',
-}
-
const isTimestampType = (field: IncrementalField): boolean => {
const type = field.type || field.field_type
return type === 'timestamp' || type === 'datetime' || type === 'date'
@@ -1723,7 +1717,7 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
() => [],
(): { name: string; type: ManualLinkSourceType }[] =>
manualLinkSources.map((source) => ({
- name: manualLinkSourceMap[source],
+ name: MANUAL_LINK_SOURCE_LABELS[source],
type: source,
})),
],
diff --git a/products/data_warehouse/frontend/shared/components/SourceIcon.tsx b/products/data_warehouse/frontend/shared/components/SourceIcon.tsx
index bf11a0b4642c..404068b2bde0 100644
--- a/products/data_warehouse/frontend/shared/components/SourceIcon.tsx
+++ b/products/data_warehouse/frontend/shared/components/SourceIcon.tsx
@@ -17,6 +17,7 @@ import IconFileUpload from 'public/services/file-upload.svg'
import IconGoogleCloudStorage from 'public/services/google-cloud-storage.png'
import { availableSourcesLogic } from '../../scenes/NewSourceScene/availableSourcesLogic'
+import { storageProviderFromUrl } from '../storageProvider'
import { supportsDirectQuery } from './forms/schemaGroupingUtils'
// eslint-disable-next-line import/no-cycle
import { getDataWarehouseSourceUrl } from './ManagedSourcesTable'
@@ -27,19 +28,7 @@ import { getDataWarehouseSourceUrl } from './ManagedSourcesTable'
* @param url
*/
export function mapUrlToProvider(url: string | undefined): string {
- if (!url) {
- return 'BlushingHog'
- }
- if (url.includes('amazonaws.com')) {
- return 'aws'
- } else if (url.startsWith('https://storage.googleapis.com')) {
- return 'google-cloud'
- } else if (url.includes('.blob.')) {
- return 'azure'
- } else if (url.includes('.r2.cloudflarestorage.com')) {
- return 'cloudflare-r2'
- }
- return 'BlushingHog'
+ return storageProviderFromUrl(url) ?? 'BlushingHog'
}
export function mapUrlToSourceName(url: string): string {
diff --git a/products/data_warehouse/frontend/shared/storageProvider.test.ts b/products/data_warehouse/frontend/shared/storageProvider.test.ts
new file mode 100644
index 000000000000..a61f9f4f611f
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/storageProvider.test.ts
@@ -0,0 +1,64 @@
+import { describeStorageProviderMismatch } from './storageProvider'
+
+describe('describeStorageProviderMismatch', () => {
+ it.each([
+ {
+ provider: 'google-cloud',
+ url: 'https://your-org.s3.amazonaws.com/invoices/*.pqt',
+ urlLabel: 'S3',
+ chosenLabel: 'Google Cloud Storage',
+ },
+ {
+ provider: 'aws',
+ url: 'https://storage.googleapis.com/your-org/invoices/*.pqt',
+ urlLabel: 'Google Cloud Storage',
+ chosenLabel: 'S3',
+ },
+ {
+ provider: 'aws',
+ url: 'https://your-account-id.r2.cloudflarestorage.com/invoices/*.pqt',
+ urlLabel: 'Cloudflare R2',
+ chosenLabel: 'S3',
+ },
+ {
+ provider: 'cloudflare-r2',
+ url: 'https://yourstorageaccount.blob.core.windows.net/your-container/*.pqt',
+ urlLabel: 'Azure',
+ chosenLabel: 'Cloudflare R2',
+ },
+ ] as const)(
+ 'names both providers for a $urlLabel URL under $chosenLabel',
+ ({ provider, url, urlLabel, chosenLabel }) => {
+ const message = describeStorageProviderMismatch(url, provider)
+
+ expect(message).toContain(`points at ${urlLabel}`)
+ expect(message).toContain(`you chose ${chosenLabel}`)
+ }
+ )
+
+ // An S3-compatible store reached through the `aws` provider lives on a host of its own, so an
+ // unrecognized host must stay silent rather than accuse the user of picking the wrong provider.
+ it.each([
+ { provider: 'aws', url: 'https://your-org.s3.amazonaws.com/invoices/*.pqt', case: 'a matching host' },
+ {
+ provider: 'google-cloud',
+ url: 'https://storage.googleapis.com/your-org/invoices/*.pqt',
+ case: 'a matching host',
+ },
+ {
+ provider: 'aws',
+ url: 'https://s3.us-west-1.wasabisys.com/your-org/invoices/*.pqt',
+ case: 'an S3-compatible host',
+ },
+ { provider: 'aws', url: '', case: 'an empty URL' },
+ { provider: 'aws', url: undefined, case: 'no URL yet' },
+ {
+ provider: 'google-cloud',
+ url: 'https://storage.googleapis.com/your-org/amazonaws.com/*.pqt',
+ case: "another provider's domain used as a folder name",
+ },
+ { provider: 'aws', url: 'not a url', case: 'an unparsable URL' },
+ ] as const)('stays quiet for $case', ({ provider, url }) => {
+ expect(describeStorageProviderMismatch(url, provider)).toBeNull()
+ })
+})
diff --git a/products/data_warehouse/frontend/shared/storageProvider.ts b/products/data_warehouse/frontend/shared/storageProvider.ts
new file mode 100644
index 000000000000..f4e806ed76b7
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/storageProvider.ts
@@ -0,0 +1,60 @@
+import { ManualLinkSourceType } from '~/types'
+
+/** How each self-managed storage provider is named in the source catalog. */
+export const MANUAL_LINK_SOURCE_LABELS: Record<ManualLinkSourceType, string> = {
+ aws: 'S3',
+ 'google-cloud': 'Google Cloud Storage',
+ 'cloudflare-r2': 'Cloudflare R2',
+ azure: 'Azure',
+}
+
+/**
+ * The provider a bucket URL belongs to, or null when the host names none of them.
+ *
+ * S3-compatible stores (MinIO, Wasabi, Backblaze) are reached through the `aws` provider on hosts
+ * of their own, so an unrecognized host is normal and must not be read as a wrong provider.
+ */
+export function storageProviderFromUrl(url: string | undefined): ManualLinkSourceType | null {
+ if (!url) {
+ return null
+ }
+ // Match on the hostname alone. A bucket path can carry another provider's domain as a folder
+ // name, and matching the whole URL reads that as the provider.
+ let hostname: string
+ try {
+ hostname = new URL(url).hostname.toLowerCase()
+ } catch {
+ return null
+ }
+ if (hostname === 'amazonaws.com' || hostname.endsWith('.amazonaws.com')) {
+ return 'aws'
+ }
+ if (hostname === 'storage.googleapis.com' || hostname.endsWith('.storage.googleapis.com')) {
+ return 'google-cloud'
+ }
+ // Azure blob storage answers on a different suffix per cloud (commercial, China, US government),
+ // so match the `blob` service label rather than one of those suffixes.
+ if (hostname.includes('.blob.')) {
+ return 'azure'
+ }
+ if (hostname.endsWith('.r2.cloudflarestorage.com')) {
+ return 'cloudflare-r2'
+ }
+ return null
+}
+
+/**
+ * Tells the user their bucket URL belongs to a provider other than the one they picked, or null
+ * when the two agree. The credentials of one provider never work against another's host, so this
+ * pairing can only fail, and it fails at query time long after the form is gone.
+ */
+export function describeStorageProviderMismatch(
+ urlPattern: string | undefined,
+ provider: ManualLinkSourceType
+): string | null {
+ const urlProvider = storageProviderFromUrl(urlPattern)
+ if (!urlProvider || urlProvider === provider) {
+ return null
+ }
+ return `This URL points at ${MANUAL_LINK_SOURCE_LABELS[urlProvider]}, but you chose ${MANUAL_LINK_SOURCE_LABELS[provider]}. Go back and pick ${MANUAL_LINK_SOURCE_LABELS[urlProvider]}, or enter a ${MANUAL_LINK_SOURCE_LABELS[provider]} URL.`
+}