Skip to content

Commit

Permalink
feat: - Use "error" in the expected HTTP status code field to verify …
Browse files Browse the repository at this point in the history
…that requests are returning an error
  • Loading branch information
ReuDa committed Nov 28, 2024
1 parent dd48ed0 commit d21d660
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions exthttpcheck/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ func requestWorker(executionRunData *ExecutionRunData, state *HTTPCheckState, ch
}

responseStatusWasExpected := false
responseBodyWasSuccessful := true
responseTimeWasSuccessful := true

req, err := createRequest(state)
if err != nil {
Expand Down Expand Up @@ -212,17 +210,23 @@ func requestWorker(executionRunData *ExecutionRunData, state *HTTPCheckState, ch
if err != nil {
log.Error().Err(err).Msg("Failed to execute request")
now := time.Now()
responseStatusWasExpected = slices.Contains(state.ExpectedStatusCodes, "error")
executionRunData.metrics <- action_kit_api.Metric{
Metric: map[string]string{
"url": req.URL.String(),
"error": err.Error(),
"url": req.URL.String(),
"error": err.Error(),
"expected_http_status": strconv.FormatBool(responseStatusWasExpected),
},
Name: extutil.Ptr("response_time"),
Value: float64(now.Sub(started).Milliseconds()),
Timestamp: now,
}
responseStatusWasExpected = slices.Contains(state.ExpectedStatusCodes, "error")
if responseStatusWasExpected {
executionRunData.requestSuccessCounter.Add(1)
}
} else {
responseBodyWasSuccessful := true
responseTimeWasSuccessful := true
responseTimeValue := float64(ended.Sub(requestWritten).Milliseconds())
log.Debug().Msgf("Got response %s", response.Status)
responseStatusWasExpected = slices.Contains(state.ExpectedStatusCodes, strconv.Itoa(response.StatusCode))
Expand Down

0 comments on commit d21d660

Please sign in to comment.