Code-review pass after D1 shipped, all three model lineages running in parallel against the actual Go source (not docs): Convergent findings (≥2 reviewers — high confidence): - C1 BLOCK · Run() errCh/select race could silently drop fast bind errors. Fixed: net.Listen() now runs synchronously before the goroutine; bind errors surface as Run()'s return value. - C2 BLOCK · scripts/d1_smoke.sh sleep 0.5 races bind on cold boxes. Fixed: replaced with poll_health() loop, 5s/svc budget, 50ms poll. - C3 WARN · LoadConfig silent fallback when file missing. Fixed: emits slog.Warn with path + hint when path given but file absent. Single-reviewer fixes: - S1 WARN · slog.SetDefault inside Run() mutated global state from a library function. Fixed: Run() no longer calls SetDefault. - S2 WARN · os.IsNotExist → errors.Is(err, fs.ErrNotExist) idiom. - S6 WARN · smoke double-curl collapsed to single curl -i parse. Second-pass Opus review on post-fix code caught one more: - head -1 on curl -i fragile against 1xx interim lines. Fixed: awk picks the last HTTP/* status line (robust to 100 Continue). Accepted with rationale (deferred or planned): - S3 secrets-in-lakehouse.toml: D2.3 SecretsProvider already planned - S4 5x cmd/*/main.go duplication: defer until D2 reveals real per-service config consumption - S5 /health log volume: defer post-G0, not on k8s yet - 2nd-pass theoreticals: clean-exit-no-Shutdown path doesn't trigger, defensive defer ln.Close() aspirational, etc. Verification: - go build ./cmd/... exit 0 - go vet ./... clean - ./scripts/d1_smoke.sh D1 acceptance gate: PASSED - 3-lineage code review · 14 findings · 7 fixed · 0 deferred · 5 accepted with rationale Total D1 review coverage across the phase: - 3 doc-review passes (Opus + Kimi + Qwen) — 13 findings, 10 fixed - 1 runtime smoke — 1 finding (port 3100 collision), fixed - 1 code-review parallel pass — 14 findings, 7 fixed - 1 code-review second pass (Opus) — 1 actionable, fixed - Cumulative: 29 findings · 19 fixed inline · 5 accepted · 5 deferred Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
102 lines
3.2 KiB
Go
102 lines
3.2 KiB
Go
// Package shared also provides the TOML config loader. Per ADR
|
|
// equivalent of Rust ADR-006 (TOML config over env vars), every
|
|
// service reads `lakehouse.toml` with sane defaults and env
|
|
// overrides. Config is hot-reload-unaware in G0; reload-on-SIGHUP
|
|
// is a G1+ concern.
|
|
package shared
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io/fs"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
// Config is the unified Lakehouse config. Each service reads only
|
|
// the section it cares about, but they all share the same file so
|
|
// operators have one place to look.
|
|
type Config struct {
|
|
Gateway ServiceConfig `toml:"gateway"`
|
|
Storaged ServiceConfig `toml:"storaged"`
|
|
Catalogd ServiceConfig `toml:"catalogd"`
|
|
Ingestd ServiceConfig `toml:"ingestd"`
|
|
Queryd ServiceConfig `toml:"queryd"`
|
|
S3 S3Config `toml:"s3"`
|
|
Log LogConfig `toml:"log"`
|
|
}
|
|
|
|
// ServiceConfig is the per-binary bind config. Default Bind ""
|
|
// means "use the service's hardcoded G0 default" — see DefaultConfig.
|
|
type ServiceConfig struct {
|
|
Bind string `toml:"bind"`
|
|
}
|
|
|
|
// S3Config holds S3-compatible storage settings. Endpoint blank →
|
|
// AWS default. Bucket "" → "lakehouse-primary".
|
|
type S3Config struct {
|
|
Endpoint string `toml:"endpoint"`
|
|
Region string `toml:"region"`
|
|
Bucket string `toml:"bucket"`
|
|
AccessKeyID string `toml:"access_key_id"`
|
|
SecretAccessKey string `toml:"secret_access_key"`
|
|
UsePathStyle bool `toml:"use_path_style"`
|
|
}
|
|
|
|
// LogConfig — slog level for now; structured fields land G1+.
|
|
type LogConfig struct {
|
|
Level string `toml:"level"`
|
|
}
|
|
|
|
// DefaultConfig returns the G0 dev defaults. Ports are shifted to
|
|
// 3110+ to coexist with the live Rust lakehouse on 3100/3201-3204
|
|
// during the migration. G5 cutover flips gateway back to 3100.
|
|
func DefaultConfig() Config {
|
|
return Config{
|
|
Gateway: ServiceConfig{Bind: "127.0.0.1:3110"},
|
|
Storaged: ServiceConfig{Bind: "127.0.0.1:3211"},
|
|
Catalogd: ServiceConfig{Bind: "127.0.0.1:3212"},
|
|
Ingestd: ServiceConfig{Bind: "127.0.0.1:3213"},
|
|
Queryd: ServiceConfig{Bind: "127.0.0.1:3214"},
|
|
S3: S3Config{
|
|
Endpoint: "http://localhost:9000",
|
|
Region: "us-east-1",
|
|
Bucket: "lakehouse-primary",
|
|
UsePathStyle: true,
|
|
},
|
|
Log: LogConfig{Level: "info"},
|
|
}
|
|
}
|
|
|
|
// LoadConfig reads `lakehouse.toml` from path; if path is empty or
|
|
// the file doesn't exist, returns DefaultConfig. Any decode error is
|
|
// fatal (we don't want a misconfigured service silently falling back
|
|
// to defaults — that's the kind of bug you find at 2am).
|
|
//
|
|
// Per Opus + Qwen WARN #3: when path WAS given but the file is
|
|
// missing, log a warning so silent default-fallback doesn't hide
|
|
// misconfiguration. Empty path is fine (caller didn't ask for a
|
|
// file); non-empty + missing is suspicious.
|
|
func LoadConfig(path string) (Config, error) {
|
|
cfg := DefaultConfig()
|
|
if path == "" {
|
|
return cfg, nil
|
|
}
|
|
b, err := os.ReadFile(path)
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
slog.Warn("config file not found, using defaults",
|
|
"path", path,
|
|
"hint", "create the file or pass -config /path/to/lakehouse.toml")
|
|
return cfg, nil
|
|
}
|
|
if err != nil {
|
|
return cfg, fmt.Errorf("read config: %w", err)
|
|
}
|
|
if err := toml.Unmarshal(b, &cfg); err != nil {
|
|
return cfg, fmt.Errorf("parse config: %w", err)
|
|
}
|
|
return cfg, nil
|
|
}
|