@@ -141,6 +141,7 @@ var _ = Describe("Backend handler", func() {
141
141
Context ("metrics" , func () {
142
142
var (
143
143
beforeRequestCountMetric float64
144
+ beforeResponseCountMetric float64
144
145
beforeResponseDurationSecondsMetric float64
145
146
)
146
147
@@ -152,6 +153,15 @@ var _ = Describe("Backend handler", func() {
152
153
)
153
154
}
154
155
156
+ var measureResponseCount = func (responseCode string ) float64 {
157
+ return promtest .ToFloat64 (
158
+ handlers .BackendHandlerResponseCountMetric .With (prometheus.Labels {
159
+ "backend_id" : "backend-metrics" ,
160
+ "response_code" : responseCode ,
161
+ }),
162
+ )
163
+ }
164
+
155
165
var measureResponseDurationSeconds = func (responseCode string ) float64 {
156
166
return promtest .ToFloat64 (
157
167
handlers .BackendHandlerResponseDurationSecondsMetric .With (prometheus.Labels {
@@ -179,6 +189,7 @@ var _ = Describe("Backend handler", func() {
179
189
rw .WriteHeader (http .StatusOK )
180
190
})
181
191
192
+ beforeResponseCountMetric = measureResponseCount ("200" )
182
193
beforeResponseDurationSecondsMetric = measureResponseDurationSeconds ("200" )
183
194
184
195
router .ServeHTTP (
@@ -193,6 +204,12 @@ var _ = Describe("Backend handler", func() {
193
204
).To (Equal (float64 (1 )))
194
205
})
195
206
207
+ It ("should count the number of proxied responses" , func () {
208
+ Expect (
209
+ measureResponseCount ("200" ) - beforeResponseCountMetric ,
210
+ ).To (Equal (float64 (1 )))
211
+ })
212
+
196
213
It ("should record the duration of proxied responses" , func () {
197
214
Expect (
198
215
measureResponseDurationSeconds ("200" ) - beforeResponseDurationSecondsMetric ,
@@ -207,6 +224,7 @@ var _ = Describe("Backend handler", func() {
207
224
rw .WriteHeader (http .StatusOK )
208
225
})
209
226
227
+ beforeResponseCountMetric = measureResponseCount ("504" )
210
228
beforeResponseDurationSecondsMetric = measureResponseDurationSeconds ("504" )
211
229
212
230
router .ServeHTTP (
@@ -221,6 +239,12 @@ var _ = Describe("Backend handler", func() {
221
239
).To (Equal (float64 (1 )))
222
240
})
223
241
242
+ It ("should count the number of proxied responses" , func () {
243
+ Expect (
244
+ measureResponseCount ("504" ) - beforeResponseCountMetric ,
245
+ ).To (Equal (float64 (1 )))
246
+ })
247
+
224
248
It ("should record the duration of proxied responses" , func () {
225
249
Expect (
226
250
measureResponseDurationSeconds ("504" ) - beforeResponseDurationSecondsMetric ,
0 commit comments