Repository navigation
perf: introduce DAG-based Initializer system, eliminate ServerFactory, and remove ViewerMode - #890
Conversation
…lizer DAG refactor(core/init/default): decompose defaultextension.go into modular Initializers refactor(server): eliminate ServerFactory in favor of two-stage Initializer DAG
There was a problem hiding this comment.
Code Review
This pull request refactors the initialization and lifecycle management of the KHI application by introducing a DAG-based initialization engine (coreinit.Engine and Initializer) to replace the legacy InitExtension design. Additionally, it removes the ViewerMode configuration and its associated backend endpoints and frontend elements. The review feedback suggests making the Engine termination process thread-safe and idempotent using sync.Once, and adding os.O_TRUNC when opening the export destination file in job mode to prevent file corruption.
…le, and handle runner lifecycle
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the KHI application's initialization and lifecycle management by replacing the legacy InitExtension mechanism with a new DAG-based Initializer and Engine system. It modularizes various setup steps (such as logging, parameter parsing, OAuth, and server execution) into discrete initializers, simplifies the main entry point, and removes the 'Viewer Mode' configuration across both the backend and frontend. The review feedback highlights two key areas for improvement: first, a high-severity race condition in main.go during signal-initiated termination, where the application may exit prematurely with status 0 instead of waiting for the graceful shutdown to complete and returning the correct signal-based exit code; second, a limitation in the Engine where OnRun hooks are executed sequentially, which could block subsequent hooks if any of them are blocking.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the initialization and lifecycle management of the KHI application by replacing the legacy InitExtension mechanism with a new DAG-based initialization engine (Engine, InitContext, Initializer). It also completely removes the 'Viewer Mode' feature from both the backend parameters/routes and the frontend Angular application. The review feedback highlights three key areas for improvement: executing OnRun hooks concurrently to prevent blocking other services, configuring timeouts on the http.Server to avoid resource exhaustion, and calling file.Sync() during job exports to ensure data integrity.
Summary
This PR refactors KHI's backend initialization and server lifecycle into a modular, DAG-based
Initializersystem, eliminatesServerFactory/ServerOptionin favor of direct route registration, and completely removesViewerModeacross the backend and frontend.Key Changes
1. Modular DAG-based Initializer & Lifecycle System (
pkg/core/init)coreinit.Engine&coreinit.InitContext:ContextKey[T].coreinit.Initializerstructs.OnRunfor starting server/job runners andOnTerminatefor graceful teardown).pkg/core/init/default):defaultextension.gointo dedicated single-responsibility initializers:ParametersInitializer: CLI flag binding and parsing.LoggerInitializer: Slog initialization.KubernetesClientInitializer: In-cluster / out-of-cluster k8s client setup.InspectionServerInitializer: Task server and progress manager setup.GinServerInitializer: Gin engine and middleware setup.ServerInitializer: KHI HTTP routes registration.ServerRunnerInitializer: HTTP server listener and graceful shutdown handling.JobRunnerInitializer: Job mode execution handling.OAuthInitializer,DebugInitializer: Auth callback routes and pprof debug endpoints.cmd/kubernetes-history-inspector/main.go):main()from ~250 lines of procedural setup to cleanEngine.Init(),Engine.Run(), andEngine.Wait()lifecycle management with OS signal listening.2. Elimination of
ServerFactoryandServerOptions(pkg/server)ServerFactoryand functional options (pkg/server/option) with a direct route registration helperserver.SetupKHIServerRoutes(engine, ...)integrated intoServerInitializer.3. Complete Elimination of
ViewerModepkg/):--viewer-modeCLI parameter frompkg/parameters.pkg/server/configpackage and/api/v3/configendpoint.web/):GetConfigResponseschema andBackendAPI.getConfig()method.Viewer Modebadge fromHeaderComponent.StartupDialogComponentandInspectionListComponent(enabling "New Inspection" unconditionally).Verification
make test-go: All tests passed across all packages.make lint-go: 0 issues reported bygolangci-lint.make build-go: Successfully built binary.make test-web: All 728 unit tests passed in Karma ChromeHeadless.make lint-web: 0 lint errors reported by Angular ESLint & Stylelint.make build-storybook: Storybook build completed successfully.make build-web: Frontend production build succeeded.make pre-commit: Formatter and linters verified.