Skip to content

Commit

Permalink
Add container_id to metric tags
Browse files Browse the repository at this point in the history
  • Loading branch information
gjulianm committed Oct 9, 2024
1 parent 916bf78 commit 192cb2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/collector/corechecks/gpu/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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,
Expand All @@ -112,6 +112,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
Expand Down Expand Up @@ -160,13 +161,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
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/collector/corechecks/gpu/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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
Expand Down Expand Up @@ -129,6 +132,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),
}
}

Expand Down

0 comments on commit 192cb2d

Please sign in to comment.