forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add dcgm scraper to collect nvidia GPU metrics #160
Merged
movence
merged 17 commits into
amazon-contributing:aws-cwa-dev
from
movence:ci-nvidia-gpu
Mar 1, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0d98f61
add dcgm exporter scraper and move prometheus scraper test mock to mo…
movence 66a683b
update emf exporter to handle GPU metrics with different metric types
movence edc2cee
remove custom logic in emf exporter
movence a6443f1
update gpu flag comment
movence 782f24a
remove comments and test codes
movence 18db72a
remove unused codes and rename scraper init funcs
movence 5d11f3c
remove comments
movence 9ed6770
add changelog for gpu
movence e8af343
add gpu metric consumer that uses k8s decorator for attributes
movence 0b7c895
address comments
movence bc8d269
handle the case with no dp
movence 43ba471
consolidate CI metrics structs into single RawContainerInsights
movence 5a4f394
update feature toggle flag name
movence 3ee43f6
rename k8s attributes vars with Attribute prefix
movence 6a2de95
merge conflicts
movence cc3bf6e
remove unused variable and code for setting metric type to it
movence 852fff7
clean ups
movence 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: 'enhancement' | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: containerinsightsreceiver | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: "Adds DCGM scraper to collect NVIDIA GPU metrics" | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [160] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: Supports NVIDIA GPU metrics by adding a new prometheus data scraper in a k8s environment. The new scraper | | ||
relabels the default DCGM labels into existing Container Insights labels. | ||
|
||
# e.g. '[aws]' | ||
# Include 'aws' if the change is done by cwa | ||
# Default: '[user]' | ||
change_logs: [aws] |
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 |
---|---|---|
|
@@ -166,6 +166,49 @@ func GetUnitForMetric(metric string) string { | |
return metricToUnitMap[metric] | ||
} | ||
|
||
type FieldsAndTagsPair struct { | ||
Fields map[string]any | ||
Tags map[string]string | ||
} | ||
|
||
// ConvertToFieldsAndTags converts OTLP metric to a field containing metric values and a tag containing for decoration | ||
func ConvertToFieldsAndTags(m pmetric.Metric, logger *zap.Logger) []FieldsAndTagsPair { | ||
var converted []FieldsAndTagsPair | ||
if m.Name() == "" { | ||
return converted | ||
} | ||
|
||
var dps pmetric.NumberDataPointSlice | ||
switch m.Type() { | ||
case pmetric.MetricTypeGauge: | ||
dps = m.Gauge().DataPoints() | ||
case pmetric.MetricTypeSum: | ||
dps = m.Sum().DataPoints() | ||
default: | ||
logger.Warn("Unsupported metric type", zap.String("metric", m.Name()), zap.String("type", m.Type().String())) | ||
} | ||
|
||
if dps.Len() == 0 { | ||
logger.Warn("Metric has no datapoint", zap.String("metric", m.Name())) | ||
} | ||
|
||
for i := 0; i < dps.Len(); i++ { | ||
tags := make(map[string]string) | ||
attrs := dps.At(i).Attributes() | ||
attrs.Range(func(k string, v pcommon.Value) bool { | ||
tags[k] = v.AsString() | ||
return true | ||
}) | ||
converted = append(converted, FieldsAndTagsPair{ | ||
Fields: map[string]any{ | ||
m.Name(): nil, // metric value not needed for attribute decoration | ||
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. If we're going to have this limitation (plus only supporting gauge and sum), then I think just move this helper method to the gpu decorator (it's only used from there right now anyway). Having it here in this common place implies that it should work for any OTLP metric. |
||
}, | ||
Tags: tags, | ||
}) | ||
} | ||
return converted | ||
} | ||
|
||
// ConvertToOTLPMetrics converts a field containing metric values and a tag containing the relevant labels to OTLP metrics | ||
func ConvertToOTLPMetrics(fields map[string]any, tags map[string]string, logger *zap.Logger) pmetric.Metrics { | ||
md := pmetric.NewMetrics() | ||
|
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
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
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.
TypeGpuNode, and TypeGpuCluster are nowhere used, do we need this?
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.
You are right that they are not currently being used. The intention is to use them for GPU count metrics.