@@ -88,14 +88,20 @@ func (r *RouteRegistry) Register(uri route.Uri, endpoint *route.Endpoint) {
88
88
return
89
89
}
90
90
91
- poolPutResult := r .register (uri , endpoint )
91
+ poolPutResult , routeAdded := r .register (uri , endpoint )
92
92
93
93
r .reporter .CaptureRegistryMessage (endpoint , poolPutResult .String ())
94
94
95
95
if poolPutResult == route .EndpointAdded && ! endpoint .UpdatedAt .IsZero () {
96
96
r .reporter .CaptureRouteRegistrationLatency (time .Since (endpoint .UpdatedAt ))
97
97
}
98
98
99
+ if routeAdded {
100
+ r .logger .Info ("route-registered" , slog .Any ("uri" , uri ))
101
+ // for backward compatibility:
102
+ r .logger .Debug ("uri-added" , slog .Any ("uri" , uri ))
103
+ }
104
+
99
105
switch poolPutResult {
100
106
case route .EndpointAdded :
101
107
if r .logger .Enabled (context .Background (), slog .LevelInfo ) {
@@ -116,7 +122,7 @@ func (r *RouteRegistry) Register(uri route.Uri, endpoint *route.Endpoint) {
116
122
}
117
123
}
118
124
119
- func (r * RouteRegistry ) register (uri route.Uri , endpoint * route.Endpoint ) route.PoolPutResult {
125
+ func (r * RouteRegistry ) register (uri route.Uri , endpoint * route.Endpoint ) ( putResult route.PoolPutResult , routeAdded bool ) {
120
126
r .RLock ()
121
127
defer r .RUnlock ()
122
128
@@ -127,44 +133,45 @@ func (r *RouteRegistry) register(uri route.Uri, endpoint *route.Endpoint) route.
127
133
if pool == nil {
128
134
// release read lock, insertRouteKey() will acquire a write lock.
129
135
r .RUnlock ()
130
- pool = r .insertRouteKey (routekey , uri )
136
+ pool , routeAdded = r .insertRouteKey (routekey , uri )
131
137
r .RLock ()
132
138
}
133
139
134
140
if endpoint .StaleThreshold > r .dropletStaleThreshold || endpoint .StaleThreshold == 0 {
135
141
endpoint .StaleThreshold = r .dropletStaleThreshold
136
142
}
137
143
138
- poolPutResult : = pool .Put (endpoint )
144
+ putResult = pool .Put (endpoint )
139
145
// Overwrites the load balancing algorithm of a pool by that of a specified endpoint, if that is valid.
140
146
r .SetTimeOfLastUpdate (t )
141
147
142
- return poolPutResult
148
+ return putResult , routeAdded
143
149
}
144
150
145
- // insertRouteKey acquires a write lock, inserts the route key into the registry and releases the write lock.
146
- func (r * RouteRegistry ) insertRouteKey (routekey route.Uri , uri route.Uri ) * route.EndpointPool {
151
+ // insertRouteKey acquires a write lock, inserts the route key into the registry and releases the
152
+ // write lock. If a pool already exists it returns that instead.
153
+ func (r * RouteRegistry ) insertRouteKey (routekey route.Uri , uri route.Uri ) (pool * route.EndpointPool , poolAdded bool ) {
147
154
r .Lock ()
148
155
defer r .Unlock ()
149
156
150
157
// double check that the route key is still not found, now with the write lock.
151
- pool := r .byURI .Find (routekey )
152
- if pool == nil {
153
- host , contextPath := splitHostAndContextPath (uri )
154
- pool = route .NewPool (& route.PoolOpts {
155
- Logger : r .logger ,
156
- RetryAfterFailure : r .dropletStaleThreshold / 4 ,
157
- Host : host ,
158
- ContextPath : contextPath ,
159
- MaxConnsPerBackend : r .maxConnsPerBackend ,
160
- LoadBalancingAlgorithm : r .DefaultLoadBalancingAlgorithm ,
161
- })
162
- r .byURI .Insert (routekey , pool )
163
- r .logger .Info ("route-registered" , slog .Any ("uri" , routekey ))
164
- // for backward compatibility:
165
- r .logger .Debug ("uri-added" , slog .Any ("uri" , routekey ))
158
+ pool = r .byURI .Find (routekey )
159
+ if pool != nil {
160
+ return pool , false
166
161
}
167
- return pool
162
+
163
+ host , contextPath := splitHostAndContextPath (uri )
164
+ pool = route .NewPool (& route.PoolOpts {
165
+ Logger : r .logger ,
166
+ RetryAfterFailure : r .dropletStaleThreshold / 4 ,
167
+ Host : host ,
168
+ ContextPath : contextPath ,
169
+ MaxConnsPerBackend : r .maxConnsPerBackend ,
170
+ LoadBalancingAlgorithm : r .DefaultLoadBalancingAlgorithm ,
171
+ })
172
+ r .byURI .Insert (routekey , pool )
173
+
174
+ return pool , true
168
175
}
169
176
170
177
func (r * RouteRegistry ) Unregister (uri route.Uri , endpoint * route.Endpoint ) {
0 commit comments