Skip to content

fix: analytics 500s, production-safe config, optional credentials, CI - #11

Merged
op-techy merged 3 commits into
mainfrom
fix/analytics-config-hardening
Dec 2, 2026
Merged

op-techy merged 3 commits into
mainfrom
fix/analytics-config-hardening

Conversation

@op-techy

@op-techy op-techy commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Found by re-running the whole app end to end in Docker after #10.

Bugs

  • Campaign timeline returned 500 (GET /api/analytics/campaigns/{id}/timeline). DATE_TRUNC on a TIMESTAMP column comes back as java.sql.Timestamp, but the code read it as Instant (ClassCastException). It is now read as UTC wall-clock time, so the hour is right whatever the JVM time zone.
  • Engagement refresh returned 500 (POST /api/analytics/engagement-scores/refresh). Postgres could not type :nowUtc - INTERVAL '90 days' and failed with operator does not exist: timestamp > interval. The parameter is now cast to timestamp.

Configuration

  • Logging is INFO by default instead of DEBUG for Spring Security, Web and Data. Raise a package with LOGGING_LEVEL_<PACKAGE>=DEBUG.
  • CORS is now one config in SecurityConfig:
    • origins come from CORS_ALLOWED_ORIGINS (default *)
    • credentials are never allowed, since auth is a Bearer header and no cookies are used
    • before this, every origin was allowed with credentials
    • removed the unused CorsConfig and the spring.mvc.cors block, which Spring Boot ignores
  • Swagger server URL comes from APP_BASE_URL instead of a hardcoded personal ngrok URL.
  • Optional settings no longer stop the app from starting:
    • RESEND_API_KEY, MAIL_*, IPINFO_TOKEN, AWS_S3_BUCKET, AWS keys
    • with blank AWS keys, the AWS SDK's default credentials chain is used (e.g. an IAM role)
    • senders that aren't configured are skipped
    • image upload without a bucket returns 503 with a clear message instead of a generic 500
  • build.gradle:
    • one AWS BOM (2.25.27) instead of modules declared at two versions
    • duplicate yauaa removed
    • unused MaxMind GeoIP2 removed (replaced by IPinfo)
    • the resolved runtime classpath is otherwise unchanged (checked with a dependency diff)
  • Docker: the runtime image runs as an unprivileged app user.
  • CI: .github/workflows/ci.yml runs the unit, integration and scale tests and builds the Docker image on every PR and push to main.

⚠️ Deploy notes

  • Set CORS_ALLOWED_ORIGINS to the frontend's domain in production. Without it any origin is allowed, as before.
  • Swagger UI now targets APP_BASE_URL, so make sure it is the public URL.

Not changed

  • Page JSON. Spring still logs a one-time warning that the paged JSON (PageImpl) format may change. The only way to silence it is to switch to the VIA_DTO format, which moves totalElements and the other paging fields under page and would break the frontend. That needs coordination with the frontend.
  • Unused dependencies. bucket4j and the Caffeine/cache starter aren't used by any code yet. They're labelled as planned work (BE-3/BE-4), so I left them in.

Test plan

  • ./gradlew test: 353/353 passed (6 new: optional senders, IPinfo, CORS config, CORS preflight)
  • ./gradlew integrationTest: 27/27 passed (4 new)
    • timeline hour and engagement refresh, both failing before the fix
    • app starts with only the required settings, which fails before the change
    • upload without a bucket returns 503
  • ./gradlew scaleTest: 9/9 passed
  • Image built (arm64) and run against postgres:16-alpine with only DB, JWT, APP_BASE_URL, AWS_FROM_EMAIL and CORS_ALLOWED_ORIGINS set:
    • starts in about 6 s and runs as app
    • login, CSV import and send (3/3) work
    • open tracking, timeline and engagement refresh return 200
    • CORS allows the configured origin and rejects others with 403
    • Swagger points at APP_BASE_URL
    • no ERROR and no DEBUG lines in the log
  • Same image in the default profile with no senders configured: starts, SES reported unhealthy, Resend skipped

- Timeline: DATE_TRUNC on a TIMESTAMP column comes back as java.sql.Timestamp,
  which the code read as Instant (ClassCastException). The value is read as
  UTC wall-clock time, so the hour is right whatever the JVM time zone.
- Engagement refresh: Postgres could not type ":nowUtc - INTERVAL '90 days'"
  and failed with "timestamp > interval". The parameter is cast to timestamp.
- Integration tests for both (the JVM runs in Africa/Lagos, so a time-zone
  shift of the timeline hour is caught too).
… image

- Logging: INFO by default instead of DEBUG for Spring Security/Web/Data;
  raise per package with LOGGING_LEVEL_<PACKAGE>.
- CORS: one config in SecurityConfig, origins from CORS_ALLOWED_ORIGINS
  (default any), never credentials (auth is a Bearer header). Removes the
  unused CorsConfig and the spring.mvc.cors block, which Spring Boot ignored.
- Swagger server URL comes from APP_BASE_URL instead of a personal ngrok URL.
- Optional settings no longer stop the app from starting: RESEND_API_KEY,
  MAIL_*, AWS keys (blank = SDK default chain, e.g. an IAM role),
  AWS_S3_BUCKET and IPINFO_TOKEN. Unconfigured senders are skipped; image
  uploads without a bucket return 503 with a clear message.
- build.gradle: one AWS BOM (2.25.27) instead of modules pinned at two
  versions, duplicate yauaa removed, unused MaxMind GeoIP2 removed. The
  resolved runtime classpath is otherwise unchanged.
- Dockerfile: the runtime image runs as an unprivileged user.
- Tests for the optional settings, CORS, and starting with only the required
  settings. README and .env.example updated.
@op-techy
op-techy force-pushed the fix/analytics-config-hardening branch from f89249b to 44dd1f5 Compare December 2, 2026 22:05
@op-techy
op-techy merged commit cabdfc1 into main Dec 2, 2026
2 checks passed
@op-techy
op-techy deleted the fix/analytics-config-hardening branch December 2, 2026 22:29
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