Skip to content

Commit

Permalink
Add InstanceType to GPU metrics (open-telemetry#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
movence authored Mar 14, 2024
1 parent a7e0c68 commit 34bd73a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type DcgmScraperOpts struct {
type hostInfoProvider interface {
GetClusterName() string
GetInstanceID() string
GetInstanceType() string
}

func NewDcgmScraper(opts DcgmScraperOpts) (*DcgmScraper, error) {
Expand Down Expand Up @@ -170,6 +171,13 @@ func getMetricRelabelConfig(hostInfoProvider hostInfoProvider) []*relabel.Config
Replacement: hostInfoProvider.GetInstanceID(),
Action: relabel.Replace,
},
{
SourceLabels: model.LabelNames{"namespace"},
TargetLabel: ci.InstanceType,
Regex: relabel.MustNewRegexp(".*"),
Replacement: hostInfoProvider.GetInstanceType(),
Action: relabel.Replace,
},
{
SourceLabels: model.LabelNames{"pod"},
TargetLabel: ci.AttributeFullPodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ DCGM_FI_DEV_GPU_UTIL{gpu="0",UUID="uuid",device="nvidia0",modelName="NVIDIA A10G
`

const (
dummyInstanceID = "i-0000000000"
dummyClusterName = "cluster-name"
dummyInstanceID = "i-0000000000"
dummyClusterName = "cluster-name"
dummyInstanceType = "instance-type"
)

type mockHostInfoProvider struct {
Expand All @@ -50,6 +51,10 @@ func (m mockHostInfoProvider) GetInstanceID() string {
return dummyInstanceID
}

func (m mockHostInfoProvider) GetInstanceType() string {
return dummyInstanceType
}

type mockDecorator struct {
}

Expand Down Expand Up @@ -151,6 +156,7 @@ func TestNewDcgmScraperEndToEnd(t *testing.T) {
ci.AttributeK8sNamespace: "kube-system",
ci.ClusterNameKey: dummyClusterName,
ci.InstanceID: dummyInstanceID,
ci.InstanceType: dummyInstanceType,
ci.AttributeFullPodName: "fullname-hash",
ci.AttributeK8sPodName: "fullname-hash",
ci.AttributeContainerName: "main",
Expand All @@ -164,6 +170,7 @@ func TestNewDcgmScraperEndToEnd(t *testing.T) {
ci.AttributeK8sNamespace: "kube-system",
ci.ClusterNameKey: dummyClusterName,
ci.InstanceID: dummyInstanceID,
ci.InstanceType: dummyInstanceType,
ci.AttributeFullPodName: "fullname-hash",
ci.AttributeK8sPodName: "fullname-hash",
ci.AttributeContainerName: "main",
Expand Down

0 comments on commit 34bd73a

Please sign in to comment.