From 78c1d247cd1cb573e5f33ac77b6ffbf2cb89e9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Julia=CC=81n?= Date: Fri, 27 Sep 2024 07:16:37 -0700 Subject: [PATCH] Add container_id to metric tags --- pkg/collector/corechecks/gpu/gpu.go | 7 ++++--- pkg/collector/corechecks/gpu/stats.go | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/collector/corechecks/gpu/gpu.go b/pkg/collector/corechecks/gpu/gpu.go index 31ab1cf46a0749..8d5d365ef422b9 100644 --- a/pkg/collector/corechecks/gpu/gpu.go +++ b/pkg/collector/corechecks/gpu/gpu.go @@ -110,7 +110,7 @@ func (m *Check) ensureInitialized() error { } // ensureProcessor ensures that there is a stats processor for the given key -func (m *Check) ensureProcessor(key *model.StreamKey, snd sender.Sender, gpuThreads int, checkDuration time.Duration) { +func (m *Check) ensureProcessor(key *model.StreamKey, snd sender.Sender, gpuThreads int, checkDuration time.Duration, metadata *model.StreamMetadata) { if _, ok := m.statProcessors[key.Pid]; !ok { m.statProcessors[key.Pid] = &StatsProcessor{ key: key, @@ -123,6 +123,7 @@ func (m *Check) ensureProcessor(key *model.StreamKey, snd sender.Sender, gpuThre m.statProcessors[key.Pid].measuredInterval = checkDuration m.statProcessors[key.Pid].timeResolver = m.timeResolver m.statProcessors[key.Pid].lastCheck = m.lastCheckTime + m.statProcessors[key.Pid].metadata = metadata } // Run executes the check @@ -167,13 +168,13 @@ func (m *Check) Run() error { usedProcessors := make(map[uint32]bool) for _, data := range stats.CurrentData { - m.ensureProcessor(&data.Key, snd, gpuThreads, checkDuration) + m.ensureProcessor(&data.Key, snd, gpuThreads, checkDuration, &data.Metadata) m.statProcessors[data.Key.Pid].processCurrentData(data) usedProcessors[data.Key.Pid] = true } for _, data := range stats.PastData { - m.ensureProcessor(&data.Key, snd, gpuThreads, checkDuration) + m.ensureProcessor(&data.Key, snd, gpuThreads, checkDuration, &data.Metadata) m.statProcessors[data.Key.Pid].processPastData(data) usedProcessors[data.Key.Pid] = true } diff --git a/pkg/collector/corechecks/gpu/stats.go b/pkg/collector/corechecks/gpu/stats.go index 1a39c08f7bbd29..c1da65bbc43e45 100644 --- a/pkg/collector/corechecks/gpu/stats.go +++ b/pkg/collector/corechecks/gpu/stats.go @@ -65,6 +65,9 @@ type StatsProcessor struct { // utilizationNormFactor is the factor to normalize the utilization by, to account for the fact that we might have more kernels enqueued than the GPU can run in parallel. This factor // allows distributing the utilization over all the streams that are enqueued utilizationNormFactor float64 + + // Metadata associated to this stream + metadata *model.StreamMetadata } // processKernelSpan processes a kernel span @@ -127,6 +130,7 @@ func (sp *StatsProcessor) processCurrentData(data *model.StreamData) { func (sp *StatsProcessor) getTags() []string { return []string{ fmt.Sprintf("pid:%d", sp.key.Pid), + fmt.Sprintf("container_id:%s", sp.metadata.ContainerID), } }