From c32a7b2a866224efa6a200e115df1fd04267436f Mon Sep 17 00:00:00 2001 From: Richard Kettelerij Date: Fri, 21 Jun 2024 14:26:51 +0200 Subject: [PATCH] fix(pingdom): implement cut off for too long tags --- internal/service/providers/pingdom.go | 18 +++++++++++------- internal/service/providers/pingdom_test.go | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/service/providers/pingdom.go b/internal/service/providers/pingdom.go index 969f38b..d62190a 100644 --- a/internal/service/providers/pingdom.go +++ b/internal/service/providers/pingdom.go @@ -194,9 +194,19 @@ func (m *PingdomUptimeProvider) checkToJSON(check model.UptimeCheck, includeType relativeURL += "?" + checkURL.RawQuery } - // add the check id (from the k8s annotation) as a tag, so we can latter retrieve the check it during update or delete. + // add the check id (from the k8s annotation) as a tag, so + // we can latter retrieve the check during update or delete. check.Tags = append(check.Tags, customIDPrefix+check.ID) + // tags can be at most 64 chars long, cut off longer ones + for k := range check.Tags { + tag := check.Tags[k] + if len(tag) > 64 { + tag = tag[:64] + } + check.Tags[k] = tag + } + message := map[string]any{ "name": check.Name, "host": checkURL.Hostname(), @@ -210,9 +220,6 @@ func (m *PingdomUptimeProvider) checkToJSON(check model.UptimeCheck, includeType // update messages shouldn't include 'type', since the type of check can't be modified in Pingdom. message["type"] = "http" } - if check.Tags != nil && len(check.Tags) > 0 { - message["tags"] = check.Tags - } if m.settings.UserIDs != nil && len(m.settings.UserIDs) > 0 { message["userids"] = m.settings.UserIDs } @@ -284,9 +291,6 @@ func handleRateLimits(ctx context.Context, rateLimitHeader string) error { } func parseRateLimitHeader(header string) (remaining int, resetTime int, err error) { - if header == "" { - return 0, 0, nil - } _, err = fmt.Sscanf(header, "Remaining: %d Time until reset: %d", &remaining, &resetTime) return } diff --git a/internal/service/providers/pingdom_test.go b/internal/service/providers/pingdom_test.go index 7c63ef9..bc438ab 100644 --- a/internal/service/providers/pingdom_test.go +++ b/internal/service/providers/pingdom_test.go @@ -26,7 +26,7 @@ func TestAgainstREALPingdomAPI(t *testing.T) { "uptime.pdok.nl/id": "3w2e9d804b2cd6bf18b8c0a6e1c04e46ac62b98c", "uptime.pdok.nl/name": "UptimeOperatorPingdomTestCheck", "uptime.pdok.nl/url": "https://service.pdok.nl/cbs/landuse/wfs/v1_0?request=GetCapabilities&service=WFS", - "uptime.pdok.nl/tags": "tag1, tag2", + "uptime.pdok.nl/tags": "tag1, tag2, TooLongTagOvEtj8xOzZmGPJNf5ZcGikHzTjAG55xvcWVymItA0O8Us9tq6fEAfRYeN6AODj2gwRRi5l", "uptime.pdok.nl/request-headers": "key1:value1, key2:value2", "uptime.pdok.nl/response-check-for-string-contains": "bla", "uptime.pdok.nl/response-check-for-string-not-contains": "",