in internal/telemetrygen/logs/logs.go [52:94]
func Run(c *Config, exp exporter, logger *zap.Logger) error {
if c.TotalDuration > 0 {
c.NumLogs = 0
} else if c.NumLogs <= 0 {
return fmt.Errorf("either `logs` or `duration` must be greater than 0")
}
limit := rate.Limit(c.Rate)
if c.Rate == 0 {
limit = rate.Inf
logger.Info("generation of logs isn't being throttled")
} else {
logger.Info("generation of logs is limited", zap.Float64("per-second", float64(limit)))
}
wg := sync.WaitGroup{}
res := resource.NewWithAttributes(semconv.SchemaURL, c.GetAttributes()...)
running := &atomic.Bool{}
running.Store(true)
for i := 0; i < c.WorkerCount; i++ {
wg.Add(1)
w := worker{
numLogs: c.NumLogs,
limitPerSecond: limit,
body: c.Body,
totalDuration: c.TotalDuration,
running: running,
wg: &wg,
logger: logger.With(zap.Int("worker", i)),
index: i,
}
go w.simulateLogs(res, exp, c.GetTelemetryAttributes())
}
if c.TotalDuration > 0 {
time.Sleep(c.TotalDuration)
running.Store(false)
}
wg.Wait()
return nil
}