Skip to content

Commit

Permalink
Added failure list code, tested
Browse files Browse the repository at this point in the history
  • Loading branch information
mchinta7 committed Dec 28, 2023
1 parent 2c93ca6 commit 411bb35
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
2 changes: 2 additions & 0 deletions api/types/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type ResponseStats struct {
Total int
// Failures represents number of failure request.
Failures int
// List of failures
FailureList []error
// Duration means the time of benchmark.
Duration time.Duration
// PercentileLatencies represents the latency distribution in seconds.
Expand Down
5 changes: 5 additions & 0 deletions cmd/kperf/commands/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func printResponseStats(stats *types.ResponseStats) {
fmt.Println("Response stat:")
fmt.Printf(" Total: %v\n", stats.Total)
fmt.Printf(" Failures: %v\n", stats.Failures)
fmt.Println("==========================")
for i, v := range stats.FailureList {
fmt.Printf(" Failure %d: %v\n", i+1, v)
}
fmt.Println("==========================")
fmt.Printf(" Duration: %v\n", stats.Duration)
fmt.Printf(" Requests/sec: %.2f\n", float64(stats.Total)/stats.Duration.Seconds())

Expand Down
15 changes: 9 additions & 6 deletions metrics/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ type ResponseMetric interface {
// ObserveLatency observes latency.
ObserveLatency(seconds float64)
// ObserveFailure observes failure response.
ObserveFailure()
ObserveFailure(err error)
// Gather returns the summary.
Gather() (latencies []float64, percentileLatencies map[float64]float64, failure int)
Gather() (latencies []float64, percentileLatencies map[float64]float64, failure int, failureList []error)
}

type responseMetricImpl struct {
mu sync.Mutex
failureCount int64
failureList []error
latencies *list.List
}

func NewResponseMetric() ResponseMetric {
return &responseMetricImpl{
latencies: list.New(),
latencies: list.New(),
failureList: []error{},
}
}

Expand All @@ -38,15 +40,16 @@ func (m *responseMetricImpl) ObserveLatency(seconds float64) {
}

// ObserveFailure implements ResponseMetric.
func (m *responseMetricImpl) ObserveFailure() {
func (m *responseMetricImpl) ObserveFailure(err error) {
m.failureList = append(m.failureList, err)
atomic.AddInt64(&m.failureCount, 1)
}

// Gather implements ResponseMetric.
func (m *responseMetricImpl) Gather() ([]float64, map[float64]float64, int) {
func (m *responseMetricImpl) Gather() ([]float64, map[float64]float64, int, []error) {
latencies := m.dumpLatencies()

return latencies, buildPercentileLatencies(latencies), int(atomic.LoadInt64(&m.failureCount))
return latencies, buildPercentileLatencies(latencies), int(atomic.LoadInt64(&m.failureCount)), m.failureList
}

func (m *responseMetricImpl) dumpLatencies() []float64 {
Expand Down
2 changes: 1 addition & 1 deletion metrics/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestResponseMetric(t *testing.T) {
c.ObserveLatency(float64(i))
}

_, res, _ := c.Gather()
_, res, _, _ := c.Gather()
assert.Equal(t, float64(1), res[0])
assert.Equal(t, float64(50), res[50])
assert.Equal(t, float64(90), res[90])
Expand Down
5 changes: 3 additions & 2 deletions request/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
_, err = io.Copy(io.Discard, respBody)
}
if err != nil {
respMetric.ObserveFailure()
respMetric.ObserveFailure(err)
}
}()
}
Expand All @@ -80,10 +80,11 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I

totalDuration := time.Since(start)

_, percentileLatencies, failures := respMetric.Gather()
_, percentileLatencies, failures, failureList := respMetric.Gather()
return &types.ResponseStats{
Total: spec.Total,
Failures: failures,
FailureList: failureList,
Duration: totalDuration,
PercentileLatencies: percentileLatencies,
}, nil
Expand Down
17 changes: 17 additions & 0 deletions tmp/xx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 1
description: test
spec:
rate: 100
total: 10
conns: 10
requests:
- staleList:
version: v1
resource: pods
limit: 500
shares: 100
- quorumList:
version: v1
resource: pods
limit: 1000
shares: 150

0 comments on commit 411bb35

Please sign in to comment.