Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 429 errors as retryable client errors #138

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
invocationContext: innerInvocationContext)
}

func completion(innerResult: Result<OutputType, HTTPClientError>) {

Check warning on line 105 in Sources/SmokeHTTPClient/HTTPOperationsClient +executeAsyncRetriableWithOutput.swift

View workflow job for this annotation

GitHub Actions / SwiftLint version 3.2.1

Function Body Length Violation: Function body should span 50 lines or less excluding comments and whitespace: currently spans 65 lines (function_body_length)

Check warning on line 105 in Sources/SmokeHTTPClient/HTTPOperationsClient +executeAsyncRetriableWithOutput.swift

View workflow job for this annotation

GitHub Actions / SwiftLint version 3.2.1

Function Body Length Violation: Function body should span 50 lines or less excluding comments and whitespace: currently spans 65 lines (function_body_length)
let result: Result<OutputType, HTTPClientError>
let logger = invocationContext.reporting.logger

Expand Down Expand Up @@ -158,7 +158,7 @@

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public extension HTTPOperationsClient {
} catch let error as HTTPClientError {
// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand All @@ -145,7 +145,7 @@ public extension HTTPOperationsClient {
case .clientError:
// never retry
shouldRetryOnError = false
case .serverError:
case .serverError, .clientRetryableError:
shouldRetryOnError = retryOnError(error)
}
let logger = invocationContext.reporting.logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public extension HTTPOperationsClient {
} catch let error as HTTPClientError {
// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand All @@ -146,7 +146,7 @@ public extension HTTPOperationsClient {
case .clientError:
// never retry
shouldRetryOnError = false
case .serverError:
case .serverError, .clientRetryableError:
shouldRetryOnError = retryOnError(error)
}
let logger = invocationContext.reporting.logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public extension HTTPOperationsClient {
if let typedError = error as? HTTPClientError {
// report failure metric
switch typedError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public extension HTTPOperationsClient {
if let typedError = error as? HTTPClientError {
// report failure metric
switch typedError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch innerError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down Expand Up @@ -268,7 +268,7 @@
// use the specified event loop or pick one for the client to use for all retry attempts
let eventLoop = invocationContext.reporting.eventLoop ?? self.eventLoopGroup.next()

let retriable = ExecuteWithOutputRetriable<OutputType, StandardHTTPClientInvocationReporting<InvocationReportingType.TraceContextType>, HandlerDelegateType>(

Check warning on line 271 in Sources/SmokeHTTPClient/HTTPOperationsClient+executeRetriableWithOutput.swift

View workflow job for this annotation

GitHub Actions / SwiftLint version 3.2.1

Line Length Violation: Line should be 150 characters or less; currently it has 165 characters (line_length)
endpointOverride: endpointOverride, requestComponents: requestComponents,
httpMethod: httpMethod,
invocationContext: wrappingInvocationContext, eventLoopOverride: eventLoop, httpClient: self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public extension HTTPOperationsClient {

// report failure metric
switch error.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
httpMethod: HTTPMethod,
invocationContext: HTTPClientInvocationContext<InvocationReportingType, HandlerDelegateType>) async throws
-> OutputType where OutputType: HTTPResponseOutputProtocol {
let durationMetricDetails: (Date, Metrics.Timer?, OutwardsRequestAggregator?)?

Check warning on line 91 in Sources/SmokeHTTPClient/HTTPOperationsClient+executeWithOutput.swift

View workflow job for this annotation

GitHub Actions / SwiftLint version 3.2.1

Large Tuple Violation: Tuples should have at most 2 members (large_tuple)

if invocationContext.reporting.outwardsRequestAggregator != nil ||
invocationContext.reporting.latencyTimer != nil {
Expand Down Expand Up @@ -124,7 +124,7 @@
if let typedError = error as? HTTPClientError {
// report failure metric
switch typedError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public extension HTTPOperationsClient {
if let typedError = error as? HTTPClientError {
// report failure metric
switch typedError.category {
case .clientError:
case .clientError, .clientRetryableError:
invocationContext.reporting.failure4XXCounter?.increment()
case .serverError:
invocationContext.reporting.failure5XXCounter?.increment()
Expand Down
7 changes: 6 additions & 1 deletion Sources/SmokeHTTPClient/HttpClientError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public struct HTTPClientError: Error {

public enum Category {
case clientError
case clientRetryableError
case serverError
}

Expand All @@ -32,7 +33,11 @@ public struct HTTPClientError: Error {
public var category: Category {
switch responseCode {
case 400...499:
return .clientError
if(responseCode == 429) {
return .clientRetryableError
} else {
return .clientError
}
default:
return .serverError
}
Expand Down
Loading