Skip to content

Commit

Permalink
ui: add thresholds to summary export
Browse files Browse the repository at this point in the history
  • Loading branch information
cuonglm committed Nov 11, 2019
1 parent f6290b7 commit 5d558ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
14 changes: 14 additions & 0 deletions ui/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,20 @@ func (s *Summary) SummarizeMetricsJSON(w io.Writer, data SummaryData) error {

sinkData := m.Sink.Format(data.Time)
metricsData[name] = sinkData

if len(m.Thresholds.Thresholds) > 0 {
sinkDataWithThreshold := make(map[string]interface{})
for k, v := range sinkData {
sinkDataWithThreshold[k] = v
}
thresholds := make(map[string]interface{})
for _, threshold := range m.Thresholds.Thresholds {
thresholds[threshold.Source] = threshold.LastFailed
}
sinkDataWithThreshold["thresholds"] = thresholds
metricsData[name] = sinkDataWithThreshold

This comment has been minimized.

Copy link
@mstoykov

mstoykov Nov 11, 2019

Collaborator

This will get overwritten at 5d558ee#diff-cc7288c8b0cb64e706ac188a9e524b7fR444 for non Trend metrics

This comment has been minimized.

Copy link
@cuonglm

cuonglm Nov 11, 2019

Author Contributor

@mstoykov Do we have thresholds for non Trend metrics?

This comment has been minimized.

Copy link
@mstoykov

mstoykov Nov 11, 2019

Collaborator

The example in the documentation is for a Rate

}

if _, ok := m.Sink.(*stats.TrendSink); ok {
continue
}
Expand Down
20 changes: 18 additions & 2 deletions ui/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,20 @@ func createTestMetrics() map[string]*stats.Metric {
metrics["vus"] = gaugeMetric
metrics["http_reqs"] = countMetric
metrics["checks"] = checksMetric
metrics["my_trend"] = &stats.Metric{Name: "my_trend", Type: stats.Trend, Contains: stats.Time, Sink: sink}
metrics["my_trend"] = &stats.Metric{
Name: "my_trend",
Type: stats.Trend,
Contains: stats.Time,
Sink: sink,
Thresholds: stats.Thresholds{
Thresholds: []*stats.Threshold{
&stats.Threshold{
Source: "my_trend<1000",
LastFailed: true,
},
},
},
}

return metrics
}
Expand Down Expand Up @@ -209,7 +222,10 @@ func TestSummarizeMetricsJSON(t *testing.T) {
"med": 15,
"min": 10,
"p(90)": 19,
"p(95)": 19.5
"p(95)": 19.5,
"thresholds": {
"my_trend<1000": true
}
},
"vus": {
"value": 1,
Expand Down

0 comments on commit 5d558ee

Please sign in to comment.