Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions internal/backendclient/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ type NodeResources struct {
}

type AgentConfig struct {
TotalComponents int64 `json:"totalComponents"`
RetentionPeriodSeconds int64 `json:"retentionPeriodSeconds"`
EnabledComponents []string `json:"enabledComponents"`
DisabledComponents []string `json:"disabledComponents"`
InventoryEnabled bool `json:"inventoryEnabled"`
InventoryIntervalSeconds int64 `json:"inventoryIntervalSeconds"`
AttestationEnabled bool `json:"attestationEnabled"`
AttestationIntervalSeconds int64 `json:"attestationIntervalSeconds"`
TotalComponents int64 `json:"totalComponents"`
RetentionPeriodSeconds int64 `json:"retentionPeriodSeconds"`
MetricScrapeIntervalSeconds int64 `json:"metricScrapeIntervalSeconds"`
Comment thread
jingxiang-z marked this conversation as resolved.
EnabledComponents []string `json:"enabledComponents"`
DisabledComponents []string `json:"disabledComponents"`
InventoryEnabled bool `json:"inventoryEnabled"`
InventoryIntervalSeconds int64 `json:"inventoryIntervalSeconds"`
AttestationEnabled bool `json:"attestationEnabled"`
AttestationIntervalSeconds int64 `json:"attestationIntervalSeconds"`
}

type CPUInfo struct {
Expand Down
13 changes: 13 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ func (config *Config) AttestationLoopAgentConfig() (enabled bool, intervalSecond
return config.Attestation.Enabled, int64(config.Attestation.Interval.Seconds())
}

// HealthCheckInterval returns the resolved component health-check interval.
func (config *Config) HealthCheckInterval() time.Duration {
if config == nil || config.HealthExporter == nil || config.HealthExporter.HealthCheckInterval.Duration <= 0 {
return time.Minute
}
return config.HealthExporter.HealthCheckInterval.Duration
}

// MetricScrapeIntervalSeconds returns the resolved metric scrape interval stored in inventory.
func (config *Config) MetricScrapeIntervalSeconds() int64 {
return int64(config.HealthCheckInterval().Seconds())
}

// getComponentLists computes enabled/disabled lists from config rules against all available components.
func (config *Config) getComponentLists(allComponentNames []string) (enabled, disabled []string) {
enabled, disabled = []string{}, []string{}
Expand Down
8 changes: 8 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,9 @@ func TestInventoryAgentConfig(t *testing.T) {
APIVersion: "v1",
RetentionPeriod: metav1.Duration{Duration: 24 * time.Hour},
Components: []string{"*", "-memory", "-disk"},
HealthExporter: &HealthExporterConfig{
HealthCheckInterval: metav1.Duration{Duration: 30 * time.Second},
},
Inventory: &InventoryConfig{
Enabled: true,
Interval: metav1.Duration{Duration: time.Hour},
Expand All @@ -903,4 +906,9 @@ func TestInventoryAgentConfig(t *testing.T) {
attestationEnabled, attestationIntervalSeconds := cfg.AttestationLoopAgentConfig()
assert.True(t, attestationEnabled)
assert.Equal(t, int64(86400), attestationIntervalSeconds)

assert.Equal(t, 30*time.Second, cfg.HealthCheckInterval())
assert.Equal(t, int64(30), cfg.MetricScrapeIntervalSeconds())
assert.Equal(t, time.Minute, (*Config)(nil).HealthCheckInterval())
assert.Equal(t, int64(60), (*Config)(nil).MetricScrapeIntervalSeconds())
}
17 changes: 9 additions & 8 deletions internal/enrollment/enrollment.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ func syncInventoryOnce(ctx context.Context, cfg *config.Config) error {
return machineinfo.GetMachineInfo(nvmlInstance)
}),
&inventory.AgentConfig{
TotalComponents: int64(len(allComponents)),
RetentionPeriodSeconds: retentionPeriodSeconds,
EnabledComponents: enabledComponents,
DisabledComponents: disabledComponents,
InventoryEnabled: inventoryEnabled,
InventoryIntervalSeconds: inventoryIntervalSeconds,
AttestationEnabled: attestationEnabled,
AttestationIntervalSeconds: attestationIntervalSeconds,
TotalComponents: int64(len(allComponents)),
RetentionPeriodSeconds: retentionPeriodSeconds,
MetricScrapeIntervalSeconds: cfg.MetricScrapeIntervalSeconds(),
EnabledComponents: enabledComponents,
DisabledComponents: disabledComponents,
InventoryEnabled: inventoryEnabled,
InventoryIntervalSeconds: inventoryIntervalSeconds,
AttestationEnabled: attestationEnabled,
AttestationIntervalSeconds: attestationIntervalSeconds,
},
)
manager := inventory.NewManager(src, sink, inventory.InventoryConfig{})
Expand Down
17 changes: 9 additions & 8 deletions internal/inventory/mapper/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ func ToNodeUpsertRequest(s *inventory.Snapshot) *backendclient.NodeUpsertRequest
return &backendclient.NodeUpsertRequest{
Hostname: s.Hostname,
AgentConfig: backendclient.AgentConfig{
TotalComponents: s.AgentConfig.TotalComponents,
RetentionPeriodSeconds: s.AgentConfig.RetentionPeriodSeconds,
EnabledComponents: cloneStringSlice(s.AgentConfig.EnabledComponents),
DisabledComponents: cloneStringSlice(s.AgentConfig.DisabledComponents),
InventoryEnabled: s.AgentConfig.InventoryEnabled,
InventoryIntervalSeconds: s.AgentConfig.InventoryIntervalSeconds,
AttestationEnabled: s.AgentConfig.AttestationEnabled,
AttestationIntervalSeconds: s.AgentConfig.AttestationIntervalSeconds,
TotalComponents: s.AgentConfig.TotalComponents,
RetentionPeriodSeconds: s.AgentConfig.RetentionPeriodSeconds,
MetricScrapeIntervalSeconds: s.AgentConfig.MetricScrapeIntervalSeconds,
EnabledComponents: cloneStringSlice(s.AgentConfig.EnabledComponents),
DisabledComponents: cloneStringSlice(s.AgentConfig.DisabledComponents),
InventoryEnabled: s.AgentConfig.InventoryEnabled,
InventoryIntervalSeconds: s.AgentConfig.InventoryIntervalSeconds,
AttestationEnabled: s.AgentConfig.AttestationEnabled,
AttestationIntervalSeconds: s.AgentConfig.AttestationIntervalSeconds,
},
MachineID: s.MachineID,
SystemUUID: s.SystemUUID,
Expand Down
19 changes: 11 additions & 8 deletions internal/inventory/mapper/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestToNodeUpsertRequestAgentConfigJSONIncludesZeroValues(t *testing.T) {
require.JSONEq(t, `{
"totalComponents": 0,
"retentionPeriodSeconds": 0,
"metricScrapeIntervalSeconds": 0,
"enabledComponents": [],
"disabledComponents": [],
"inventoryEnabled": false,
Expand Down Expand Up @@ -65,14 +66,15 @@ func TestToNodeUpsertRequest(t *testing.T) {
ContainerRuntimeVersion: "containerd://1.7.13",
NetPrivateIP: "10.0.0.10",
AgentConfig: inventory.AgentConfig{
TotalComponents: 30,
RetentionPeriodSeconds: 86400,
EnabledComponents: []string{"cpu", "gpu"},
DisabledComponents: []string{"disk"},
InventoryEnabled: true,
InventoryIntervalSeconds: 3600,
AttestationEnabled: true,
AttestationIntervalSeconds: 86400,
TotalComponents: 30,
RetentionPeriodSeconds: 86400,
MetricScrapeIntervalSeconds: 60,
EnabledComponents: []string{"cpu", "gpu"},
DisabledComponents: []string{"disk"},
InventoryEnabled: true,
InventoryIntervalSeconds: 3600,
AttestationEnabled: true,
AttestationIntervalSeconds: 86400,
},
Resources: inventory.Resources{
CPUInfo: inventory.CPUInfo{
Expand Down Expand Up @@ -130,6 +132,7 @@ func TestToNodeUpsertRequest(t *testing.T) {
require.Equal(t, bootTime.UTC(), *req.Uptime)
require.Equal(t, int64(30), req.AgentConfig.TotalComponents)
require.Equal(t, int64(86400), req.AgentConfig.RetentionPeriodSeconds)
require.Equal(t, int64(60), req.AgentConfig.MetricScrapeIntervalSeconds)
require.Equal(t, []string{"cpu", "gpu"}, req.AgentConfig.EnabledComponents)
require.Equal(t, []string{"disk"}, req.AgentConfig.DisabledComponents)
require.True(t, req.AgentConfig.InventoryEnabled)
Expand Down
18 changes: 10 additions & 8 deletions internal/inventory/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,15 @@ func TestMachineInfoSourceCollectWithAgentConfig(t *testing.T) {
},
},
&inventory.AgentConfig{
TotalComponents: 42,
RetentionPeriodSeconds: 86400,
EnabledComponents: []string{"cpu", "gpu"},
DisabledComponents: []string{"disk"},
InventoryEnabled: true,
InventoryIntervalSeconds: 3600,
AttestationEnabled: true,
AttestationIntervalSeconds: 86400,
TotalComponents: 42,
RetentionPeriodSeconds: 86400,
MetricScrapeIntervalSeconds: 60,
EnabledComponents: []string{"cpu", "gpu"},
DisabledComponents: []string{"disk"},
InventoryEnabled: true,
InventoryIntervalSeconds: 3600,
AttestationEnabled: true,
AttestationIntervalSeconds: 86400,
},
)

Expand All @@ -146,6 +147,7 @@ func TestMachineInfoSourceCollectWithAgentConfig(t *testing.T) {
require.Equal(t, "machine-id", snap.MachineID)
require.Equal(t, int64(42), snap.AgentConfig.TotalComponents)
require.Equal(t, int64(86400), snap.AgentConfig.RetentionPeriodSeconds)
require.Equal(t, int64(60), snap.AgentConfig.MetricScrapeIntervalSeconds)
require.Equal(t, []string{"cpu", "gpu"}, snap.AgentConfig.EnabledComponents)
require.Equal(t, []string{"disk"}, snap.AgentConfig.DisabledComponents)
require.True(t, snap.AgentConfig.InventoryEnabled)
Expand Down
17 changes: 9 additions & 8 deletions internal/inventory/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ type Snapshot struct {
}

type AgentConfig struct {
TotalComponents int64
RetentionPeriodSeconds int64
EnabledComponents []string
DisabledComponents []string
InventoryEnabled bool
InventoryIntervalSeconds int64
AttestationEnabled bool
AttestationIntervalSeconds int64
TotalComponents int64
RetentionPeriodSeconds int64
MetricScrapeIntervalSeconds int64
EnabledComponents []string
DisabledComponents []string
InventoryEnabled bool
InventoryIntervalSeconds int64
AttestationEnabled bool
AttestationIntervalSeconds int64
}

type Resources struct {
Expand Down
23 changes: 10 additions & 13 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ func initializeMachineID(ctx context.Context, dbRW, dbRO *sql.DB) (string, error

// getHealthCheckInterval determines the health check interval from config
func getHealthCheckInterval(config *config.Config) time.Duration {
healthCheckInterval := time.Minute // default
if config.HealthExporter != nil && config.HealthExporter.HealthCheckInterval.Duration > 0 {
healthCheckInterval = config.HealthExporter.HealthCheckInterval.Duration
}
return healthCheckInterval
return config.HealthCheckInterval()
}

func getInventorySyncInterval(config *config.Config) time.Duration {
Expand Down Expand Up @@ -474,14 +470,15 @@ func (s *Server) startInventoryLoop(
return machineinfo.GetMachineInfo(nvmlInstance, machineinfo.WithDCGMGPUIndexes(dcgmGPUIndexes))
}),
&inventory.AgentConfig{
TotalComponents: int64(len(allComponents)),
RetentionPeriodSeconds: retentionPeriodSeconds,
EnabledComponents: enabledComponents,
DisabledComponents: disabledComponents,
InventoryEnabled: inventoryEnabled,
InventoryIntervalSeconds: inventoryIntervalSeconds,
AttestationEnabled: attestationEnabled,
AttestationIntervalSeconds: attestationIntervalSeconds,
TotalComponents: int64(len(allComponents)),
RetentionPeriodSeconds: retentionPeriodSeconds,
MetricScrapeIntervalSeconds: cfg.MetricScrapeIntervalSeconds(),
EnabledComponents: enabledComponents,
DisabledComponents: disabledComponents,
InventoryEnabled: inventoryEnabled,
InventoryIntervalSeconds: inventoryIntervalSeconds,
AttestationEnabled: attestationEnabled,
AttestationIntervalSeconds: attestationIntervalSeconds,
},
)
sink := inventorysink.NewBackendSink(agentstate.NewSQLite())
Expand Down
1 change: 1 addition & 0 deletions internal/validation/outbound/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func ValidateNodeUpsertRequest(req *backendclient.NodeUpsertRequest) []Issue {

validateNonNegative(&issues, "numeric", "agentConfig.totalComponents", req.AgentConfig.TotalComponents)
validateNonNegative(&issues, "numeric", "agentConfig.retentionPeriodSeconds", req.AgentConfig.RetentionPeriodSeconds)
validateNonNegative(&issues, "numeric", "agentConfig.metricScrapeIntervalSeconds", req.AgentConfig.MetricScrapeIntervalSeconds)
validateNonNegative(&issues, "numeric", "agentConfig.inventoryIntervalSeconds", req.AgentConfig.InventoryIntervalSeconds)
validateNonNegative(&issues, "numeric", "agentConfig.attestationIntervalSeconds", req.AgentConfig.AttestationIntervalSeconds)

Expand Down
9 changes: 9 additions & 0 deletions internal/validation/outbound/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func TestValidateNodeUpsertRequest(t *testing.T) {
MachineID: "machine-1",
SystemUUID: "not-a-uuid",
Uptime: &now,
AgentConfig: backendclient.AgentConfig{
MetricScrapeIntervalSeconds: -1,
},
Resources: backendclient.NodeResources{
CPUInfo: backendclient.CPUInfo{LogicalCores: "-1"},
MemoryInfo: backendclient.MemoryInfo{
Expand Down Expand Up @@ -64,6 +67,12 @@ func TestValidateNodeUpsertRequest(t *testing.T) {
Field: "hostname",
Message: "field is required",
})
require.Contains(t, issues, Issue{
Severity: SeverityWarning,
Category: "numeric",
Field: "agentConfig.metricScrapeIntervalSeconds",
Message: "value is negative",
})
require.Contains(t, issues, Issue{
Severity: SeverityCritical,
Category: "numeric",
Expand Down
Loading