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

Make possible to configure retry options for Consul discovery client #51

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 @@ -39,28 +39,10 @@ SuperluminalServiceDiscoveryExample class >> version [
{ #category : #'private - activation' }
SuperluminalServiceDiscoveryExample >> basicStartWithin: context [

| consulAgentLocation echoServiceLocation |

consulAgentLocation := self configuration consulAgentLocation.
LaunchpadLogRecord emitInfo: 'Discovering dependencies' during: [
echoServiceLocation := Retry
value: [
( ConsulAgentHttpAPIBasedDiscoveryClient queryingAgentOn:
consulAgentLocation ) withLocationOfService: #echo
do: [ :location | location ]
ifUnable: [ Error signal: 'Cannot discover #echo service' ]
]
configuredBy: [ :retry |
retry
upTo: 3 timesEvery: self configuration retryDelayInMs;
on: Error evaluating: [ :attemptNumber :exception |
LaunchpadLogRecord emitWarning:
( 'Attempt #<1p> failed with error: <2s>' expandMacrosWith:
attemptNumber
with: exception messageText )
]
]
].
| echoServiceLocation |

LaunchpadLogRecord emitInfo: 'Discovering dependencies'
during: [ echoServiceLocation := self discoverEchoServiceQueryingConsulAgent ].

RESTfulAPIClient cachingOnLocalMemory
get: ( echoServiceLocation
Expand All @@ -69,11 +51,36 @@ SuperluminalServiceDiscoveryExample >> basicStartWithin: context [
addPathSegment: self configuration message;
yourself )
withSuccessfulResponseDo: [ :response |
response = self configuration message asUppercase ifFalse: [ Error signal: 'Invalid response received' ] ].

response = self configuration message asUppercase ifFalse: [
Error signal: 'Invalid response received' ]
].
self exitSuccess
]

{ #category : #'private - activation' }
SuperluminalServiceDiscoveryExample >> discoverEchoServiceQueryingConsulAgent [

^ ( ConsulAgentHttpAPIBasedDiscoveryClient queryingAgentOn: self configuration consulAgentLocation
configuredBy: [ :options | options at: #retry put: self retryOptions ] )
withLocationOfService: #echo
do: [ :location | location ]
ifUnable: [ Error signal: 'Cannot discover #echo service' ]
]

{ #category : #'private - activation' }
SuperluminalServiceDiscoveryExample >> retryOptions [

^ [ :retry |
retry
upTo: 3 timesEvery: self configuration retryDelayInMs;
on: Error evaluating: [ :attemptNumber :exception |
LaunchpadLogRecord emitWarning:
( 'Attempt #<1p> failed with error: <2s>' expandMacrosWith: attemptNumber
with: exception messageText )
]
]
]

{ #category : #'error handling' }
SuperluminalServiceDiscoveryExample >> stackTraceDumper [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ Class {
#name : #ConsulAgentHttpAPIBasedDiscoveryClient,
#superclass : #ServiceDiscoveryClient,
#instVars : [
'agentLocation',
'fallbackClient',
'apiClient'
'apiClient',
'options'
],
#category : #'Superluminal-Service-Discovery'
}

{ #category : #'Instance creation' }
{ #category : #'private - instance creation' }
ConsulAgentHttpAPIBasedDiscoveryClient class >> configuredBy: aBlock chainedWith: aServiceDiscoveryClient [

| options |

options := Dictionary new.
aBlock cull: options.
^ self new initializeConfiguredBy: options chainedWith: aServiceDiscoveryClient
]

{ #category : #'instance creation' }
ConsulAgentHttpAPIBasedDiscoveryClient class >> queryingAgentOn: aConsulAgentLocation [

^ self queryingAgentOn: aConsulAgentLocation chainedWith: NullServiceDiscoveryClient new
Expand All @@ -24,7 +34,33 @@ ConsulAgentHttpAPIBasedDiscoveryClient class >> queryingAgentOn: aConsulAgentLoc
{ #category : #'instance creation' }
ConsulAgentHttpAPIBasedDiscoveryClient class >> queryingAgentOn: aConsulAgentLocation chainedWith: aServiceDiscoveryClient [

^ self new initializeQueryingAgentOn: aConsulAgentLocation chainedWith: aServiceDiscoveryClient
^ self configuredBy: [ :options | options at: #agentLocation put: aConsulAgentLocation ]
chainedWith: aServiceDiscoveryClient
]

{ #category : #'instance creation' }
ConsulAgentHttpAPIBasedDiscoveryClient class >> queryingAgentOn: aConsulAgentLocation configuredBy: aBlock [

^ self queryingAgentOn: aConsulAgentLocation
configuredBy: aBlock
chainedWith: NullServiceDiscoveryClient new
]

{ #category : #'instance creation' }
ConsulAgentHttpAPIBasedDiscoveryClient class >> queryingAgentOn: aConsulAgentLocation configuredBy: aBlock chainedWith: aServiceDiscoveryClient [

^ self
configuredBy: [ :options |
options at: #agentLocation put: aConsulAgentLocation.
aBlock cull: options
]
chainedWith: aServiceDiscoveryClient
]

{ #category : #private }
ConsulAgentHttpAPIBasedDiscoveryClient >> agentLocation [

^ options at: #agentLocation
]

{ #category : #private }
Expand All @@ -33,7 +69,7 @@ ConsulAgentHttpAPIBasedDiscoveryClient >> discoverLocationOf: serviceName ifFoun
| serviceHealthList |

^ apiClient
getAt: agentLocation / 'v1' / 'health' / 'service' / serviceName
getAt: self agentLocation / 'v1' / 'health' / 'service' / serviceName
configuredBy: [ :request |
( request queryString: [ :queryString |
queryString fieldNamed: 'filter' pairedTo: 'Checks.Status == passing' ] )
Expand All @@ -50,9 +86,9 @@ ConsulAgentHttpAPIBasedDiscoveryClient >> discoverLocationOf: serviceName ifFoun
]

{ #category : #initialization }
ConsulAgentHttpAPIBasedDiscoveryClient >> initializeQueryingAgentOn: aConsulAgentLocation chainedWith: aServiceDiscoveryClient [
ConsulAgentHttpAPIBasedDiscoveryClient >> initializeConfiguredBy: anOptionsDictionary chainedWith: aServiceDiscoveryClient [

agentLocation := aConsulAgentLocation.
options := anOptionsDictionary.
fallbackClient := aServiceDiscoveryClient.
apiClient := RESTfulAPIClient cachingOnLocalMemory
]
Expand All @@ -64,7 +100,8 @@ ConsulAgentHttpAPIBasedDiscoveryClient >> withLocationOfService: serviceName do:
configuredBy: [ :retry |
retry
upTo: 2;
on: NetworkError , HTTPError
on: NetworkError , HTTPError.
options at: #retry ifPresent: [ :action | action value: retry ]
]
]

Expand Down