Skip to content

Commit

Permalink
set name to task stats to simplify sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jahaja committed Sep 19, 2020
1 parent 34f06d5 commit 405676c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
45 changes: 24 additions & 21 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type TaskRun struct {

type TaskStats struct {
sync.Mutex
Name string `json:"name"`
TotalRuns int64 `json:"total_runs"`
NumSuccessful int64 `json:"num_successful"`
NumFailed int64 `json:"num_failed"`
Expand Down Expand Up @@ -118,7 +119,7 @@ func (ts *TaskStats) Calculate() {
return flatMetrics[i].Duration < flatMetrics[j].Duration
})

percentiles := []float64{0.75, 0.85, 0.95, 0.99}
percentiles := []float64{0.5, 0.75, 0.85, 0.95, 0.99}
for _, p := range percentiles {
idx := int64(float64(ts.TotalRuns) * p)

Expand All @@ -136,8 +137,9 @@ func (ts *TaskStats) Calculate() {
ts.AverageDuration = float32(ts.TotalDuration) / float32(ts.TotalRuns)
}

func NewTaskStat() *TaskStats {
func NewTaskStat(name string) *TaskStats {
return &TaskStats{
Name: name,
Metrics: make(map[int64]int64),
Percentiles: make(map[int]int64),
Errors: make(map[string]int64),
Expand Down Expand Up @@ -267,7 +269,7 @@ func (lt *LoadTest) handleTaskRun(tr *TaskRun) {
}

if _, ok := lt.Stats.Tasks[name]; !ok {
lt.Stats.Tasks[name] = NewTaskStat()
lt.Stats.Tasks[name] = NewTaskStat(name)
}

taskStat := lt.Stats.Tasks[name]
Expand Down
3 changes: 3 additions & 0 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ func RunAPIServer(lt *LoadTest) error {
if numUsers == 0 {
writer.WriteHeader(http.StatusBadRequest)
return
} else if numUsers == lt.Config.NumUsers {
return
}

lt.Config.NumUsers = numUsers
lt.SetStatus(StatusSpawning)
writer.WriteHeader(http.StatusOK)
})

Expand Down

0 comments on commit 405676c

Please sign in to comment.