Add Prewarming Pool Alert
that checks for every environment if the filled share of the prewarmin pool is at least the specified threshold.
This commit is contained in:

committed by
Sebastian Serth

parent
1be3ce5ae1
commit
c46a09eeae
@ -1,16 +1,55 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/openHPI/poseidon/internal/config"
|
||||
"github.com/openHPI/poseidon/internal/environment"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
"github.com/openHPI/poseidon/tests"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
)
|
||||
|
||||
func (s *MainTestSuite) TestHealthRoute() {
|
||||
request, err := http.NewRequest(http.MethodGet, "/health", http.NoBody)
|
||||
if err != nil {
|
||||
s.T().Fatal(err)
|
||||
}
|
||||
recorder := httptest.NewRecorder()
|
||||
http.HandlerFunc(Health).ServeHTTP(recorder, request)
|
||||
s.Equal(http.StatusNoContent, recorder.Code)
|
||||
func (s *MainTestSuite) TestHealth() {
|
||||
s.Run("returns StatusNoContent as default", func() {
|
||||
request, err := http.NewRequest(http.MethodGet, "/health", http.NoBody)
|
||||
if err != nil {
|
||||
s.T().Fatal(err)
|
||||
}
|
||||
recorder := httptest.NewRecorder()
|
||||
manager := &environment.ManagerHandlerMock{}
|
||||
manager.On("Statistics").Return(map[dto.EnvironmentID]*dto.StatisticalExecutionEnvironmentData{})
|
||||
|
||||
Health(manager).ServeHTTP(recorder, request)
|
||||
s.Equal(http.StatusNoContent, recorder.Code)
|
||||
})
|
||||
s.Run("returns InternalServerError for warnings and errors", func() {
|
||||
s.Run("Prewarming Pool Alert", func() {
|
||||
request, err := http.NewRequest(http.MethodGet, "/health", http.NoBody)
|
||||
if err != nil {
|
||||
s.T().Fatal(err)
|
||||
}
|
||||
recorder := httptest.NewRecorder()
|
||||
manager := &environment.ManagerHandlerMock{}
|
||||
manager.On("Statistics").Return(map[dto.EnvironmentID]*dto.StatisticalExecutionEnvironmentData{
|
||||
tests.DefaultEnvironmentIDAsInteger: {
|
||||
ID: tests.DefaultEnvironmentIDAsInteger,
|
||||
PrewarmingPoolSize: 3,
|
||||
IdleRunners: 1,
|
||||
},
|
||||
})
|
||||
config.Config.Server.PrewarmingPoolAlertThreshold = 0.5
|
||||
|
||||
Health(manager).ServeHTTP(recorder, request)
|
||||
s.Equal(http.StatusServiceUnavailable, recorder.Code)
|
||||
|
||||
b, err := io.ReadAll(recorder.Body)
|
||||
s.Require().NoError(err)
|
||||
var details dto.InternalServerError
|
||||
err = json.Unmarshal(b, &details)
|
||||
s.Require().NoError(err)
|
||||
s.Contains(details.Message, ErrorPrewarmingPoolDepleting.Error())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user