-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[CONTP-499] Parsing GPU tags on kubeapiserver collector #31465
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
af401ee
Parsing GPU tags on kubeapiserver collector
gabedos 6443d24
GPU parsing unit tests
gabedos e62cff5
Release note
gabedos 2d49ed8
Adding unit tests for kubelet parser
gabedos d13ba55
File metadata updates
gabedos 2c5d869
Merge branch 'main' into gabedos/kubeapiserver-gpu-tagging
gabedos 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 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 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 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 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 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,48 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
gabedos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
// Package gpu provides utilities for interacting with GPU resources. | ||
package gpu | ||
|
||
import "strings" | ||
|
||
// ResourceGPU represents a GPU resource | ||
type ResourceGPU string | ||
|
||
// Resource name prefixes | ||
const ( | ||
gpuNvidiaGeneric ResourceGPU = "nvidia.com/gpu" | ||
gpuAMD ResourceGPU = "amd.com/gpu" | ||
gpuIntelXe ResourceGPU = "gpu.intel.com/xe" | ||
gpuInteli915 ResourceGPU = "gpu.intel.com/i915" | ||
|
||
gpuNvidiaMigPrefix ResourceGPU = "nvidia.com/mig" | ||
) | ||
|
||
// longToShortGPUName maps a GPU resource to a simplified name | ||
var longToShortGPUName = map[ResourceGPU]string{ | ||
gpuNvidiaGeneric: "nvidia", | ||
gpuAMD: "amd", | ||
gpuIntelXe: "intel", | ||
gpuInteli915: "intel", | ||
} | ||
|
||
// ExtractSimpleGPUName returns a simplified GPU name. | ||
// If the resource is not recognized, the second return value is false. | ||
func ExtractSimpleGPUName(gpuName ResourceGPU) (string, bool) { | ||
val, ok := longToShortGPUName[gpuName] | ||
if ok { | ||
return val, true | ||
} | ||
|
||
// More complex cases (eg. nvidia.com/mig-3g.20gb => nvidia) | ||
switch { | ||
case strings.HasPrefix(string(gpuName), string(gpuNvidiaMigPrefix)): | ||
return "nvidia", true | ||
} | ||
|
||
// Not a GPU resource (or not recognized) | ||
return "", false | ||
} |
This file contains 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,41 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
package gpu | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestExtractSimpleGPUName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
gpuName ResourceGPU | ||
found bool | ||
expected string | ||
}{ | ||
{ | ||
name: "known gpu resource", | ||
gpuName: gpuNvidiaGeneric, | ||
found: true, | ||
expected: "nvidia", | ||
}, | ||
{ | ||
name: "unknown gpu resource", | ||
gpuName: ResourceGPU("cpu"), | ||
found: false, | ||
expected: "", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
actual, found := ExtractSimpleGPUName(test.gpuName) | ||
assert.Equal(t, test.found, found) | ||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
releasenotes/notes/kubeapiserver-gpu-tagging-e6202bc782982e5d.yaml
This file contains 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,12 @@ | ||
# Each section from every release note are combined when the | ||
# CHANGELOG.rst is rendered. So the text needs to be worded so that | ||
# it does not depend on any information only available in another | ||
# section. This may mean repeating some details, but each section | ||
# must be readable independently of the other. | ||
# | ||
# Each section note must be formatted as reStructuredText. | ||
--- | ||
fixes: | ||
- | | ||
Include `gpu_vendor` pod tags on the Datadog Cluster Agent when | ||
enabling datadog.clusterTagger.collectKubernetesTags. |
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.
can we wrap this logic in one function to be reused in
comp/core/workloadmeta/collectors/util/kubernetes_resource_parsers/pod.go
?I feel like the code is very similar
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.
I've tried implementing a function such as the following:
However, I get an error stating "cannot range over resourceList: no core type". It seems that Go's type system cannot infer the underlying map structure directly from
T corev1.ResourceList | kubelet.ResourceList
.I've tried directly setting it to
[T ~map[corev1.ResourceName]resource.Quantity | ~map[kubelet.ResourceName]resource.Quantity]
and get the same issue. It's interesting thatcorev1.ResourceName
andkubelet.ResourceName
are both simply strings, so these types are essentially the same. I tried type casting the inputmap[string]resource.Quantity(container.Resources.Requests)
but it doesn't allow me either.I can't think of a lightweight way for wrapping this logic into one function that can be reused. Do you have any ideas? It would be very appreciated. Thanks!