Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Router code out of the main module etc. #380

Merged
merged 24 commits into from
Aug 21, 2023
Merged

Move Router code out of the main module etc. #380

merged 24 commits into from
Aug 21, 2023

Commits on Aug 18, 2023

  1. Move Router code out of the main module.

    It's currently very hard to unit test the methods of the Router type
    because it's so tightly coupled with program initialisation stuff in the
    main module.
    
    Moving it into its own module is the first step towards fixing this.
    sengi committed Aug 18, 2023
    Configuration menu
    Copy the full SHA
    11d00a5 View commit details
    Browse the repository at this point in the history

Commits on Aug 19, 2023

  1. Extract the mongo startup script from the Makefile.

    It's much easier to read and debug as a standalone shell script, plus we
    get shellcheck coverage.
    
    Hopefully this fixes the last of the mongo startup flakiness.
    sengi committed Aug 19, 2023
    Configuration menu
    Copy the full SHA
    f9eff5a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6ec7465 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    586023d View commit details
    Browse the repository at this point in the history
  4. Move version.go out of main and use BuildInfo.

    Move version.go from main to the router module (lib/) so that it can
    (later) be accessed from Router itself.
    
    Make it use standard debug.BuildInfo that the Go toolchain produced
    automatically, so we no longer have to mess about with shell scripts
    and linker flags.
    
    This eliminates some unnecessary differences between the Dockerfile and
    Makefile builds.
    sengi committed Aug 19, 2023
    Configuration menu
    Copy the full SHA
    bf04cfe View commit details
    Browse the repository at this point in the history
  5. Always print the version info on startup.

    It's useful to see the version string in the logs on startup.
    sengi committed Aug 19, 2023
    Configuration menu
    Copy the full SHA
    eb84ce6 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    f2fd2f8 View commit details
    Browse the repository at this point in the history
  7. Don't assume the default Prometheus registry.

    Registering metrics in a global namespace is neither test-friendly nor
    concurrency-safe. There's also the potential for name clashes to cause
    panics on startup, which can even happen implicitly on import because
    we've been calling prometheus.MustRegister() from module init functions.
    
    Injecting a prometheus.Registerer will allow us to write proper
    integration tests (and be able to run them in parallel), rather than
    almost everything having to be an end-to-end test that forks and execs
    an external Router binary.
    
    Also don't export Prometheus objects from modules. Nothing outside the
    module should depend on implementation details of the module's metrics.
    The public interface for reading metrics within the same process is
    prometheus.Gatherer. For everything else, there's `/metrics`.
    sengi committed Aug 19, 2023
    Configuration menu
    Copy the full SHA
    eab0792 View commit details
    Browse the repository at this point in the history
  8. Make metric var names less excessively verbose.

    <insert mean joke about Java>
    sengi committed Aug 19, 2023
    Configuration menu
    Copy the full SHA
    a3818f2 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    cd02846 View commit details
    Browse the repository at this point in the history
  10. Clarify metric descriptions.

    sengi committed Aug 19, 2023
    Configuration menu
    Copy the full SHA
    98e6e0d View commit details
    Browse the repository at this point in the history
  11. Pass NewRouter a struct instead of too many params.

    NewRouter()'s parameter list was already getting out of hand.
    
    Copying it straight into struct Router for now just for the sake of
    convenience. Probably change that soon.
    sengi committed Aug 19, 2023
    Configuration menu
    Copy the full SHA
    68cf596 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    d444d64 View commit details
    Browse the repository at this point in the history

Commits on Aug 20, 2023

  1. Avoid automatically registering metrics globally.

    Only the main module now touches the default Prometheus registry.
    
    We want to be able to refactor some of our unnecessarily-end-to-end
    tests into integration tests (in the true sense) and unit tests. To do
    that, we can't have components messing with global state.
    
    This also improves separation of concerns generally. For example, the
    triemux and handlers modules can no longer cause panics simply by being
    imported if there's a metric name clash.
    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    e1d62af View commit details
    Browse the repository at this point in the history
  2. Remove unnecessary envMap type from test helpers.

    It's way simpler to use cmd.Env.
    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    4a1900f View commit details
    Browse the repository at this point in the history
  3. Bind servers under test to local loopback interface.

    This eliminates the annoying "wants to accept incoming connections"
    popups on macOS.
    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    1b264cc View commit details
    Browse the repository at this point in the history
  4. Get rid of varargs in test helpers.

    Unnecessary abstraction in test helpers can easily undermine the value
    of the tests. Get rid of unnecessary logic and just be explicit.
    
    Most of this was generated with some sed-foo.
    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    22d8a86 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    46e13a6 View commit details
    Browse the repository at this point in the history
  6. Remove an unrelated test assertion.

    In a test that's supposed to check whether reloading the route table
    works, asserting that the async reload request took < 5 ms is neither
    helpful nor tasty, unlike this other [recipe for
    flakes](https://bakewithsarah.com/chocolate-fudge-flake-cake/).
    
    Also don't request the reload twice; it's unnecessary and makes the test
    slightly less useful, e.g. it would fail to catch a bug where the reload
    fails the first time but succeeds on retry.
    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    341963e View commit details
    Browse the repository at this point in the history
  7. More deflaking: allow 1.5 poll intervals for reload.

    The default poll interval is 2 s, so wait 3.
    
    This doesn't slow down the test; gomega.Eventually polls every 10 ms by
    default.
    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    7940707 View commit details
    Browse the repository at this point in the history
  8. Remove /stats API endpoint.

    `/stats` is disused and useless now that we have a Prometheus gauge for
    the route count. It didn't use to return anything else.
    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    73b9cd9 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    d3ad82c View commit details
    Browse the repository at this point in the history
  10. Fix typo in test name.

    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    832ef3e View commit details
    Browse the repository at this point in the history
  11. Fix bad syntax in examples.

    sengi committed Aug 20, 2023
    Configuration menu
    Copy the full SHA
    46d2942 View commit details
    Browse the repository at this point in the history