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

Improve checking against blacklist by reducing the number of calls to KV #167

Merged
merged 1 commit into from
Feb 3, 2017
Merged
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
26 changes: 15 additions & 11 deletions consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,10 @@ func (c *ConsulAlertClient) UpdateCheckData() {
}
if settodelete {
log.Printf("Reminder %s %s needs to be deleted, stale", node, check)
c.DeleteReminder(node, check)
c.DeleteReminder(node, check)
}
}


for _, health := range healths {

node := health.Node
Expand Down Expand Up @@ -656,26 +655,31 @@ func (c *ConsulAlertClient) GetProfileInfo(node, serviceID, checkID string) (not

// IsBlacklisted gets the blacklist status of check
func (c *ConsulAlertClient) IsBlacklisted(check *Check) bool {
blacklistExist := func() bool {
kvPairs, _, err := c.api.KV().List("consul-alerts/config/checks/blacklist/", nil)
return len(kvPairs) != 0 && err == nil
}

node := check.Node
nodeCheckKey := fmt.Sprintf("consul-alerts/config/checks/blacklist/nodes/%s", node)
nodeBlacklisted := c.CheckKeyExists(nodeCheckKey)
nodeBlacklisted := func() bool { return c.CheckKeyExists(nodeCheckKey) }

service := "_"
serviceBlacklisted := false
serviceBlacklisted := func() bool { return false }
if check.ServiceID != "" {
service = check.ServiceID
serviceCheckKey := fmt.Sprintf("consul-alerts/config/checks/blacklist/services/%s", service)
serviceBlacklisted = c.CheckKeyExists(serviceCheckKey)
serviceBlacklisted = func() bool { return c.CheckKeyExists(serviceCheckKey) }
}

checkId := check.CheckID
checkCheckKey := fmt.Sprintf("consul-alerts/config/checks/blacklist/checks/%s", checkId)
checkBlacklisted := c.CheckKeyExists(checkCheckKey)
checkID := check.CheckID
checkCheckKey := fmt.Sprintf("consul-alerts/config/checks/blacklist/checks/%s", checkID)
checkBlacklisted := func() bool { return c.CheckKeyExists(checkCheckKey) }

singleKey := fmt.Sprintf("consul-alerts/config/checks/blacklist/single/%s/%s/%s", node, service, checkId)
singleBlacklisted := c.CheckKeyExists(singleKey)
singleKey := fmt.Sprintf("consul-alerts/config/checks/blacklist/single/%s/%s/%s", node, service, checkID)
singleBlacklisted := func() bool { return c.CheckKeyExists(singleKey) }

return nodeBlacklisted || serviceBlacklisted || checkBlacklisted || singleBlacklisted
return blacklistExist() && (nodeBlacklisted() || serviceBlacklisted() || checkBlacklisted() || singleBlacklisted())
}

func (c *ConsulAlertClient) CheckKeyExists(key string) bool {
Expand Down