mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-29 00:01:42 +08:00
fix(telemetry): avoid generic disable flag
This commit is contained in:
@@ -84,7 +84,6 @@ jobs:
|
||||
needs: check
|
||||
env:
|
||||
BETTER_AUTH_SECRET: ci-test-secret-that-is-at-least-32-chars
|
||||
ZPAN_TELEMETRY_DISABLED: '1'
|
||||
E2E_CLOUD_BUSINESS_EMAIL_NODE: ${{ secrets.E2E_CLOUD_BUSINESS_EMAIL_NODE }}
|
||||
E2E_CLOUD_BUSINESS_PASSWORD_NODE: ${{ secrets.E2E_CLOUD_BUSINESS_PASSWORD_NODE }}
|
||||
steps:
|
||||
@@ -132,7 +131,6 @@ jobs:
|
||||
needs: check
|
||||
env:
|
||||
BETTER_AUTH_SECRET: ci-test-secret-that-is-at-least-32-chars
|
||||
ZPAN_TELEMETRY_DISABLED: '1'
|
||||
E2E_CLOUD_BUSINESS_EMAIL_CF: ${{ secrets.E2E_CLOUD_BUSINESS_EMAIL_CF }}
|
||||
E2E_CLOUD_BUSINESS_PASSWORD_CF: ${{ secrets.E2E_CLOUD_BUSINESS_PASSWORD_CF }}
|
||||
steps:
|
||||
@@ -153,7 +151,6 @@ jobs:
|
||||
TRUSTED_ORIGINS=http://localhost:5185
|
||||
ZPAN_CLOUD_URL=https://zpan-cloud-staging.saltbo.workers.dev
|
||||
VITE_ZPAN_CLOUD_URL=https://zpan-cloud-staging.saltbo.workers.dev
|
||||
ZPAN_TELEMETRY_DISABLED=1
|
||||
E2E_STORAGE_ENDPOINT=http://127.0.0.1:9191
|
||||
E2E_STORAGE_BUCKET=e2e-test
|
||||
E2E_STORAGE_REGION=auto
|
||||
|
||||
@@ -53,8 +53,8 @@ function envAllowsIp(value: string | undefined): boolean {
|
||||
return !['0', 'false', 'no', 'off'].includes(value?.trim().toLowerCase() ?? '')
|
||||
}
|
||||
|
||||
function envDisablesTelemetry(value: string | undefined): boolean {
|
||||
return ['1', 'true', 'yes', 'on'].includes(value?.trim().toLowerCase() ?? '')
|
||||
function isGitHubActionsE2E(): boolean {
|
||||
return process.env.GITHUB_ACTIONS === 'true' && process.env.BETTER_AUTH_URL === 'http://localhost:5185'
|
||||
}
|
||||
|
||||
console.log('licensing.refresh.scheduler.started interval=6h')
|
||||
@@ -84,6 +84,8 @@ setInterval(() => {
|
||||
}, TRAFFIC_SYNC_INTERVAL_MS)
|
||||
|
||||
function reportNodeInstanceTelemetry(): void {
|
||||
if (isGitHubActionsE2E()) return
|
||||
|
||||
void (async () => {
|
||||
try {
|
||||
await reportInstanceTelemetry({
|
||||
@@ -92,7 +94,6 @@ function reportNodeInstanceTelemetry(): void {
|
||||
configuredInstanceId: process.env.ZPAN_INSTANCE_ID,
|
||||
siteUrl: process.env.ZPAN_PUBLIC_ORIGIN ?? process.env.BETTER_AUTH_URL,
|
||||
allowIp: envAllowsIp(process.env.ZPAN_TELEMETRY_ALLOW_IP),
|
||||
disabled: envDisablesTelemetry(process.env.ZPAN_TELEMETRY_DISABLED),
|
||||
},
|
||||
cron: INSTANCE_TELEMETRY_CRON,
|
||||
trigger: 'runtime',
|
||||
|
||||
@@ -57,7 +57,6 @@ describe('POST /api/internal/instance-telemetry/report', () => {
|
||||
configuredInstanceId: 'configured-instance',
|
||||
siteUrl: 'https://zpan.example.com/path',
|
||||
allowIp: true,
|
||||
disabled: false,
|
||||
},
|
||||
cron: '0 */12 * * *',
|
||||
trigger: 'deploy',
|
||||
|
||||
@@ -11,10 +11,6 @@ function envAllowsIp(value: string | undefined): boolean {
|
||||
return !['0', 'false', 'no', 'off'].includes(value?.trim().toLowerCase() ?? '')
|
||||
}
|
||||
|
||||
function envDisablesTelemetry(value: string | undefined): boolean {
|
||||
return ['1', 'true', 'yes', 'on'].includes(value?.trim().toLowerCase() ?? '')
|
||||
}
|
||||
|
||||
internal.post('/instance-telemetry/report', async (c) => {
|
||||
const platform = c.get('platform')
|
||||
const token = platform.getEnv(INTERNAL_API_TOKEN_ENV)?.trim()
|
||||
@@ -43,7 +39,6 @@ internal.post('/instance-telemetry/report', async (c) => {
|
||||
configuredInstanceId: platform.getEnv('ZPAN_INSTANCE_ID'),
|
||||
siteUrl: platform.getEnv('ZPAN_PUBLIC_ORIGIN') ?? platform.getEnv('BETTER_AUTH_URL'),
|
||||
allowIp: envAllowsIp(platform.getEnv('ZPAN_TELEMETRY_ALLOW_IP')),
|
||||
disabled: envDisablesTelemetry(platform.getEnv('ZPAN_TELEMETRY_DISABLED')),
|
||||
},
|
||||
cron: INSTANCE_TELEMETRY_CRON,
|
||||
trigger: 'deploy',
|
||||
|
||||
@@ -75,7 +75,6 @@ describe('handleScheduled', () => {
|
||||
configuredInstanceId: 'configured-instance',
|
||||
siteUrl: 'https://zpan.example',
|
||||
allowIp: true,
|
||||
disabled: false,
|
||||
},
|
||||
cron: '0 */12 * * *',
|
||||
trigger: 'scheduled',
|
||||
|
||||
@@ -60,20 +60,6 @@ describe('instance telemetry', () => {
|
||||
expect(getInstanceDisplayName).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not call the telemetry endpoint when telemetry is disabled', async () => {
|
||||
const result = await reportInstanceTelemetry({
|
||||
db: {} as Database,
|
||||
config: { disabled: true },
|
||||
cron: INSTANCE_TELEMETRY_CRON,
|
||||
runtime: { target: 'cloudflare-worker', provider: 'cloudflare' },
|
||||
})
|
||||
|
||||
expect(result).toEqual({ reported: false, reason: 'disabled' })
|
||||
expect(posthogMocks.PostHog).not.toHaveBeenCalled()
|
||||
expect(getOrCreateInstanceId).not.toHaveBeenCalled()
|
||||
expect(getInstanceDisplayName).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('captures the expected telemetry event with built-in PostHog host and project token', async () => {
|
||||
vi.mocked(getOrCreateInstanceId).mockResolvedValue('inst-1')
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ export interface InstanceTelemetryConfig {
|
||||
configuredInstanceId?: string
|
||||
siteUrl?: string
|
||||
allowIp?: boolean
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
export interface InstanceTelemetryRuntime {
|
||||
@@ -43,8 +42,6 @@ export interface InstanceTelemetryResult {
|
||||
}
|
||||
|
||||
export async function reportInstanceTelemetry(params: InstanceTelemetryParams): Promise<InstanceTelemetryResult> {
|
||||
if (params.config.disabled) return { reported: false, reason: 'disabled' }
|
||||
|
||||
const posthogHost = (params.config.posthogHost ?? INSTANCE_TELEMETRY_POSTHOG_HOST).trim()
|
||||
const posthogProjectToken = (params.config.posthogProjectToken ?? INSTANCE_TELEMETRY_POSTHOG_PROJECT_TOKEN).trim()
|
||||
if (!posthogHost || !posthogProjectToken) return { reported: false, reason: 'disabled' }
|
||||
|
||||
@@ -16,7 +16,6 @@ export interface ScheduledEnv {
|
||||
ZPAN_PUBLIC_ORIGIN?: string
|
||||
ZPAN_INSTANCE_ID?: string
|
||||
ZPAN_TELEMETRY_ALLOW_IP?: string
|
||||
ZPAN_TELEMETRY_DISABLED?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
@@ -27,10 +26,6 @@ function envAllowsIp(value: string | undefined): boolean {
|
||||
return !['0', 'false', 'no', 'off'].includes(value?.trim().toLowerCase() ?? '')
|
||||
}
|
||||
|
||||
function envDisablesTelemetry(value: string | undefined): boolean {
|
||||
return ['1', 'true', 'yes', 'on'].includes(value?.trim().toLowerCase() ?? '')
|
||||
}
|
||||
|
||||
export async function handleScheduled(event: ScheduledTrigger, env: ScheduledEnv): Promise<void> {
|
||||
const platform = createCloudflarePlatform(env)
|
||||
const cloudBaseUrl = env.ZPAN_CLOUD_URL ?? ZPAN_CLOUD_URL_DEFAULT
|
||||
@@ -47,7 +42,6 @@ export async function handleScheduled(event: ScheduledTrigger, env: ScheduledEnv
|
||||
configuredInstanceId: env.ZPAN_INSTANCE_ID,
|
||||
siteUrl: env.ZPAN_PUBLIC_ORIGIN ?? env.BETTER_AUTH_URL,
|
||||
allowIp: envAllowsIp(env.ZPAN_TELEMETRY_ALLOW_IP),
|
||||
disabled: envDisablesTelemetry(env.ZPAN_TELEMETRY_DISABLED),
|
||||
},
|
||||
cron: event.cron,
|
||||
trigger: 'scheduled',
|
||||
|
||||
Reference in New Issue
Block a user