From babc7f9f07035c7c07dd6984a3273db9944494ac Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Thu, 29 Oct 2020 17:18:43 -0400 Subject: [PATCH 1/4] Fix issue with displayed condition when condition uses len() --- core/condition.go | 6 +++++- core/condition_test.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/condition.go b/core/condition.go index cd3ce9a7..ec2c7931 100644 --- a/core/condition.go +++ b/core/condition.go @@ -155,7 +155,11 @@ func sanitizeAndResolve(list []string, result *Result) []string { if err.Error() != "unexpected end of JSON input" { result.Errors = append(result.Errors, err.Error()) } - element = fmt.Sprintf("%s %s", element, InvalidConditionElementSuffix) + if wantLength { + element = fmt.Sprintf("len(%s) %s", element, InvalidConditionElementSuffix) + } else { + element = fmt.Sprintf("%s %s", element, InvalidConditionElementSuffix) + } } else { if wantLength { element = fmt.Sprintf("%d", resolvedElementLength) diff --git a/core/condition_test.go b/core/condition_test.go index 45be961a..5ec95e25 100644 --- a/core/condition_test.go +++ b/core/condition_test.go @@ -126,6 +126,19 @@ func TestCondition_evaluateWithInvalidBodyJSONPathComplex(t *testing.T) { } } +func TestCondition_evaluateWithInvalidBodyJSONPathComplexWithLengthFunction(t *testing.T) { + expectedResolvedCondition := "len([BODY].data.name) (INVALID) == john" + condition := Condition("len([BODY].data.name) == john") + result := &Result{Body: []byte("{\"data\": {\"id\": 1}}")} + condition.evaluate(result) + if result.ConditionResults[0].Success { + t.Errorf("Condition '%s' should have been a failure, because the path was invalid", condition) + } + if result.ConditionResults[0].Condition != expectedResolvedCondition { + t.Errorf("Condition '%s' should have resolved to '%s', but resolved to '%s' instead", condition, expectedResolvedCondition, result.ConditionResults[0].Condition) + } +} + func TestCondition_evaluateWithBodyJSONPathDoublePlaceholders(t *testing.T) { condition := Condition("[BODY].user.firstName != [BODY].user.lastName") result := &Result{Body: []byte("{\"user\": {\"firstName\": \"john\", \"lastName\": \"doe\"}}")} From 206649755334f6252de3e5a8fe8374a8e21d47a1 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Fri, 30 Oct 2020 09:50:40 -0400 Subject: [PATCH 2/4] Set MaxIdleConns and MaxIdleConnsPerHost to 100 and 20 respectively --- client/client.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/client.go b/client/client.go index 1dad7832..8daaa246 100644 --- a/client/client.go +++ b/client/client.go @@ -19,6 +19,8 @@ func GetHTTPClient(insecure bool) *http.Client { insecureHTTPClient = &http.Client{ Timeout: time.Second * 10, Transport: &http.Transport{ + MaxIdleConns: 100, + MaxIdleConnsPerHost: 20, TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, From 835704bf8a7dbe6888d4ba7fdeb5b825ea5bc326 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Fri, 30 Oct 2020 09:51:42 -0400 Subject: [PATCH 3/4] Set MaxIdleConns and MaxIdleConnsPerHost to 100 and 20 respectively --- client/client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/client.go b/client/client.go index 8daaa246..cb8df091 100644 --- a/client/client.go +++ b/client/client.go @@ -32,6 +32,10 @@ func GetHTTPClient(insecure bool) *http.Client { if secureHTTPClient == nil { secureHTTPClient = &http.Client{ Timeout: time.Second * 10, + Transport: &http.Transport{ + MaxIdleConns: 100, + MaxIdleConnsPerHost: 20, + }, } } return secureHTTPClient From 38c76aefc2bd08e434ed6b1b11b29aa0a26ec7d5 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Mon, 2 Nov 2020 22:43:55 -0500 Subject: [PATCH 4/4] Validate interface implementation on compile --- alerting/provider/provider.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/alerting/provider/provider.go b/alerting/provider/provider.go index 41e8b0fd..06be60c6 100644 --- a/alerting/provider/provider.go +++ b/alerting/provider/provider.go @@ -2,6 +2,9 @@ package provider import ( "github.com/TwinProduction/gatus/alerting/provider/custom" + "github.com/TwinProduction/gatus/alerting/provider/pagerduty" + "github.com/TwinProduction/gatus/alerting/provider/slack" + "github.com/TwinProduction/gatus/alerting/provider/twilio" "github.com/TwinProduction/gatus/core" ) @@ -13,3 +16,11 @@ type AlertProvider interface { // ToCustomAlertProvider converts the provider into a custom.AlertProvider ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *custom.AlertProvider } + +var ( + // Validate interface implementation on compile + _ AlertProvider = (*custom.AlertProvider)(nil) + _ AlertProvider = (*twilio.AlertProvider)(nil) + _ AlertProvider = (*slack.AlertProvider)(nil) + _ AlertProvider = (*pagerduty.AlertProvider)(nil) +)