agentleFS
CloudflareKnown publishercloudflare/cloudflare-prometheus-exporter/AGENTS.md

cloudflare-prometheus-exporter

AGENTS.md182 starsChanged 9 months agoMITView on GitHub

Generated: 2026-01-05 Change: p Cloudflare Prometheus exporter: Worker + Durable Objects fetching CF metrics via GraphQL/REST, exposing Prometheus format. Stack: Hono, gql.tada, Zod, urql. TypeScript (strict mode enforced): - noUncheckedIndexedAccess: true - index access returns T | undefined - verbatimModuleSyntax: true - explicit type imports required - Zod for runtime validation at boundaries Formatting (Biome): - Tabs, double quotes - Auto-organize imports DO Patterns: - State loaded in blockConcurrencyWhile constructor - Alarms for refresh scheduling (jitter applied) - Static get()…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Avoid adding new as casts

    line 63
  2. Very specific:

    Metric types: Only counter and gauge (no histogram/summary)

    line 82

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

PROJECT KNOWLEDGE BASE

Generated: 2026-01-05 Change: p

OVERVIEW

Cloudflare Prometheus exporter: Worker + Durable Objects fetching CF metrics via GraphQL/REST, exposing Prometheus format. Stack: Hono, gql.tada, Zod, urql.

STRUCTURE

src/
  worker.tsx           # Entry: Hono app + DO exports
  durable-objects/     # 3 DOs: MetricCoordinator → AccountMetricCoordinator → MetricExporter
  lib/                 # Shared: types, config, prometheus serialization, logging
  cloudflare/          # CF API client + GraphQL queries
    gql/               # Generated: schema.gql, graphql-env.d.ts (DO NOT EDIT)
  components/          # Landing page JSX (Hono JSX, not React)

WHERE TO LOOK

TaskLocationNotes
Add metric querysrc/cloudflare/queries.ts + src/cloudflare/client.tsAdd to enum, implement in client
Modify DO statesrc/durable-objects/*.tsEach DO has typed state, persisted via ctx.storage
Config optionssrc/lib/runtime-config.tsKV overrides + env defaults, Zod-validated
Prometheus outputsrc/lib/prometheus.tsserializeToPrometheus()
GraphQL typesRun bun run gql:generateRegenerates src/cloudflare/gql/

CODE MAP

SymbolTypeLocationRole
MetricCoordinatorDOdurable-objects/MetricCoordinator.tsSingleton, owns account list, delegates to AccountMetricCoordinator
AccountMetricCoordinatorDOdurable-objects/AccountMetricCoordinator.tsPer-account, manages zone list + MetricExporter DOs
MetricExporterDOdurable-objects/MetricExporter.tsPer-query scope, fetches + caches metrics, handles counter accumulation
CloudflareMetricsClientClasscloudflare/client.tsGraphQL + REST client, DataLoader batching
getConfigFnlib/runtime-config.tsMerges KV overrides with env defaults
serializeToPrometheusFnlib/prometheus.tsMetricDefinition[] → text format

CONVENTIONS

TypeScript (strict mode enforced):

  • noUncheckedIndexedAccess: true - index access returns T | undefined
  • verbatimModuleSyntax: true - explicit type imports required
  • Zod for runtime validation at boundaries

Formatting (Biome):

  • Tabs, double quotes
  • Auto-organize imports

DO Patterns:

  • State loaded in blockConcurrencyWhile constructor
  • Alarms for refresh scheduling (jitter applied)
  • Static get() factory ensures initialization

ANTI-PATTERNS (THIS PROJECT)

Type assertions exist but constrained:

  • env as Env & OptionalEnvVars in config files (widening for optional vars)
  • Avoid adding new as casts

console.error in DOs:

  • Some DOs use console.error instead of logger for uninitialized state errors
  • New code should use createLogger()

Silent catches:

  • worker.tsx:98 - .catch(() => null) for JSON parse
  • Acceptable for input validation; avoid for business logic

Generated files - DO NOT EDIT:

  • src/cloudflare/gql/graphql-env.d.ts
  • src/cloudflare/gql/schema.gql
  • worker-configuration.d.ts

UNIQUE STYLES

DO ID format: "scope:id:queryName" (e.g., "account:abc123:http-metrics")

Metric types: Only counter and gauge (no histogram/summary)

Free tier handling: CF_FREE_TIER_ACCOUNTS env var, zones filtered from paid-tier GraphQL queries

Counter accumulation: Cloudflare returns window totals; DOs accumulate for Prometheus monotonic semantics

Hostname metrics: Allowlist-based (HOST_METRICS_ALLOWLIST, max 50). All gauges, fixed 1-minute window for alerting. Avg latencies as primary metrics; P50/P95 as separate metric families (_p50_seconds, _p95_seconds). Ingestion delay controlled by HOST_METRICS_DELAY_SECONDS (default 60s), independent from global SCRAPE_DELAY_SECONDS. Hosts normalized to lowercase. Disabled when allowlist empty or excludeHost=true.

COMMANDS

bun run dev          # Local dev (wrangler dev)
bun run deploy       # Deploy to CF
bun run check        # Biome lint + format check
bun run format       # Auto-format
bun run gql:generate # Regenerate GraphQL types
bun run cf-typegen   # Regenerate worker-configuration.d.ts

NOTES

No tests: Project lacks test infrastructure

Docker: For local Prometheus scraping only, not production deployment

Rate limiting: CF_API_RATE_LIMITER binding (200 req/10s) - shared across all DOs in worker. Rough budget: ~160 req/60s per 50-zone account (incl REST); ~7 such accounts can saturate.

Dual config: wrangler.jsonc vars + optional env vars + KV runtime overrides

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.