Skip to content

Commit

Permalink
fix(aggregated_metrics): Fix the IsError method causing retries (back…
Browse files Browse the repository at this point in the history
…port k230) (#15298)

Co-authored-by: Shantanu Alshi <[email protected]>
  • Loading branch information
loki-gh-app[bot] and shantanualsi authored Dec 6, 2024
1 parent 4d37150 commit fb11736
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/util/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func ErrorTypeFromHTTPStatus(status int) string {
}

func IsError(status int) bool {
return status/200 != 0
return status < 200 || status >= 300
}

func IsServerError(status int) bool {
Expand Down
56 changes: 56 additions & 0 deletions pkg/util/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,59 @@ func TestErrorTypeFromHTTPStatus(t *testing.T) {
})
}
}

func TestIsError(t *testing.T) {
tests := []struct {
name string
status int
expectedResult bool
}{
{
name: "200 OK",
status: 200,
expectedResult: false,
},
{
name: "201 Created",
status: 201,
expectedResult: false,
},
{
name: "400 Bad Request",
status: 400,
expectedResult: true,
},
{
name: "404 Not Found",
status: 404,
expectedResult: true,
},
{
name: "429 Too Many Requests",
status: 429,
expectedResult: true,
},
{
name: "500 Internal Server Error",
status: 500,
expectedResult: true,
},
{
name: "503 Service Unavailable",
status: 503,
expectedResult: true,
},
{
name: "600 Unknown",
status: 600,
expectedResult: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := util.IsError(tt.status)
assert.Equal(t, tt.expectedResult, result)
})
}
}

0 comments on commit fb11736

Please sign in to comment.