-
Notifications
You must be signed in to change notification settings - Fork 756
Add advanced health check configuration to config file #1360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ArangoGutierrez
wants to merge
1
commit into
NVIDIA:main
Choose a base branch
from
ArangoGutierrez:health_status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,229 @@ | ||||||||||
| /* | ||||||||||
| * Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||||||||||
| * | ||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||
| * You may obtain a copy of the License at | ||||||||||
| * | ||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| * | ||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| * See the License for the specific language governing permissions and | ||||||||||
| * limitations under the License. | ||||||||||
| */ | ||||||||||
|
|
||||||||||
| package v1 | ||||||||||
|
|
||||||||||
| import ( | ||||||||||
| "encoding/json" | ||||||||||
| "fmt" | ||||||||||
| "strings" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| // Health defines the configuration for device health checks | ||||||||||
| type Health struct { | ||||||||||
| // Disabled indicates whether health checks are disabled entirely | ||||||||||
| Disabled bool `json:"disabled,omitempty" yaml:"disabled,omitempty"` | ||||||||||
| // EventTypes specifies which NVML event types to monitor | ||||||||||
| EventTypes []string `json:"eventTypes,omitempty" yaml:"eventTypes,omitempty"` | ||||||||||
| // IgnoredXIDs lists XIDs that should be ignored (non-fatal) | ||||||||||
| IgnoredXIDs []uint64 `json:"ignoredXIDs,omitempty" yaml:"ignoredXIDs,omitempty"` | ||||||||||
| // CriticalXIDs specifies which XIDs are considered critical | ||||||||||
| // Can be "all" or a list of specific XIDs | ||||||||||
| CriticalXIDs *CriticalXIDsType `json:"criticalXIDs,omitempty" yaml:"criticalXIDs,omitempty"` | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // CriticalXIDsType represents either "all" XIDs or a specific list | ||||||||||
| type CriticalXIDsType struct { | ||||||||||
| // All indicates if all XIDs should be considered critical | ||||||||||
| All bool | ||||||||||
| // XIDs contains specific XIDs to treat as critical | ||||||||||
| XIDs []uint64 | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // UnmarshalJSON implements custom JSON unmarshaling for CriticalXIDsType | ||||||||||
| func (c *CriticalXIDsType) UnmarshalJSON(data []byte) error { | ||||||||||
| // Try to unmarshal as string first | ||||||||||
| var str string | ||||||||||
| if err := json.Unmarshal(data, &str); err == nil { | ||||||||||
| if strings.ToLower(str) == "all" { | ||||||||||
| c.All = true | ||||||||||
| c.XIDs = nil | ||||||||||
| return nil | ||||||||||
| } | ||||||||||
| return fmt.Errorf("invalid string value for criticalXIDs: %s", str) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Try to unmarshal as array of numbers | ||||||||||
| var xids []uint64 | ||||||||||
| if err := json.Unmarshal(data, &xids); err == nil { | ||||||||||
| c.All = false | ||||||||||
| c.XIDs = xids | ||||||||||
| return nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return fmt.Errorf("criticalXIDs must be either \"all\" or an array of numbers") | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // MarshalJSON implements custom JSON marshaling for CriticalXIDsType | ||||||||||
| func (c CriticalXIDsType) MarshalJSON() ([]byte, error) { | ||||||||||
| if c.All { | ||||||||||
| return json.Marshal("all") | ||||||||||
| } | ||||||||||
| return json.Marshal(c.XIDs) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // UnmarshalYAML implements custom YAML unmarshaling for CriticalXIDsType | ||||||||||
| func (c *CriticalXIDsType) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||||||||||
| // Try to unmarshal as string first | ||||||||||
| var str string | ||||||||||
| if err := unmarshal(&str); err == nil { | ||||||||||
| if strings.ToLower(str) == "all" { | ||||||||||
| c.All = true | ||||||||||
| c.XIDs = nil | ||||||||||
| return nil | ||||||||||
| } | ||||||||||
| return fmt.Errorf("invalid string value for criticalXIDs: %s", str) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Try to unmarshal as array of numbers | ||||||||||
| var xids []uint64 | ||||||||||
| if err := unmarshal(&xids); err == nil { | ||||||||||
| c.All = false | ||||||||||
| c.XIDs = xids | ||||||||||
| return nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return fmt.Errorf("criticalXIDs must be either \"all\" or an array of numbers") | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // MarshalYAML implements custom YAML marshaling for CriticalXIDsType | ||||||||||
| func (c CriticalXIDsType) MarshalYAML() (interface{}, error) { | ||||||||||
| if c.All { | ||||||||||
| return "all", nil | ||||||||||
| } | ||||||||||
| return c.XIDs, nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // DefaultHealth returns the default health configuration for standard deployments | ||||||||||
| func DefaultHealth() *Health { | ||||||||||
| return &Health{ | ||||||||||
| Disabled: false, | ||||||||||
| EventTypes: []string{ | ||||||||||
| "EventTypeXidCriticalError", | ||||||||||
| "EventTypeDoubleBitEccError", | ||||||||||
| "EventTypeSingleBitEccError", | ||||||||||
| }, | ||||||||||
| IgnoredXIDs: []uint64{ | ||||||||||
| 13, // Graphics Engine Exception | ||||||||||
| 31, // GPU memory page fault | ||||||||||
| 43, // GPU stopped processing | ||||||||||
| 45, // Preemptive cleanup, due to previous errors | ||||||||||
| 68, // Video processor exception | ||||||||||
| 109, // Context Switch Timeout Error | ||||||||||
| }, | ||||||||||
| CriticalXIDs: &CriticalXIDsType{ | ||||||||||
| All: true, | ||||||||||
| }, | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // IsCritical checks if a given XID should be treated as critical | ||||||||||
| func (h *Health) IsCritical(xid uint64) bool { | ||||||||||
| // If health checks are disabled, nothing is critical | ||||||||||
| if h.Disabled { | ||||||||||
| return false | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Check if XID is in ignored list | ||||||||||
| for _, ignoredXID := range h.IgnoredXIDs { | ||||||||||
| if xid == ignoredXID { | ||||||||||
| return false | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // If no critical XIDs specified, default to all | ||||||||||
| if h.CriticalXIDs == nil { | ||||||||||
| return true | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // If all XIDs are critical (except ignored ones) | ||||||||||
| if h.CriticalXIDs.All { | ||||||||||
| return true | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Check if XID is in critical list | ||||||||||
| for _, criticalXID := range h.CriticalXIDs.XIDs { | ||||||||||
| if xid == criticalXID { | ||||||||||
| return true | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return false | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Validate checks if the health configuration is valid | ||||||||||
| func (h *Health) Validate() error { | ||||||||||
| if h == nil { | ||||||||||
| return nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Validate event types | ||||||||||
| validEventTypes := map[string]bool{ | ||||||||||
| "EventTypeXidCriticalError": true, | ||||||||||
| "EventTypeDoubleBitEccError": true, | ||||||||||
| "EventTypeSingleBitEccError": true, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| for _, eventType := range h.EventTypes { | ||||||||||
| if !validEventTypes[eventType] { | ||||||||||
| return fmt.Errorf("invalid event type: %s", eventType) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Check for XID conflicts | ||||||||||
| if h.CriticalXIDs != nil && !h.CriticalXIDs.All && len(h.CriticalXIDs.XIDs) > 0 { | ||||||||||
| ignoredMap := make(map[uint64]bool) | ||||||||||
| for _, xid := range h.IgnoredXIDs { | ||||||||||
| ignoredMap[xid] = true | ||||||||||
| } | ||||||||||
|
|
||||||||||
| for _, xid := range h.CriticalXIDs.XIDs { | ||||||||||
| if ignoredMap[xid] { | ||||||||||
| return fmt.Errorf("XID %d is in both ignored and critical lists", xid) | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Merge applies values from another Health config, overriding the current values with | ||||||||||
| // values from 'other'. This includes the Disabled field - if 'other' explicitly sets | ||||||||||
| // Disabled to false, it will enable health checks even if they were previously disabled. | ||||||||||
| // This is intentional behavior for configuration merging where 'other' represents a | ||||||||||
| // higher-priority configuration source. | ||||||||||
| // | ||||||||||
| // For fields that are slices (EventTypes, IgnoredXIDs) or pointers (CriticalXIDs), | ||||||||||
| // only non-empty/non-nil values from 'other' will override the current values. | ||||||||||
| func (h *Health) Merge(other *Health) { | ||||||||||
| if other == nil { | ||||||||||
| return | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
||||||||||
| // Intentionally override Disabled unconditionally, even if other.Disabled is false. | |
| // See method documentation above for rationale. |
ArangoGutierrez marked this conversation as resolved.
Show resolved
Hide resolved
ArangoGutierrez marked this conversation as resolved.
Show resolved
Hide resolved
ArangoGutierrez marked this conversation as resolved.
Show resolved
Hide resolved
ArangoGutierrez marked this conversation as resolved.
Show resolved
Hide resolved
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ArangoGutierrez rn, we only look at XID and ECC errors should we also consider GPU power and temp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good discussion, but out of scope for this PR