-
Notifications
You must be signed in to change notification settings - Fork 765
[GFD] Prevent GFD from crashing when device is unhealthy #1510
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
Closed
Closed
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,9 @@ | |||||
|
|
||||||
| package lm | ||||||
|
|
||||||
| import "fmt" | ||||||
| import ( | ||||||
| "k8s.io/klog/v2" | ||||||
| ) | ||||||
|
|
||||||
| // list represents a list of labelers that iself implements the Labeler interface. | ||||||
| type list []Labeler | ||||||
|
|
@@ -29,13 +31,17 @@ func Merge(labelers ...Labeler) Labeler { | |||||
| } | ||||||
|
|
||||||
| // Labels returns the labels from a set of labelers. Labels later in the list | ||||||
| // overwrite earlier labels. | ||||||
| // overwrite earlier labels. If a labeler fails, the error is logged as a | ||||||
| // warning and the labeler is skipped, allowing the pipeline to continue with | ||||||
| // partial results. This provides fault tolerance for unhealthy devices or | ||||||
| // transient errors without crashing the entire labeling process. | ||||||
| func (labelers list) Labels() (Labels, error) { | ||||||
| allLabels := make(Labels) | ||||||
| for _, labeler := range labelers { | ||||||
| for i, labeler := range labelers { | ||||||
| labels, err := labeler.Labels() | ||||||
| if err != nil { | ||||||
| return nil, fmt.Errorf("error generating labels: %v", err) | ||||||
| klog.Warningf("Labeler at index %d failed, skipping: %v", i, err) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, does it make sense to use:
Suggested change
insread? |
||||||
| continue | ||||||
| } | ||||||
| for k, v := range labels { | ||||||
| allLabels[k] = v | ||||||
|
|
||||||
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,141 @@ | ||
| /** | ||
| # 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 lm | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // mockLabeler is a test double for the Labeler interface | ||
| type mockLabeler struct { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Why not use |
||
| labels Labels | ||
| err error | ||
| } | ||
|
|
||
| func (m *mockLabeler) Labels() (Labels, error) { | ||
| return m.labels, m.err | ||
| } | ||
|
|
||
| func TestMerge(t *testing.T) { | ||
| testCases := []struct { | ||
| description string | ||
| labelers []Labeler | ||
| expectedLabels Labels | ||
| }{ | ||
| { | ||
| description: "empty list returns empty labels", | ||
| labelers: []Labeler{}, | ||
| expectedLabels: Labels{}, | ||
| }, | ||
| { | ||
| description: "single successful labeler", | ||
| labelers: []Labeler{ | ||
| &mockLabeler{ | ||
| labels: Labels{"key1": "value1"}, | ||
| }, | ||
| }, | ||
| expectedLabels: Labels{"key1": "value1"}, | ||
| }, | ||
| { | ||
| description: "multiple successful labelers", | ||
| labelers: []Labeler{ | ||
| &mockLabeler{labels: Labels{"key1": "value1"}}, | ||
| &mockLabeler{labels: Labels{"key2": "value2"}}, | ||
| &mockLabeler{labels: Labels{"key3": "value3"}}, | ||
| }, | ||
| expectedLabels: Labels{ | ||
| "key1": "value1", | ||
| "key2": "value2", | ||
| "key3": "value3", | ||
| }, | ||
| }, | ||
| { | ||
| description: "single failing labeler is skipped", | ||
| labelers: []Labeler{ | ||
| &mockLabeler{labels: Labels{"key1": "value1"}}, | ||
| &mockLabeler{err: fmt.Errorf("device unhealthy: GPU is lost")}, | ||
| &mockLabeler{labels: Labels{"key3": "value3"}}, | ||
| }, | ||
| expectedLabels: Labels{ | ||
| "key1": "value1", | ||
| "key3": "value3", | ||
| }, | ||
| }, | ||
| { | ||
| description: "multiple failing labelers are skipped", | ||
| labelers: []Labeler{ | ||
| &mockLabeler{labels: Labels{"key1": "value1"}}, | ||
| &mockLabeler{err: fmt.Errorf("error 1")}, | ||
| &mockLabeler{err: fmt.Errorf("error 2")}, | ||
| &mockLabeler{labels: Labels{"key4": "value4"}}, | ||
| }, | ||
| expectedLabels: Labels{ | ||
| "key1": "value1", | ||
| "key4": "value4", | ||
| }, | ||
| }, | ||
| { | ||
| description: "all failing labelers returns empty labels", | ||
| labelers: []Labeler{ | ||
| &mockLabeler{err: fmt.Errorf("error 1")}, | ||
| &mockLabeler{err: fmt.Errorf("error 2")}, | ||
| }, | ||
| expectedLabels: Labels{}, | ||
| }, | ||
| { | ||
| description: "later labeler overwrites earlier labels", | ||
| labelers: []Labeler{ | ||
| &mockLabeler{labels: Labels{"key": "value1"}}, | ||
| &mockLabeler{labels: Labels{"key": "value2"}}, | ||
| }, | ||
| expectedLabels: Labels{"key": "value2"}, | ||
| }, | ||
| { | ||
| description: "empty labels from labeler are merged", | ||
| labelers: []Labeler{ | ||
| &mockLabeler{labels: Labels{}}, | ||
| &mockLabeler{labels: Labels{"key": "value"}}, | ||
| }, | ||
| expectedLabels: Labels{"key": "value"}, | ||
| }, | ||
| { | ||
| description: "failing labeler between successful ones", | ||
| labelers: []Labeler{ | ||
| &mockLabeler{labels: Labels{"before": "value"}}, | ||
| &mockLabeler{err: fmt.Errorf("GPU XID error")}, | ||
| &mockLabeler{labels: Labels{"after": "value"}}, | ||
| }, | ||
| expectedLabels: Labels{ | ||
| "before": "value", | ||
| "after": "value", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.description, func(t *testing.T) { | ||
| merged := Merge(tc.labelers...) | ||
| labels, err := merged.Labels() | ||
|
|
||
| require.NoError(t, err, "Merge should never return error") | ||
| require.EqualValues(t, tc.expectedLabels, labels) | ||
| }) | ||
| } | ||
| } | ||
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.
Just a nit: is the index useful in this case? Should we add a
Name()orString()function to the labeler?