Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: rate limit and duration #122

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/metrics/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func counter(mp *metric.MeterProvider, c Config, logger *zap.Logger) WorkerFunc
i++
logger.Info("generating", zap.String("name", name))
counter.Add(ctx, i)
time.Sleep(time.Duration(c.Rate) * time.Second)
time.Sleep(time.Duration(float64(time.Second) / float64(c.Rate)))
}
} else {
for {
i++
logger.Info("generating", zap.String("name", name))
counter.Add(ctx, i)
time.Sleep(time.Duration(c.Rate) * time.Second)
time.Sleep(time.Duration(float64(time.Second) / float64(c.Rate)))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/metrics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func histogram(mp *metric.MeterProvider, c Config, logger *zap.Logger) WorkerFun
logger.Info("generating", zap.String("name", name))
dur := time.Duration(rand.NormFloat64()*5000000) * time.Microsecond
durRecorder.Record(ctx, dur.Microseconds())
time.Sleep(time.Duration(c.Rate) * time.Second)
time.Sleep(time.Duration(float64(time.Second) / float64(c.Rate)))
}
} else {
for {
logger.Info("generating", zap.String("name", name))
dur := time.Duration(rand.NormFloat64()*5000000) * time.Microsecond
durRecorder.Record(ctx, dur.Microseconds())
time.Sleep(time.Duration(c.Rate) * time.Second)
time.Sleep(time.Duration(float64(time.Second) / float64(c.Rate)))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/metrics/up_down_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func upDownCounter(mp *metric.MeterProvider, c Config, logger *zap.Logger) Worke
} else {
counter.Add(ctx, -1)
}
time.Sleep(time.Duration(c.Rate) * time.Second)
time.Sleep(time.Duration(float64(time.Second) / float64(c.Rate)))
}
} else {
for {
Expand All @@ -56,7 +56,7 @@ func upDownCounter(mp *metric.MeterProvider, c Config, logger *zap.Logger) Worke
} else {
counter.Add(ctx, -1)
}
time.Sleep(time.Duration(c.Rate) * time.Second)
time.Sleep(time.Duration(float64(time.Second) / float64(c.Rate)))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/metrics/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func (w *Worker) Run(ctx context.Context, workerFunc WorkerFunc) error {
if w.totalDuration == 0 {
// w.numMetrics = 0
w.totalDuration = 86400 * time.Second // 24 hours
} else if w.numMetrics == 0 {
w.logger.Error("either `metrics` or `duration` must be greater than 0")
return fmt.Errorf("either `metrics` or `duration` must be greater than 0")
// } else if w.numMetrics == 0 { // !!! "NumMetrics" this undefined, always 0 !!!
// w.logger.Error("either `metrics` or `duration` must be greater than 0")
// return fmt.Errorf("either `metrics` or `duration` must be greater than 0")
}

running := atomic.NewBool(true)
Expand Down