Skip to content

Commit d21d660

Browse files
committed
feat: - Use "error" in the expected HTTP status code field to verify that requests are returning an error
1 parent dd48ed0 commit d21d660

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

exthttpcheck/check.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ func requestWorker(executionRunData *ExecutionRunData, state *HTTPCheckState, ch
183183
}
184184

185185
responseStatusWasExpected := false
186-
responseBodyWasSuccessful := true
187-
responseTimeWasSuccessful := true
188186

189187
req, err := createRequest(state)
190188
if err != nil {
@@ -212,17 +210,23 @@ func requestWorker(executionRunData *ExecutionRunData, state *HTTPCheckState, ch
212210
if err != nil {
213211
log.Error().Err(err).Msg("Failed to execute request")
214212
now := time.Now()
213+
responseStatusWasExpected = slices.Contains(state.ExpectedStatusCodes, "error")
215214
executionRunData.metrics <- action_kit_api.Metric{
216215
Metric: map[string]string{
217-
"url": req.URL.String(),
218-
"error": err.Error(),
216+
"url": req.URL.String(),
217+
"error": err.Error(),
218+
"expected_http_status": strconv.FormatBool(responseStatusWasExpected),
219219
},
220220
Name: extutil.Ptr("response_time"),
221221
Value: float64(now.Sub(started).Milliseconds()),
222222
Timestamp: now,
223223
}
224-
responseStatusWasExpected = slices.Contains(state.ExpectedStatusCodes, "error")
224+
if responseStatusWasExpected {
225+
executionRunData.requestSuccessCounter.Add(1)
226+
}
225227
} else {
228+
responseBodyWasSuccessful := true
229+
responseTimeWasSuccessful := true
226230
responseTimeValue := float64(ended.Sub(requestWritten).Milliseconds())
227231
log.Debug().Msgf("Got response %s", response.Status)
228232
responseStatusWasExpected = slices.Contains(state.ExpectedStatusCodes, strconv.Itoa(response.StatusCode))

0 commit comments

Comments
 (0)