Skip to content

Conversation

@mostlygeek
Copy link
Owner

@mostlygeek mostlygeek commented Sep 28, 2025

The configuration is become more complex as llama-swap adds more advanced features. This commit moves config to its own package so it can be developed independently of the proxy package.

Additionally, enforcing a public API for a configuration will allow downstream usage to be more decoupled.

Summary by CodeRabbit

  • Refactor
    • Centralized configuration into a dedicated config module and updated components to use it; ensured runtime reload paths initialize consistently with the new module.
  • Tests
    • Updated test suite to use the new configuration module and types; adjusted tests to preserve cross-platform coverage.
  • Chores
    • Simplified Makefile test commands for targeted and full runs and added missing phony targets for improved build reliability.

The configuration is become more complex as llama-swap adds more
advanced features. This commit moves config to its own package so it can
be developed independently of the proxy package.

Additionally, enforcing a public API for a configuration will allow
downstream usage to be more decoupled.
@coderabbitai
Copy link

coderabbitai bot commented Sep 28, 2025

Walkthrough

Refactors configuration into a dedicated proxy/config package and updates all call sites and tests to use config.Config / config.ModelConfig. Adjusts Makefile test targets to ./proxy/... and adds test/test-all to .PHONY. Updates main reload path to use config.LoadConfig and swap the proxy handler with the new config.

Changes

Cohort / File(s) Summary
Build & Test Targets
Makefile
Updated test invocations to use ./proxy/... and added test and test-all to .PHONY.
Main entrypoint config usage
llama-swap.go
Import proxy/config; call config.LoadConfig; rename local var to conf; on reload recreate handler via proxy.New(conf); preserve reload signaling.
Proxy manager API and usage
proxy/proxymanager.go, proxy/proxymanager_test.go
Import proxy/config; New now accepts config.Config; tests updated to use config.* types and config.LoadConfigFromReader; default ID refs updated.
Process and ProcessGroup types & tests
proxy/process.go, proxy/process_test.go, proxy/processgroup.go, proxy/processgroup_test.go
Replace local ModelConfig/Config with config.ModelConfig/config.Config; update constructors (NewProcess, NewProcessGroup) and uses (e.g., config.SanitizeCommand); tests adjusted.
Metrics monitor
proxy/metrics_monitor.go
NewMetricsMonitor now accepts *config.Config; added config import.
Test helpers
proxy/helpers_test.go
Test helper return and local types changed to config.ModelConfig; added config import.
Config package extraction
proxy/config/config.go
Package declaration changed from proxy to config; code otherwise unchanged.
Config package tests
proxy/config/config_test.go, proxy/config/config_posix_test.go, proxy/config/config_windows_test.go
Package declarations changed from proxy to config to match extraction; test code unchanged.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Main as llama-swap (main)
    participant CFG as config.LoadConfig
    participant PM as Proxy (srv)
    participant Watch as fsnotify (watcher)

    Note over Main,CFG: startup
    Main->>CFG: LoadConfig(path)
    CFG-->>Main: conf
    Main->>PM: srv.Handler = proxy.New(conf)
    Note right of PM: proxy handler running

    Note over Watch: config file watcher
    Watch->>Main: config change event
    Main->>CFG: LoadConfig(path)  -- reload
    CFG-->>Main: conf'
    Main->>PM: srv.Handler = proxy.New(conf')  -- swap handler
    Note right of PM: handler replaced (hot-swap)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

configuration, enhancement

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly conveys the primary change of extracting configuration into a new config package and migrating existing configuration code out of the proxy module, making it clear and specific enough for a reviewer scanning the history to understand the pull request’s intent.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch config-subpackage

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c92e662 and 10ec5b0.

📒 Files selected for processing (1)
  • Makefile (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Makefile

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
proxy/proxymanager_test.go (1)

25-68: Fix the short var declarations that shadow the config package

Statements like config := config.AddDefaultGroupToConfig(...) attempt to declare a local variable named config while simultaneously referring to the imported config package. In Go, the newly declared identifier’s scope covers the entire statement, so the right-hand side no longer sees the package and compilation fails (e.g. “config.AddDefaultGroupToConfig undefined”). The same issue appears throughout this file, including other short declarations (config := ..., config, err := ..., config := config.Config{...}). Please rename the local variable (e.g. cfg) in all of these spots.

A representative fix for this block:

-	config := config.AddDefaultGroupToConfig(config.Config{
+	cfg := config.AddDefaultGroupToConfig(config.Config{
 		HealthCheckTimeout: 15,
 		Models: map[string]config.ModelConfig{
 			"model1": getTestSimpleResponderConfig("model1"),
 			"model2": getTestSimpleResponderConfig("model2"),
 		},
 		LogLevel: "error",
 	})
 
-	proxy := New(config)
+	proxy := New(cfg)

Apply the same pattern everywhere the tests currently shadow the package name so the suite compiles again.

🧹 Nitpick comments (1)
llama-swap.go (1)

42-95: Avoid double-loading configuration on startup

Line 42 already loads the config into conf, but when reloadProxyManager() runs for the first time (Line 98) the else branch executes and immediately calls config.LoadConfig again because srv.Handler is still nil. Consider threading the preloaded conf into that initial handler creation so we only hit the filesystem once during startup. This keeps boot time leaner, especially when configs live on slower volumes.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e3d491 and bcbead3.

📒 Files selected for processing (13)
  • Makefile (2 hunks)
  • config/config.go (1 hunks)
  • config/config_posix_test.go (1 hunks)
  • config/config_test.go (1 hunks)
  • llama-swap.go (4 hunks)
  • proxy/helpers_test.go (2 hunks)
  • proxy/metrics_monitor.go (2 hunks)
  • proxy/process.go (4 hunks)
  • proxy/process_test.go (6 hunks)
  • proxy/processgroup.go (2 hunks)
  • proxy/processgroup_test.go (4 hunks)
  • proxy/proxymanager.go (3 hunks)
  • proxy/proxymanager_test.go (22 hunks)
🧰 Additional context used
🧬 Code graph analysis (10)
config/config_posix_test.go (2)
proxy/config_posix_test.go (2)
  • TestConfig_DefaultValuesPosix (49-89)
  • TestConfig_LoadPosix (91-242)
proxy/config_test.go (6)
  • TestConfig_MacroInCommentStrippedBeforeExpansion (383-442)
  • name (331-335)
  • TestConfig_AutomaticPortAssignments (128-200)
  • TestConfig_MacroReplacement (202-232)
  • name (235-239)
  • TestConfig_MacroModelId (444-483)
proxy/processgroup.go (2)
config/config.go (1)
  • Config (149-169)
proxy/logMonitor.go (1)
  • LogMonitor (23-35)
proxy/proxymanager.go (1)
config/config.go (1)
  • Config (149-169)
proxy/metrics_monitor.go (1)
config/config.go (1)
  • Config (149-169)
proxy/process_test.go (2)
config/config.go (1)
  • ModelConfig (20-40)
proxy/process.go (1)
  • NewProcess (78-103)
proxy/helpers_test.go (1)
config/config.go (1)
  • ModelConfig (20-40)
proxy/process.go (1)
config/config.go (2)
  • ModelConfig (20-40)
  • SanitizeCommand (414-447)
proxy/processgroup_test.go (2)
config/config.go (5)
  • AddDefaultGroupToConfig (370-412)
  • Config (149-169)
  • ModelConfig (20-40)
  • GroupConfig (116-121)
  • DEFAULT_GROUP_ID (18-18)
proxy/processgroup.go (1)
  • NewProcessGroup (29-54)
proxy/proxymanager_test.go (2)
config/config.go (7)
  • AddDefaultGroupToConfig (370-412)
  • Config (149-169)
  • ModelConfig (20-40)
  • GroupConfig (116-121)
  • DEFAULT_GROUP_ID (18-18)
  • LoadConfigFromReader (198-367)
  • ModelFilters (77-79)
proxy/proxymanager.go (1)
  • New (48-131)
llama-swap.go (2)
config/config.go (1)
  • LoadConfig (189-196)
proxy/proxymanager.go (1)
  • New (48-131)

@mostlygeek mostlygeek merged commit 216c40b into main Sep 28, 2025
3 checks passed
@mostlygeek mostlygeek deleted the config-subpackage branch September 28, 2025 23:50
0uep pushed a commit to LM4eu/llama-swap that referenced this pull request Sep 30, 2025
…geek#329)

* proxy/config: create config package and migrate configuration

The configuration is become more complex as llama-swap adds more
advanced features. This commit moves config to its own package so it can
be developed independently of the proxy package.

Additionally, enforcing a public API for a configuration will allow
downstream usage to be more decoupled.
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