Skip to content

Bandit-only fork: drop Plug.Cowboy, add bandit_opts - #1

Merged
asib merged 4 commits into
masterfrom
bandit-transport-opts
Apr 28, 2026
Merged

Bandit-only fork: drop Plug.Cowboy, add bandit_opts#1
asib merged 4 commits into
masterfrom
bandit-transport-opts

Conversation

@asib

@asib asib commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Builds on upstream #266 (Bandit support), then simplifies the metrics server to Bandit-only and exposes transport-level configuration so callers can pass through Thousand Island options.

  • Cherry-picks the three commits from feat(metrics_server): Add Bandit support akoutmos/prom_ex#266.
  • Collapses the compile-time cond do … end in lib/prom_ex.ex to a single Bandit-only server_spec/5. Drops the Plug.Cowboy branch and the cowboy_opts / pool_size config keys.
  • Promotes :bandit and :plug to required deps; drops :plug_cowboy.
  • Adds a bandit_opts: keyword in metrics_server config that's spliced into Bandit.child_spec/1, with defensive Keyword.drop for :scheme/:plug/:port.
  • Tests for config parsing and child-spec injection (test/prom_ex/config_test.exs, test/prom_ex/metrics_server/startup_test.exs).

Why

fly_deploy's blue/green mode injects `reuseport: true, reuseaddr: true` into the Phoenix Endpoint's transport at peer-boot so old and new peers can both bind the same port during cutover. We want the same overlap-tolerance for the standalone metrics listener — without it, the new peer fails `:eaddrinuse` during the brief overlap.

Example downstream config (sprites-api):

```elixir
config :sprites, Sprites.PromEx,
metrics_server: [
port: 9568,
path: "/metrics",
protocol: :http,
auth_strategy: :none,
bandit_opts: [
thousand_island_options: [
transport_options: [reuseport: true, reuseaddr: true]
]
]
]
```

Test plan

  • `mix deps.get && MIX_ENV=test mix compile --warnings-as-errors` — clean.
  • `mix test test/prom_ex/config_test.exs test/prom_ex/metrics_server/` — 22/22 pass (includes 6 new tests for `bandit_opts`).
  • Full suite (excluding two phoenix_test files pre-broken on upstream master by an Elixir 1.18 macro escaping issue): 4 doctests + 116 tests, 0 failures.
  • Manual verification: two `Bandit.start_link` calls with this `bandit_opts` config bind 9568 simultaneously; a second listener without the config fails `:eaddrinuse`.

🤖 Generated with Claude Code

odarriba and others added 4 commits April 28, 2026 21:31
Builds on PR akoutmos#266 (Bandit support) by simplifying the metrics
server to Bandit-only and exposing transport-level configuration:

- Collapse server_spec/5 to a single Bandit definition. Plug.Cowboy
  branch and the cowboy_opts/pool_size config keys are removed.
- Promote :bandit and :plug to required deps; drop :plug_cowboy.
- New :bandit_opts keyword in metrics_server config is spliced into
  Bandit.child_spec/1 (with defensive Keyword.drop for :scheme/:plug/
  :port). Lets callers pass thousand_island_options through, e.g.
  reuseport/reuseaddr for blue/green hot deploys.
- Tests for bandit_opts parsing and child-spec injection.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@asib
asib merged commit 3dc878f into master Apr 28, 2026
@asib
asib deleted the bandit-transport-opts branch April 29, 2026 20:32
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.

2 participants