Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statuscake: Implement Equals function using TestTags #610

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/monitors/statuscake/statuscake-mappers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package statuscake

import (
"strings"

statuscake "github.com/StatusCakeDev/statuscake-go"
endpointmonitorv1alpha1 "github.com/stakater/IngressMonitorController/v2/api/v1alpha1"
"github.com/stakater/IngressMonitorController/v2/pkg/models"
)

Expand All @@ -11,6 +14,10 @@ func StatusCakeMonitorMonitorToBaseMonitorMapper(statuscakeData StatusCakeMonito
m.Name = statuscakeData.WebsiteName
m.URL = statuscakeData.WebsiteURL
m.ID = statuscakeData.TestID

var providerConfig endpointmonitorv1alpha1.StatusCakeConfig
providerConfig.TestTags = strings.Join(statuscakeData.Tags, ",")
m.Config = &providerConfig
return &m
}

Expand All @@ -20,6 +27,10 @@ func StatusCakeApiResponseDataToBaseMonitorMapper(statuscakeData statuscake.Upti
m.Name = statuscakeData.Data.Name
m.URL = statuscakeData.Data.WebsiteURL
m.ID = statuscakeData.Data.ID

var providerConfig endpointmonitorv1alpha1.StatusCakeConfig
providerConfig.TestTags = strings.Join(statuscakeData.Data.Tags, ",")
m.Config = &providerConfig
return &m
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/monitors/statuscake/statuscake-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ type StatusCakeMonitorService struct {
}

func (monitor *StatusCakeMonitorService) Equal(oldMonitor models.Monitor, newMonitor models.Monitor) bool {
// TODO: Retrieve oldMonitor config and compare it here
return false
// Since there is a discrepency between the fields in the endpointmonitor CR and the statuscake API
// use the tags to define a last updated by tags. This ensures we are not ratelimited by statuscake.
oldConf := oldMonitor.Config.(*endpointmonitorv1alpha1.StatusCakeConfig)
newConf := newMonitor.Config.(*endpointmonitorv1alpha1.StatusCakeConfig)
if oldConf.TestTags != newConf.TestTags {
msg := "Found a difference between the old TestTags and new TestTags. Updating the UptimeCheck..."
log.Info(msg, "Old Tags", oldConf.TestTags, "New Tags", newConf.TestTags)
return false
} else {
return true
}
}

// buildUpsertForm function is used to create the form needed to Add or update a monitor
Expand Down Expand Up @@ -199,7 +208,7 @@ func buildUpsertForm(m models.Monitor, cgroup string) url.Values {
if providerConfig != nil && providerConfig.Confirmation > 0 {
f.Add("confirmation", strconv.Itoa(providerConfig.Confirmation))
}
if providerConfig != nil {
if providerConfig != nil && len(providerConfig.FindString) > 0 {
f.Add("find_string", providerConfig.FindString)
}
return f
Expand Down
Loading