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 Sep 30, 2024
1 parent 2d129c1 commit 78c1d24
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 @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
}
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 @@ -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
Expand Down Expand Up @@ -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),
}
}

Expand Down

0 comments on commit 78c1d24

Please sign in to comment.