Skip to content

Commit 813b2d6

Browse files
authored
Merge pull request #843 from uber/sacheendra/emit_metrics_changes
Removed latency metrics
2 parents f19d36a + ac7f60b commit 813b2d6

File tree

3 files changed

+3
-25
lines changed

3 files changed

+3
-25
lines changed

runtime/middlewares.go

+1-23
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ package zanzibar
2222

2323
import (
2424
"context"
25-
"time"
2625

2726
jsonschema "github.com/mcuadros/go-jsonschema-generator"
2827
"github.com/uber-go/tally"
2928
)
3029

3130
const (
32-
middlewareRequestLatencyTag = "middleware.request.latency"
33-
middlewareResponseLatencyTag = "middleware.response.latency"
34-
middlewareRequestStatusTag = "middleware.request.status"
31+
middlewareRequestStatusTag = "middleware.request.status"
3532
)
3633

3734
// MiddlewareStack is a stack of Middleware Handlers that can be invoked as an Handle.
@@ -111,23 +108,16 @@ func (m *MiddlewareStack) Handle(
111108
res *ServerHTTPResponse) context.Context {
112109

113110
shared := NewSharedState(m.middlewares)
114-
middlewareRequestStartTime := time.Now()
115111

116112
for i := 0; i < len(m.middlewares); i++ {
117113
ctx, ok := m.middlewares[i].HandleRequest(ctx, req, res, shared)
118114
// If a middleware errors and writes to the response header
119115
// then abort the rest of the stack and evaluate the response
120116
// handlers for the middlewares seen so far.
121117
if ok == false {
122-
//record latency for middlewares requests in unsuccessful case as the middleware requests calls are terminated
123-
m.recordLatency(middlewareRequestLatencyTag, middlewareRequestStartTime, req.scope)
124-
125-
middlewareResponseStartTime := time.Now() // start the timer for middleware responses
126118
for j := i; j >= 0; j-- {
127119
m.middlewares[j].HandleResponse(ctx, res, shared)
128120
}
129-
//record latency for middlewares responses in unsuccessful case
130-
m.recordLatency(middlewareResponseLatencyTag, middlewareResponseStartTime, req.scope)
131121

132122
//for error metrics only emit when there is gateway error and not request error
133123
// the percentage can be calculated via error_count/total_request
@@ -137,27 +127,15 @@ func (m *MiddlewareStack) Handle(
137127
return ctx
138128
}
139129
}
140-
// record latency for middlewares requests in successful case
141-
m.recordLatency(middlewareRequestLatencyTag, middlewareRequestStartTime, req.scope)
142130

143131
ctx = m.handle(ctx, req, res)
144132

145-
middlewareResponseStartTime := time.Now()
146133
for i := len(m.middlewares) - 1; i >= 0; i-- {
147134
m.middlewares[i].HandleResponse(ctx, res, shared)
148135
}
149-
// record latency for middlewares responses in successful case
150-
m.recordLatency(middlewareResponseLatencyTag, middlewareResponseStartTime, req.scope)
151136
return ctx
152137
}
153138

154-
// recordLatency measures the latency as per the tagName and start time given.
155-
func (m *MiddlewareStack) recordLatency(tagName string, startTime time.Time, scope tally.Scope) {
156-
elapsed := time.Now().Sub(startTime)
157-
scope.Timer(tagName).Record(elapsed)
158-
scope.Histogram(tagName, tally.DefaultBuckets).RecordDuration(elapsed)
159-
}
160-
161139
// emitAvailability is used to increment the error counter for a particular tagName.
162140
func (m *MiddlewareStack) emitAvailabilityError(tagName string, middlewareName string, scope tally.Scope) {
163141
tagged := scope.Tagged(map[string]string{

test/endpoints/bar/bar_metrics_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestCallMetrics(t *testing.T) {
6262
},
6363
)
6464

65-
numMetrics := 20
65+
numMetrics := 16
6666
cg := gateway.(*testGateway.ChildProcessGateway)
6767
cg.MetricsWaitGroup.Add(numMetrics)
6868

test/endpoints/baz/baz_metrics_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestCallMetrics(t *testing.T) {
7979
headers["device"] = "ios"
8080
headers["deviceversion"] = "carbon"
8181

82-
numMetrics := 18
82+
numMetrics := 14
8383
cg.MetricsWaitGroup.Add(numMetrics)
8484

8585
_, err = gateway.MakeRequest(

0 commit comments

Comments
 (0)