Skip to content

[cleanup][nexus] Break-up some of the megafiles #1016

@smklein

Description

@smklein

Related to #1013 , which split up the model.rs file into a directory.

Line count of some of the major files:

   3038 ./external_api/http_entrypoints.rs
   3685 ./db/datastore.rs
   4028 ./nexus.rs

This is subjective, but personally I find smaller files much easier to navigate - crossing the 1000+ LoC threshold makes it easy to introduce murky coupling, and makes it easy to create merge conflicts when working on fundamentally different portions of the stack.

Before we directly go and break up these files, @davepacheco brought up the question: do we want to restructure these things, rather than merely splitting into smaller files by related function?

Source:

Regarding nexus.rs: is it worth rethinking this one? The original idea was to have a sort of business logic layer between the datastore and the HTTP endpoints that could be shared with interfaces besides than the HTTP endpoints. The best case for something like this is the logic around instance_set_runtime(), which is non-trivial, unrelated to the HTTP API itself, and might be used elsewhere like sagas or Nexus background tasks.

At the same time it feels like there's a ton of boilerplate here where this layer isn't adding anything. For the various CRUD functions that are all just (1) use LookupPath to look up a resource and then (2) call a datastore function to do something with that resource, I wonder if we're better off doing that stuff directly from the HTTP entrypoints.

The datastore layer exposes a pretty low-level interface atop the database that attempts to ensure database-level integrity, but doesn't know about higher-level application-level concerns. Examples: the idea of an Actor or ConsoleSessionWithSiloId is specific to the authn subsystem. Maybe the way to break up Nexus is to have more of these subsystems, maybe for different groups of resources, like an "instance" submodule that would contain the equivalent of instance_set_runtime(), etc. This might be clearer than a monolithic layer like nexus.rs currently provides. This is also different from just splitting the existing Nexus functions into different files. There's still a question of what to do for things that really have no specialized logic around them that are just basic CRUD.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cleanupCode cleanlinessdevelopmentBugs, paper cuts, feature requests, or other thoughts on making omicron development betternexusRelated to nexus

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions