Skip to main content

Configuration And Secrets

Canonical runtime env vars:

  • MONGODB_URI or MONGO_URI
  • MONGODB_URI_SECRET_NAME
  • KEY_VAULT_URL
  • CRM_EVENTS_REDIS_ENABLED
  • CRM_EVENTS_REDIS_URL
  • CRM_EVENTS_REDIS_URL_SECRET_NAME
  • CRM_EVENTS_REDIS_HOST
  • CRM_EVENTS_REDIS_HOST_SECRET_NAME
  • CRM_EVENTS_REDIS_PASSWORD
  • CRM_EVENTS_REDIS_PASSWORD_SECRET_NAME
  • CRM_EVENTS_REDIS_DB
  • CRM_EVENTS_API_PORT
  • CRM_EVENTS_API_CORS_ORIGINS
  • CRM_EVENTS_API_REQUIRE_DOCS_PROXY_BEARER_TOKEN
  • CRM_EVENTS_API_BEARER_TOKEN
  • CRM_EVENTS_CACHE_ENABLED
  • CRM_EVENTS_CACHE_OVERVIEW_TTL_SECONDS
  • CRM_EVENTS_CACHE_CAMPAIGNS_TTL_SECONDS
  • CRM_EVENTS_CACHE_LIVE_EVENTS_TTL_SECONDS

mongodb.* controls the Mongo connection that crm_events uses:

  • mongodb.uri
  • mongodb.uri_secret_name
  • mongodb.read_timeout_ms

redis.* controls the shared read-through cache:

  • redis.enabled
  • redis.url
  • redis.url_secret_name
  • redis.host
  • redis.host_secret_name
  • redis.password
  • redis.password_secret_name
  • redis.db

The owned local database name is fixed to crm_events. The HTTP API reads only local collections from that database:

  • campaign_snapshots
  • campaign_activity_events
  • support_case_events
  • live_events
  • sync_state

crm_events run starts automatic background jobs that refresh the campaign and overview slices hourly, and the live-events slice minutely. Tenants are enumerated from Content.config.

The background jobs still read fixed upstream Mongo databases in code: CRM, notify, notify_triggers, NotificationService, spark_bonus, Lumio, and Content.

CRM_EVENTS_API_CORS_ORIGINS is a comma-separated allowlist of browser origins. When it is unset and api.cors_origins is empty in YAML, the API only allows loopback browser origins such as http://localhost:3000.

CRM_EVENTS_API_REQUIRE_DOCS_PROXY_BEARER_TOKEN defaults to false. Set it to true when requests marked by the docs UI proxy should require bearer auth while unmarked in-cluster requests remain unauthenticated. When this is enabled, both docs-ui-svc and crm-events-svc read CRM_EVENTS_API_BEARER_TOKEN from the Kubernetes Secret crm-events-svc. The secret must expose that exact key name.

CRM_EVENTS_REDIS_ENABLED defaults to true. When it is false, crm_events does not cache reads at all.

Redis resolution prefers CRM_EVENTS_REDIS_URL, then CRM_EVENTS_REDIS_URL_SECRET_NAME, then host/password inputs where literal values beat the corresponding *_SECRET_NAME values and CRM_EVENTS_REDIS_DB supplies the DB suffix when needed. Any secret-name path requires KEY_VAULT_URL.

When Redis caching is enabled:

  • Mongo remains the source of truth
  • Redis failures fall back to Mongo reads
  • overview and campaigns default to a 1 hour payload TTL
  • live events default to a 60 second payload TTL
  • campaign list requests with a non-empty search filter bypass Redis payload caching

For spark-dev1, crm_events is configured with:

  • direct public ingress disabled
  • docs UI proxy at https://docs.spark-test.newtoncelestial.com/api/crm-events
  • in-cluster service URL http://crm-events-svc.spark-ai.svc.cluster.local
  • browser CORS allowlist entries for:
    • https://owners-hub.spark-test.newtoncelestial.com
    • https://docs.spark-test.newtoncelestial.com
  • docs UI proxy bearer auth enabled
  • docs-ui-svc and crm-events-svc load CRM_EVENTS_API_BEARER_TOKEN from the Kubernetes Secret crm-events-svc

For spark-prod-mexico1, crm_events is configured with:

  • public ingress at crm-events.prod-na-01.nwt-spark.net
  • docs UI proxy at https://docs.prod-na-01.nwt-spark.net/api/crm-events
  • in-cluster service URL http://crm-events-svc.spark-ai.svc.cluster.local
  • browser CORS allowlist entries for:
    • https://docs.prod-na-01.nwt-spark.net
    • https://dashboard.prod-na-01.nwt-spark.net
    • https://dashboard.prod-oh.newtoncelestial.com
  • docs UI proxy bearer auth enabled
  • docs-ui-svc and crm-events-svc load CRM_EVENTS_API_BEARER_TOKEN from the Kubernetes Secret crm-events-svc

The service supports Azure Key Vault resolution for:

  • Mongo URI
  • Redis URL
  • Redis host and password

If a *_SECRET_NAME value is set, KEY_VAULT_URL must also be set.

Response metadata

Every successful read response includes additive meta.sync metadata with:

  • tenant_id
  • slice
  • status
  • last_success_at
  • fresh_until
  • is_stale
  • lag_seconds for live-events slices

status is currently healthy, missing, or failed. is_stale becomes true when the slice is not healthy or its freshness window has elapsed.

Every response also includes X-Request-Id. Clients can supply that header on the request to preserve an upstream trace id, or read the generated value from the response for log correlation.

Prometheus metrics

/metrics exposes per-tenant, per-slice gauges derived from sync_state:

  • crm_events_sync_last_success_age_seconds
  • crm_events_sync_fresh_until_age_seconds
  • crm_events_sync_lag_seconds
  • crm_events_sync_failure_count

Each metric uses tenant_id and slice labels, where slice is one of overview, campaigns, or live_events.

crm_events_sync_failure_count is the consecutive failure count since the last successful sync for that tenant and slice. crm_events_sync_fresh_until_age_seconds is negative while the slice is still within its freshness window and becomes positive once the slice is stale.

Local compose defaults

Local compose expects the shared notify_triggers_notify-local Docker network and points Mongo at shared-mongo:27017 plus Redis at v2-redis:6379.

The service still writes and reads its owned crm_events database on that server. A fresh local read model starts empty until crm_events run bootstraps tenants from Content.config.

Default ports:

  • API: 8086
  • Health: 8086