diff --git a/lib/netext/httpext/tracer.go b/lib/netext/httpext/tracer.go index d4896d732d1..a40968e760a 100644 --- a/lib/netext/httpext/tracer.go +++ b/lib/netext/httpext/tracer.go @@ -63,17 +63,17 @@ type Trail struct { // SaveSamples populates the Trail's sample slice so they're accesible via GetSamples() func (tr *Trail) SaveSamples(tags *stats.SampleTags) { tr.Tags = tags - tr.Samples = []stats.Sample{ + tr.Samples = make([]stats.Sample, 0, 9) // this is with 1 more for a possible HTTPReqFailed + tr.Samples = append(tr.Samples, []stats.Sample{ {Metric: metrics.HTTPReqs, Time: tr.EndTime, Tags: tags, Value: 1}, {Metric: metrics.HTTPReqDuration, Time: tr.EndTime, Tags: tags, Value: stats.D(tr.Duration)}, - {Metric: metrics.HTTPReqBlocked, Time: tr.EndTime, Tags: tags, Value: stats.D(tr.Blocked)}, {Metric: metrics.HTTPReqConnecting, Time: tr.EndTime, Tags: tags, Value: stats.D(tr.Connecting)}, {Metric: metrics.HTTPReqTLSHandshaking, Time: tr.EndTime, Tags: tags, Value: stats.D(tr.TLSHandshaking)}, {Metric: metrics.HTTPReqSending, Time: tr.EndTime, Tags: tags, Value: stats.D(tr.Sending)}, {Metric: metrics.HTTPReqWaiting, Time: tr.EndTime, Tags: tags, Value: stats.D(tr.Waiting)}, {Metric: metrics.HTTPReqReceiving, Time: tr.EndTime, Tags: tags, Value: stats.D(tr.Receiving)}, - } + }...) } // GetSamples implements the stats.SampleContainer interface. diff --git a/stats/cloud/data.go b/stats/cloud/data.go index b072abd5e9c..66052437614 100644 --- a/stats/cloud/data.go +++ b/stats/cloud/data.go @@ -110,46 +110,39 @@ type SampleDataMap struct { // NewSampleFromTrail just creates a ready-to-send Sample instance // directly from a httpext.Trail. func NewSampleFromTrail(trail *httpext.Trail) *Sample { - if trail.Failed.Valid { - return &Sample{ - Type: DataTypeMap, - Metric: "http_req_li_all", - Data: &SampleDataMap{ - Time: toMicroSecond(trail.GetTime()), - Tags: trail.GetTags(), - Values: map[string]float64{ - metrics.HTTPReqs.Name: 1, - metrics.HTTPReqDuration.Name: stats.D(trail.Duration), - - metrics.HTTPReqBlocked.Name: stats.D(trail.Blocked), - metrics.HTTPReqConnecting.Name: stats.D(trail.Connecting), - metrics.HTTPReqTLSHandshaking.Name: stats.D(trail.TLSHandshaking), - metrics.HTTPReqSending.Name: stats.D(trail.Sending), - metrics.HTTPReqWaiting.Name: stats.D(trail.Waiting), - metrics.HTTPReqReceiving.Name: stats.D(trail.Receiving), - metrics.HTTPReqFailed.Name: stats.B(trail.Failed.Bool), - }, - }, + var values map[string]float64 + if trail.Failed.Valid { // this is done so the adding of 1 map element doesn't reexpand the map as this is a hotpath + values = map[string]float64{ + metrics.HTTPReqs.Name: 1, + metrics.HTTPReqDuration.Name: stats.D(trail.Duration), + metrics.HTTPReqBlocked.Name: stats.D(trail.Blocked), + metrics.HTTPReqConnecting.Name: stats.D(trail.Connecting), + metrics.HTTPReqTLSHandshaking.Name: stats.D(trail.TLSHandshaking), + metrics.HTTPReqSending.Name: stats.D(trail.Sending), + metrics.HTTPReqWaiting.Name: stats.D(trail.Waiting), + metrics.HTTPReqReceiving.Name: stats.D(trail.Receiving), + + metrics.HTTPReqFailed.Name: stats.B(trail.Failed.Bool), + } + } else { + values = map[string]float64{ + metrics.HTTPReqs.Name: 1, + metrics.HTTPReqDuration.Name: stats.D(trail.Duration), + metrics.HTTPReqBlocked.Name: stats.D(trail.Blocked), + metrics.HTTPReqConnecting.Name: stats.D(trail.Connecting), + metrics.HTTPReqTLSHandshaking.Name: stats.D(trail.TLSHandshaking), + metrics.HTTPReqSending.Name: stats.D(trail.Sending), + metrics.HTTPReqWaiting.Name: stats.D(trail.Waiting), + metrics.HTTPReqReceiving.Name: stats.D(trail.Receiving), } } - return &Sample{ Type: DataTypeMap, Metric: "http_req_li_all", Data: &SampleDataMap{ - Time: toMicroSecond(trail.GetTime()), - Tags: trail.GetTags(), - Values: map[string]float64{ - metrics.HTTPReqs.Name: 1, - metrics.HTTPReqDuration.Name: stats.D(trail.Duration), - - metrics.HTTPReqBlocked.Name: stats.D(trail.Blocked), - metrics.HTTPReqConnecting.Name: stats.D(trail.Connecting), - metrics.HTTPReqTLSHandshaking.Name: stats.D(trail.TLSHandshaking), - metrics.HTTPReqSending.Name: stats.D(trail.Sending), - metrics.HTTPReqWaiting.Name: stats.D(trail.Waiting), - metrics.HTTPReqReceiving.Name: stats.D(trail.Receiving), - }, + Time: toMicroSecond(trail.GetTime()), + Tags: trail.GetTags(), + Values: values, }, } }