-
Notifications
You must be signed in to change notification settings - Fork 0
Runtime controls and repository boundaries #4
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
Draft
JSYoo5B
wants to merge
23
commits into
codex/02-core-crud-resources
Choose a base branch
from
codex/03-runtime-repository-boundaries
base: codex/02-core-crud-resources
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
771d43d
refactor(network): split app service by resource
JSYoo5B d7dda14
refactor(compute): split app service by resource
JSYoo5B 2ff668f
refactor(volume): split app service by resource
JSYoo5B 7d49463
feat(runtime): add injectable clock for compute
JSYoo5B 9d17bd8
feat(runtime): add injectable clock for images
JSYoo5B 457f3a7
feat(runtime): add injectable clock for volumes
JSYoo5B 9caed46
feat(runtime): add injectable id generator for compute
JSYoo5B eccf0ad
feat(runtime): add injectable id generator for images
JSYoo5B a43fb37
feat(runtime): add injectable id generator for volumes
JSYoo5B 6a8421d
feat(runtime): add injectable id generator for network
JSYoo5B f83db37
feat(compute): activate servers on read
JSYoo5B d44a9a9
feat(volume): make volumes available on read
JSYoo5B 6c80f49
feat(runtime): add app service reset support
JSYoo5B 5d12dcd
feat(admin): add reset endpoint
JSYoo5B bb2bd60
feat(runtime): add request log service
JSYoo5B 32189d4
feat(admin): expose request recording
JSYoo5B a10ab0e
refactor(api): split router middleware
JSYoo5B 6042343
refactor(image): introduce repository boundary
JSYoo5B 63b73fe
refactor(network): introduce network repository boundary
JSYoo5B 18389b9
refactor(network): introduce subnet repository boundary
JSYoo5B 91f5c87
refactor(network): introduce port repository boundary
JSYoo5B bc8d870
refactor(compute): introduce server repository boundary
JSYoo5B 6a40197
refactor(volume): introduce volume repository boundary
JSYoo5B File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package admin | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/JSYoo5B/SandStack/internal/api/respond" | ||
| ) | ||
|
|
||
| func (h Handler) listRequests(w http.ResponseWriter, _ *http.Request) { | ||
| respond.JSON(w, http.StatusOK, requestListResponse{ | ||
| Requests: toRequestDocuments(h.requests.List()), | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package admin | ||
|
|
||
| import "github.com/JSYoo5B/SandStack/internal/app/requestlog" | ||
|
|
||
| type requestListResponse struct { | ||
| Requests []requestDocument `json:"requests"` | ||
| } | ||
|
|
||
| type requestDocument struct { | ||
| ID string `json:"id"` | ||
| Method string `json:"method"` | ||
| Path string `json:"path"` | ||
| Status int `json:"status"` | ||
| } | ||
|
|
||
| func toRequestDocuments(records []requestlog.Record) []requestDocument { | ||
| documents := make([]requestDocument, 0, len(records)) | ||
| for _, record := range records { | ||
| documents = append(documents, requestDocument{ | ||
| ID: record.ID, | ||
| Method: record.Method, | ||
| Path: record.Path, | ||
| Status: record.Status, | ||
| }) | ||
| } | ||
|
|
||
| return documents | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package admin | ||
|
|
||
| import "net/http" | ||
|
|
||
| func (h Handler) resetState(w http.ResponseWriter, _ *http.Request) { | ||
| h.reset() | ||
| w.WriteHeader(http.StatusNoContent) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/JSYoo5B/SandStack/internal/app/requestlog" | ||
| "github.com/JSYoo5B/SandStack/internal/platform/idgen" | ||
| ) | ||
|
|
||
| func requestID(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("X-Openstack-Request-Id", "req-"+idgen.RandomHex(16)) | ||
| next.ServeHTTP(w, r) | ||
| }) | ||
| } | ||
|
|
||
| func recordRequests(requests *requestlog.Service) func(http.Handler) http.Handler { | ||
| return func(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| recorder := &statusRecorder{ | ||
| ResponseWriter: w, | ||
| status: http.StatusOK, | ||
| } | ||
|
|
||
| next.ServeHTTP(recorder, r) | ||
|
|
||
| if strings.HasPrefix(r.URL.Path, "/_sandstack") { | ||
| return | ||
| } | ||
|
|
||
| requests.Add(requestlog.Record{ | ||
| ID: w.Header().Get("X-Openstack-Request-Id"), | ||
| Method: r.Method, | ||
| Path: r.URL.Path, | ||
| Status: recorder.status, | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| type statusRecorder struct { | ||
| http.ResponseWriter | ||
| status int | ||
| } | ||
|
|
||
| func (r *statusRecorder) WriteHeader(status int) { | ||
| r.status = status | ||
| r.ResponseWriter.WriteHeader(status) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,34 +10,43 @@ import ( | |
| "github.com/JSYoo5B/SandStack/internal/api/network" | ||
| "github.com/JSYoo5B/SandStack/internal/api/placement" | ||
| "github.com/JSYoo5B/SandStack/internal/api/volume" | ||
| appcompute "github.com/JSYoo5B/SandStack/internal/app/compute" | ||
| appimage "github.com/JSYoo5B/SandStack/internal/app/image" | ||
| appnetwork "github.com/JSYoo5B/SandStack/internal/app/network" | ||
| "github.com/JSYoo5B/SandStack/internal/app/requestlog" | ||
| appvolume "github.com/JSYoo5B/SandStack/internal/app/volume" | ||
| "github.com/JSYoo5B/SandStack/internal/platform/config" | ||
| "github.com/JSYoo5B/SandStack/internal/platform/idgen" | ||
| "github.com/go-chi/chi/v5" | ||
| ) | ||
|
|
||
| func NewRouter(cfg config.Config) http.Handler { | ||
| router := chi.NewRouter() | ||
| router.Use(requestID) | ||
| requests := requestlog.NewService() | ||
| router.Use(recordRequests(requests)) | ||
| identityHandler := identity.NewHandler(cfg) | ||
|
|
||
| router.Mount("/_sandstack", admin.NewRouter()) | ||
| computeService := appcompute.NewService() | ||
| imageService := appimage.NewService() | ||
| networkService := appnetwork.NewService() | ||
| volumeService := appvolume.NewService() | ||
|
|
||
| router.Mount("/_sandstack", admin.NewRouterWithState(func() { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reset endpoint receives a single composed reset function. This keeps admin routing separate from the concrete services while still making reset behavior cover all in-memory runtime state. |
||
| computeService.Reset() | ||
| imageService.Reset() | ||
| networkService.Reset() | ||
| volumeService.Reset() | ||
| requests.Reset() | ||
| }, requests)) | ||
|
|
||
| router.Get("/identity", identityHandler.Discovery()) | ||
| router.Get("/identity/", identityHandler.Discovery()) | ||
| router.Mount("/identity/v3", identityHandler.Router()) | ||
|
|
||
| router.Mount("/compute/v2.1", compute.NewRouter(cfg)) | ||
| router.Mount("/image/v2", image.NewRouter(cfg)) | ||
| router.Mount("/network/v2.0", network.NewRouter(cfg)) | ||
| router.Mount("/compute/v2.1", compute.NewRouterWithService(cfg, computeService)) | ||
| router.Mount("/image/v2", image.NewRouterWithService(cfg, imageService)) | ||
| router.Mount("/network/v2.0", network.NewRouterWithService(cfg, networkService)) | ||
| router.Mount("/placement", placement.NewRouter(cfg)) | ||
| router.Mount("/volume/v3", volume.NewRouter(cfg)) | ||
| router.Mount("/volume/v3", volume.NewRouterWithService(cfg, volumeService)) | ||
|
|
||
| return router | ||
| } | ||
|
|
||
| func requestID(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("X-Openstack-Request-Id", "req-"+idgen.RandomHex(16)) | ||
| next.ServeHTTP(w, r) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Request recording is created at the top router composition level because it is cross-service SandStack behavior. It should not leak into individual OpenStack service handlers.