Skip to content

Commit d7e7aaa

Browse files
committed
Use config
1 parent 8e19d45 commit d7e7aaa

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

cmd/api/api/api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
// newTestService creates an ApiService for testing with automatic cleanup
2626
func newTestService(t *testing.T) *ApiService {
2727
cfg := &config.Config{
28-
DataDir: t.TempDir(),
29-
BridgeName: "vmbr0",
30-
SubnetCIDR: "10.100.0.0/16",
31-
DNSServer: "1.1.1.1",
28+
DataDir: t.TempDir(),
29+
BridgeName: "vmbr0",
30+
SubnetCIDR: "10.100.0.0/16",
31+
DNSServer: "1.1.1.1",
3232
}
3333

3434
p := paths.New(cfg.DataDir)

cmd/api/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ func Load() *Config {
201201
CloudflareApiToken: getEnv("CLOUDFLARE_API_TOKEN", ""),
202202

203203
// API ingress configuration
204-
ApiHostname: getEnv("API_HOSTNAME", ""), // Empty = disabled
205-
ApiTLS: getEnvBool("API_TLS", true), // Default to TLS enabled
204+
ApiHostname: getEnv("API_HOSTNAME", ""), // Empty = disabled
205+
ApiTLS: getEnvBool("API_TLS", true), // Default to TLS enabled
206206
ApiRedirectHTTP: getEnvBool("API_REDIRECT_HTTP", true),
207207

208208
// Build system configuration

cmd/api/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/ghodss/yaml"
1919
"github.com/go-chi/chi/v5"
2020
"github.com/go-chi/chi/v5/middleware"
21-
nethttpmiddleware "github.com/oapi-codegen/nethttp-middleware"
2221
"github.com/kernel/hypeman"
2322
"github.com/kernel/hypeman/cmd/api/api"
2423
"github.com/kernel/hypeman/cmd/api/config"
@@ -30,6 +29,7 @@ import (
3029
"github.com/kernel/hypeman/lib/oapi"
3130
"github.com/kernel/hypeman/lib/otel"
3231
"github.com/kernel/hypeman/lib/vmm"
32+
nethttpmiddleware "github.com/oapi-codegen/nethttp-middleware"
3333
"github.com/riandyrn/otelchi"
3434
"golang.org/x/sync/errgroup"
3535
)
@@ -51,6 +51,9 @@ func run() error {
5151
return fmt.Errorf("invalid configuration: %w", err)
5252
}
5353

54+
// Configure GPU profile cache TTL
55+
devices.SetGPUProfileCacheTTL(cfg.GPUProfileCacheTTL)
56+
5457
// Initialize OpenTelemetry (before wire initialization)
5558
otelCfg := otel.Config{
5659
Enabled: cfg.OtelEnabled,

lib/devices/mdev.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,27 @@ type profileMetadata struct {
3535
}
3636

3737
// cachedProfiles holds profile metadata with TTL-based expiry.
38-
// The cache TTL is configurable via GPU_PROFILE_CACHE_TTL environment variable.
3938
var (
4039
cachedProfiles []profileMetadata
4140
cachedProfilesMu sync.RWMutex
4241
cachedProfilesTime time.Time
42+
gpuProfileCacheTTL time.Duration = 30 * time.Minute // default
4343
)
4444

45-
// getProfileCacheTTL returns the TTL for profile metadata cache.
46-
// Reads from GPU_PROFILE_CACHE_TTL env var, defaults to 30 minutes.
47-
func getProfileCacheTTL() time.Duration {
48-
if ttl := os.Getenv("GPU_PROFILE_CACHE_TTL"); ttl != "" {
49-
if d, err := time.ParseDuration(ttl); err == nil {
50-
return d
51-
}
45+
// SetGPUProfileCacheTTL sets the TTL for GPU profile metadata cache.
46+
// Should be called during application startup with the config value.
47+
func SetGPUProfileCacheTTL(ttl string) {
48+
if ttl == "" {
49+
return
50+
}
51+
if d, err := time.ParseDuration(ttl); err == nil {
52+
gpuProfileCacheTTL = d
5253
}
53-
return 30 * time.Minute
54+
}
55+
56+
// getProfileCacheTTL returns the configured TTL for profile metadata cache.
57+
func getProfileCacheTTL() time.Duration {
58+
return gpuProfileCacheTTL
5459
}
5560

5661
// getCachedProfiles returns cached profile metadata, refreshing if TTL has expired.

0 commit comments

Comments
 (0)