Skip to content

Commit

Permalink
Sarthak | Reporter now waits for the load and the response metric gor…
Browse files Browse the repository at this point in the history
…outines to finish in the PrintReport method
  • Loading branch information
SarthakMakhija committed Aug 18, 2023
1 parent a6c5f8c commit 1154852
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
9 changes: 9 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1. Integrate blast.go in main
2. Format report (unnecessary new lines)
3. Add total connections in the report
4. Add total responses in the report
5. Validate the options in main
6. Run against a sample server
- with input from a file
- with input from a process
7. Take a look at TODOs
29 changes: 21 additions & 8 deletions report/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ type ResponseMetrics struct {
}

type Reporter struct {
report *Report
totalLoadReportedTillNow atomic.Uint64
loadGenerationChannel chan LoadGenerationResponse
responseChannel chan SubjectServerResponse
report *Report
totalLoadReportedTillNow atomic.Uint64
loadGenerationChannel chan LoadGenerationResponse
responseChannel chan SubjectServerResponse
loadMetricsDoneChannel chan struct{}
responseMetricsDoneChannel chan struct{}
}

func NewLoadGenerationMetricsCollectingReporter(
Expand All @@ -56,8 +58,10 @@ func NewLoadGenerationMetricsCollectingReporter(
IsAvailableForReporting: false,
},
},
loadGenerationChannel: loadGenerationChannel,
responseChannel: nil,
loadGenerationChannel: loadGenerationChannel,
responseChannel: nil,
loadMetricsDoneChannel: make(chan struct{}),
responseMetricsDoneChannel: nil,
}
}

Expand All @@ -75,8 +79,10 @@ func NewResponseMetricsCollectingReporter(
ErrorCountByType: make(map[string]uint),
},
},
loadGenerationChannel: loadGenerationChannel,
responseChannel: responseChannel,
loadGenerationChannel: loadGenerationChannel,
responseChannel: responseChannel,
loadMetricsDoneChannel: make(chan struct{}),
responseMetricsDoneChannel: make(chan struct{}),
}
}

Expand All @@ -88,6 +94,11 @@ func (reporter *Reporter) Run() {
}

func (reporter *Reporter) PrintReport(writer io.Writer) {
println("printing report...")
<-reporter.loadMetricsDoneChannel
if reporter.responseMetricsDoneChannel != nil {
<-reporter.responseMetricsDoneChannel
}
print(writer, reporter.report)
}

Expand Down Expand Up @@ -128,6 +139,7 @@ func (reporter *Reporter) collectLoadMetrics() {

reporter.report.Load.TotalTime = timeToCompleteLoad
reporter.report.Load.TotalRequests = totalGeneratedLoad
close(reporter.loadMetricsDoneChannel)
}()
}

Expand Down Expand Up @@ -168,5 +180,6 @@ func (reporter *Reporter) collectResponseMetrics() {
timeToCompleteResponses := reporter.report.Response.LatestResponseReceivedTime.
Sub(reporter.report.Response.EarliestResponseReceivedTime)
reporter.report.Response.TotalTime = timeToCompleteResponses
close(reporter.responseMetricsDoneChannel)
}()
}
1 change: 1 addition & 0 deletions report/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Summary:
{{ if eq (.Response.IsAvailableForReporting) true }}
ResponseMetrics:
TotalResponses: {{ formatNumberUint .Response.TotalResponses }}
SuccessCount: {{ formatNumberUint .Response.SuccessCount }}
ErrorCount: {{ formatNumberUint .Response.ErrorCount }}
TotalResponsePayloadSize: {{ humanizePayloadSize .Response.TotalResponsePayloadLengthBytes }}
Expand Down
6 changes: 4 additions & 2 deletions report/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Summary:
ResponseMetrics:
SuccessCount: 1000
TotalResponses: 1000
SuccessCount: 999
ErrorCount: 1
TotalResponsePayloadSize: 1.8 kB
AverageResponsePayloadSize: 18 B
Expand Down Expand Up @@ -58,7 +59,8 @@ Summary:
TotalTime: tenSecondsLater.Sub(startTime),
},
Response: ResponseMetrics{
SuccessCount: 1000,
TotalResponses: 1000,
SuccessCount: 999,
ErrorCount: 1,
ErrorCountByType: map[string]uint{"response error": 1},
TotalResponsePayloadLengthBytes: 1800,
Expand Down
1 change: 1 addition & 0 deletions tests/blast_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestBlastWithLoadGenerationAndResponseReading(t *testing.T) {

output := string(buffer.Bytes())
assert.True(t, strings.Contains(output, "ResponseMetrics"))
assert.True(t, strings.Contains(output, "TotalResponses: 20"))
assert.True(t, strings.Contains(output, "SuccessCount: 20"))
assert.True(t, strings.Contains(output, "ErrorCount: 0"))
assert.True(t, strings.Contains(output, "TotalPayloadSize: 200 B"))
Expand Down

0 comments on commit 1154852

Please sign in to comment.