Skip to content

fix: bypass GetAccounts API call when CF_ACCOUNTS is set#1

Merged
aymanbagabas merged 1 commit intomainfrom
fix/bypass-get-accounts-when-cf-accounts-configured
Mar 24, 2026
Merged

fix: bypass GetAccounts API call when CF_ACCOUNTS is set#1
aymanbagabas merged 1 commit intomainfrom
fix/bypass-get-accounts-when-cf-accounts-configured

Conversation

@aymanbagabas
Copy link
Copy Markdown
Owner

Problem

When CF_ACCOUNTS is configured, the exporter hangs indefinitely on startup. The refreshAccounts function always calls client.GetAccounts() which uses ListAutoPaging under the hood — this requires Account:Read permission that zone-scoped API tokens don't have. The call blocks until the 30s context timeout, then sets cloudflare_exporter_up=0 and retries every ACCOUNT_CACHE_TTL (default 10m), never making progress.

The /health endpoint passes because it uses a different API call, masking the issue.

Fix

When CF_ACCOUNTS is explicitly set, skip the GetAccounts API call entirely and build the account list directly from the configured IDs. The API call is only made when CF_ACCOUNTS is not set, preserving existing behavior for tokens with full account permissions.

Test

CF_ACCOUNTS=<account-id>  # zone-scoped token

Before: exporter hangs at fetching accounts, cloudflare_exporter_up=0
After: exporter starts immediately, discovers zones and collects metrics

When CF_ACCOUNTS is explicitly configured, the exporter hung indefinitely
on startup because ListAutoPaging requires Account:Read permissions that
zone-scoped tokens don't have.

When CF_ACCOUNTS is provided, skip the API call entirely and construct the
account list directly from the configured IDs. The API is only called when
CF_ACCOUNTS is not set, preserving existing behavior for unrestricted tokens.
@aymanbagabas aymanbagabas merged commit 0bc3b53 into main Mar 24, 2026
1 check passed
@aymanbagabas aymanbagabas deleted the fix/bypass-get-accounts-when-cf-accounts-configured branch March 24, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant