Rename service's EvaluateConditions() to EvaluateHealth()

This commit is contained in:
TwinProduction
2020-09-24 19:49:32 -04:00
parent 286e8f8590
commit 59fed008e0
3 changed files with 8 additions and 6 deletions

View File

@ -50,6 +50,7 @@ type Service struct {
NumberOfSuccessesInARow int NumberOfSuccessesInARow int
} }
// ValidateAndSetDefaults validates the service's configuration and sets the default value of fields that have one
func (service *Service) ValidateAndSetDefaults() { func (service *Service) ValidateAndSetDefaults() {
// Set default values // Set default values
if service.Interval == 0 { 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{}} result := &Result{Success: true, Errors: []string{}}
service.getIp(result) service.getIp(result)
if len(result.Errors) == 0 { if len(result.Errors) == 0 {

View File

@ -4,14 +4,14 @@ import (
"testing" "testing"
) )
func TestIntegrationEvaluateConditions(t *testing.T) { func TestIntegrationEvaluateHealth(t *testing.T) {
condition := Condition("[STATUS] == 200") condition := Condition("[STATUS] == 200")
service := Service{ service := Service{
Name: "TwiNNatioN", Name: "TwiNNatioN",
Url: "https://twinnation.org/health", Url: "https://twinnation.org/health",
Conditions: []*Condition{&condition}, Conditions: []*Condition{&condition},
} }
result := service.EvaluateConditions() result := service.EvaluateHealth()
if !result.ConditionResults[0].Success { if !result.ConditionResults[0].Success {
t.Errorf("Condition '%s' should have been a success", condition) 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") condition := Condition("[STATUS] == 500")
service := Service{ service := Service{
Name: "TwiNNatioN", Name: "TwiNNatioN",
Url: "https://twinnation.org/health", Url: "https://twinnation.org/health",
Conditions: []*Condition{&condition}, Conditions: []*Condition{&condition},
} }
result := service.EvaluateConditions() result := service.EvaluateHealth()
if result.ConditionResults[0].Success { if result.ConditionResults[0].Success {
t.Errorf("Condition '%s' should have been a failure", condition) t.Errorf("Condition '%s' should have been a failure", condition)
} }

View File

@ -50,7 +50,7 @@ func monitor(service *core.Service) {
if cfg.Debug { if cfg.Debug {
log.Printf("[watchdog][monitor] Monitoring serviceName=%s", service.Name) log.Printf("[watchdog][monitor] Monitoring serviceName=%s", service.Name)
} }
result := service.EvaluateConditions() result := service.EvaluateHealth()
metric.PublishMetricsForService(service, result) metric.PublishMetricsForService(service, result)
serviceResultsMutex.Lock() serviceResultsMutex.Lock()
serviceResults[service.Name] = append(serviceResults[service.Name], result) serviceResults[service.Name] = append(serviceResults[service.Name], result)