Add checking for existent function in GetReplicas
Within MakeScalingHandler() there is a call to GetReplicas() which was not returning an error when a non-200 http response was received from /system/function/. The call would also return a populated struct, so the perception was that a function existed an had been scaled to zero. This meant that the function would be added to the function cache and the code would continue into SetReplicas() where an attempt would be made to scale up a non-existent function.
This change amends GetReplicas() so that it will return an error if the gateway returns anything other than a 200 reponse code from the /system/function/ endpoint. This causes MakeScalingHandler() to return earlier with an error indicating that the function could not be found. The cache.Set call is also moved to after the error check so that the cache is only updated to include existent functions.
During investigations as to the cause of #876 tests were added to function_cache to check that Get() is behaving as intended when function exists and when not. Tests are also added to plugin/external to test that GetReplicas() and SetReplicas() are following their intended modes of operation when 200 and non-200 responses are received from the gateway.
Signed-off-by:
Richard Gee <richard@technologee.co.uk>
Showing
- gateway/handlers/function_cache_test.go 40 additions, 0 deletionsgateway/handlers/function_cache_test.go
- gateway/handlers/scaling.go 2 additions, 1 deletiongateway/handlers/scaling.go
- gateway/plugin/external.go 3 additions, 0 deletionsgateway/plugin/external.go
- gateway/plugin/external_test.go 108 additions, 1 deletiongateway/plugin/external_test.go
Please register or sign in to comment