Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Commit 65e34ad

Browse files
committed
improves logging
1 parent bee792b commit 65e34ad

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

registrator.go

+34-15
Original file line numberDiff line numberDiff line change
@@ -140,36 +140,56 @@ func (r *registrator) handler(eventType watch.EventType, oldIngress *v1beta1.Ing
140140
switch eventType {
141141
case watch.Added:
142142
log.Printf("[DEBUG] received %s event for %s", eventType, newIngress.Name)
143+
metricUpdatesReceived.WithLabelValues(newIngress.Name, "add").Inc()
143144
hostnames := getHostnamesFromIngress(newIngress)
144145
target := r.getTargetForIngress(newIngress)
145-
metricUpdatesReceived.WithLabelValues(newIngress.Name, "add").Inc()
146-
if len(hostnames) > 0 && target != "" {
147-
log.Printf("[DEBUG] queued update of %d record(s) for ingress %s, pointing to %s", len(hostnames), newIngress.Name, target)
146+
if target == "" {
147+
log.Printf("[INFO] invalid ingress target for new ingress %s: %s", newIngress.Name, newIngress.Labels[r.options.TargetLabelName])
148+
} else if len(hostnames) == 0 {
149+
log.Printf("[INFO] could not extract hostnames from new ingress %s", newIngress.Name)
150+
} else {
151+
log.Printf("[DEBUG] queued update of %d record(s) for new ingress %s, pointing to %s", len(hostnames), newIngress.Name, target)
148152
r.queueUpdates(route53.ChangeActionUpsert, hostnames, target)
149153
}
150154
case watch.Modified:
151-
log.Printf("[DEBUG] received %s event for %s -> %s", eventType, oldIngress.Name, newIngress.Name)
155+
log.Printf("[DEBUG] received %s event for %s", eventType, newIngress.Name)
156+
metricUpdatesReceived.WithLabelValues(newIngress.Name, "modify").Inc()
152157
newHostnames := getHostnamesFromIngress(newIngress)
153158
newTarget := r.getTargetForIngress(newIngress)
154-
metricUpdatesReceived.WithLabelValues(newIngress.Name, "modify").Inc()
155-
if len(newHostnames) > 0 && newTarget != "" {
156-
log.Printf("[DEBUG] queued update of %d record(s) for ingress %s, pointing to %s", len(newHostnames), newIngress.Name, newTarget)
157-
r.queueUpdates(route53.ChangeActionUpsert, newHostnames, newTarget)
158-
}
159159
oldHostnames := getHostnamesFromIngress(oldIngress)
160160
oldTarget := r.getTargetForIngress(oldIngress)
161161
diffHostnames := diffStringSlices(oldHostnames, newHostnames)
162-
if len(diffHostnames) > 0 && oldTarget != "" {
163-
log.Printf("[DEBUG] queued deletion of %d record(s) for ingress %s", len(diffHostnames), oldIngress.Name)
162+
if len(diffHostnames) == 0 && newIngress.Labels[r.options.TargetLabelName] == oldIngress.Labels[r.options.TargetLabelName] {
163+
log.Printf("[DEBUG] no changes for ingress %s, looks like a no-op resync", newIngress.Name)
164+
break
165+
}
166+
if newTarget == "" {
167+
log.Printf("[INFO] invalid ingress target for modified ingress %s: %s", newIngress.Name, newIngress.Labels[r.options.TargetLabelName])
168+
} else if len(newHostnames) == 0 {
169+
log.Printf("[INFO] could not extract hostnames from modified ingress %s", newIngress.Name)
170+
} else {
171+
log.Printf("[DEBUG] queued update of %d record(s) for modified ingress %s, pointing to %s", len(newHostnames), newIngress.Name, newTarget)
172+
r.queueUpdates(route53.ChangeActionUpsert, newHostnames, newTarget)
173+
}
174+
if oldTarget == "" {
175+
log.Printf("[INFO] invalid ingress target for previous ingress %s: %s", oldIngress.Name, oldIngress.Labels[r.options.TargetLabelName])
176+
} else if len(diffHostnames) == 0 {
177+
log.Printf("[DEBUG] no difference in hostnames from previous ingress %s", oldIngress.Name)
178+
} else {
179+
log.Printf("[DEBUG] queued deletion of %d record(s) for previous ingress %s", len(diffHostnames), oldIngress.Name)
164180
r.queueUpdates(route53.ChangeActionDelete, diffHostnames, oldTarget)
165181
}
166182
case watch.Deleted:
167183
log.Printf("[DEBUG] received %s event for %s", eventType, oldIngress.Name)
184+
metricUpdatesReceived.WithLabelValues(oldIngress.Name, "delete").Inc()
168185
hostnames := getHostnamesFromIngress(oldIngress)
169186
target := r.getTargetForIngress(oldIngress)
170-
metricUpdatesReceived.WithLabelValues(oldIngress.Name, "delete").Inc()
171-
if len(hostnames) > 0 && target != "" {
172-
log.Printf("[DEBUG] queued deletion of %d record(s) for ingress %s", len(hostnames), oldIngress.Name)
187+
if target == "" {
188+
log.Printf("[INFO] invalid ingress target for old ingress %s: %s", oldIngress.Name, oldIngress.Labels[r.options.TargetLabelName])
189+
} else if len(hostnames) == 0 {
190+
log.Printf("[INFO] could not extract hostnames from old ingress %s", oldIngress.Name)
191+
} else {
192+
log.Printf("[DEBUG] queued deletion of %d record(s) for old ingress %s", len(hostnames), oldIngress.Name)
173193
r.queueUpdates(route53.ChangeActionDelete, hostnames, target)
174194
}
175195
default:
@@ -256,7 +276,6 @@ func (r *registrator) getTargetForIngress(ingress *v1beta1.Ingress) string {
256276
return sat.Target
257277
}
258278
}
259-
log.Printf("[INFO] invalid ingress target for %s: %s", ingress.Name, ingress.Labels[r.options.TargetLabelName])
260279
return ""
261280
}
262281

0 commit comments

Comments
 (0)