diff --git a/core/service.go b/core/service.go index c32d62c0..03f5fb65 100644 --- a/core/service.go +++ b/core/service.go @@ -50,6 +50,7 @@ type Service struct { NumberOfSuccessesInARow int } +// ValidateAndSetDefaults validates the service's configuration and sets the default value of fields that have one func (service *Service) ValidateAndSetDefaults() { // Set default values if service.Interval == 0 { @@ -83,7 +84,8 @@ func (service *Service) ValidateAndSetDefaults() { } } -func (service *Service) EvaluateConditions() *Result { +// EvaluateHealth sends a request to the service's URL and evaluates the conditions of the service. +func (service *Service) EvaluateHealth() *Result { result := &Result{Success: true, Errors: []string{}} service.getIp(result) if len(result.Errors) == 0 { diff --git a/core/service_test.go b/core/service_test.go index f45f8189..94694d5b 100644 --- a/core/service_test.go +++ b/core/service_test.go @@ -4,14 +4,14 @@ import ( "testing" ) -func TestIntegrationEvaluateConditions(t *testing.T) { +func TestIntegrationEvaluateHealth(t *testing.T) { condition := Condition("[STATUS] == 200") service := Service{ Name: "TwiNNatioN", Url: "https://twinnation.org/health", Conditions: []*Condition{&condition}, } - result := service.EvaluateConditions() + result := service.EvaluateHealth() if !result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a success", condition) } @@ -20,14 +20,14 @@ func TestIntegrationEvaluateConditions(t *testing.T) { } } -func TestIntegrationEvaluateConditionsWithFailure(t *testing.T) { +func TestIntegrationEvaluateHealthWithFailure(t *testing.T) { condition := Condition("[STATUS] == 500") service := Service{ Name: "TwiNNatioN", Url: "https://twinnation.org/health", Conditions: []*Condition{&condition}, } - result := service.EvaluateConditions() + result := service.EvaluateHealth() if result.ConditionResults[0].Success { t.Errorf("Condition '%s' should have been a failure", condition) } diff --git a/watchdog/watchdog.go b/watchdog/watchdog.go index 246e7bd6..840a0e9f 100644 --- a/watchdog/watchdog.go +++ b/watchdog/watchdog.go @@ -50,7 +50,7 @@ func monitor(service *core.Service) { if cfg.Debug { log.Printf("[watchdog][monitor] Monitoring serviceName=%s", service.Name) } - result := service.EvaluateConditions() + result := service.EvaluateHealth() metric.PublishMetricsForService(service, result) serviceResultsMutex.Lock() serviceResults[service.Name] = append(serviceResults[service.Name], result)