Skip to content

Commit

Permalink
Merge pull request #4 from PDOK/cutoff
Browse files Browse the repository at this point in the history
fix(pingdom): implement cut off for too long tags
  • Loading branch information
rkettelerij authored Jun 21, 2024
2 parents 2319bfd + c32a7b2 commit 9d706c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions internal/service/providers/pingdom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/providers/pingdom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down

0 comments on commit 9d706c6

Please sign in to comment.