Skip to content

Commit

Permalink
Use gql errors when calculating success metric
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerholladay committed Jul 26, 2023
1 parent 68fb52c commit 247c61d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (m *Metrics) Add(r *Result) {
m.End = end
}

if r.Code >= 200 && r.Code < 400 {
if r.Code >= 200 && r.Code < 400 && (r.Protocol != "gql" || r.Error == "") {
m.success++
}

Expand Down
14 changes: 11 additions & 3 deletions lib/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ func TestMetrics_Add(t *testing.T) {

var got Metrics
for i := 1; i <= 10000; i++ {
code := codes[i%len(codes)]

protocol := "http"
if code == 200 && i%10 == 0 {
protocol = "gql"
}

got.Add(&Result{
Code: codes[i%len(codes)],
Code: code,
Timestamp: time.Unix(int64(i-1), 0),
Latency: time.Duration(i) * time.Microsecond,
BytesIn: 1024,
BytesOut: 512,
Error: errors[i%len(errors)],
Protocol: protocol,
})
}
got.Close()
Expand Down Expand Up @@ -62,8 +70,8 @@ func TestMetrics_Add(t *testing.T) {
Wait: duration("10ms"),
Requests: 10000,
Rate: 1.000100010001,
Throughput: 0.6667660098349737,
Success: 0.6667,
Throughput: 0.6333627029075878,
Success: 0.6333,
StatusCodes: map[string]int{"500": 3333, "200": 3334, "302": 3333},
Errors: []string{"Internal server error"},

Expand Down

0 comments on commit 247c61d

Please sign in to comment.