Skip to content

Commit

Permalink
nvidia_mock: Don't send the same data multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
metalmatze committed Jan 21, 2025
1 parent f08979e commit 2798739
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions nvidia_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"log/slog"
"math/rand/v2"
"time"

"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -41,19 +40,25 @@ func (p *MockProducer) Produce(ms pmetric.MetricSlice) error {
now := time.Now()
m.SetName("gpu_utilization_percent")

for i, uuid := range p.deviceUuids {
lastTimeRounded := p.lastTime.Truncate(PERIOD).Add(PERIOD)
lastTimeRounded := p.lastTime.Truncate(PERIOD).Add(PERIOD)

for lastTimeRounded.Before(now) {
dp := g.DataPoints().AppendEmpty()
dp.SetIntValue(int64(rand.IntN(100)))
dp.SetTimestamp(pcommon.NewTimestampFromTime(lastTimeRounded))
lastTimeRounded = lastTimeRounded.Add(PERIOD)
dp.Attributes().PutStr("UUID", uuid)
dp.Attributes().PutInt("index", int64(i))
for lastTimeRounded.Before(now) {
// This will make the value go up and down between 0 and 100 based on the timestamp's seconds.
v := lastTimeRounded.Unix() % 200
if v > 100 {
v = 200 - v
}

dp := g.DataPoints().AppendEmpty()
dp.Attributes().PutStr("UUID", uuid)
dp.Attributes().PutInt("index", int64(i))
dp.SetTimestamp(pcommon.NewTimestampFromTime(lastTimeRounded))
dp.SetIntValue(v)

lastTimeRounded = lastTimeRounded.Add(PERIOD)
}
p.lastTime = now
}

return nil
}

0 comments on commit 2798739

Please sign in to comment.