Skip to content

Commit

Permalink
Log what backends are added/changed/removed on reload.
Browse files Browse the repository at this point in the history
  • Loading branch information
fancycode committed Oct 6, 2020
1 parent cd4d930 commit 5797111
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/signaling/backend_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,30 +120,44 @@ func NewBackendConfiguration(config *goconf.ConfigFile) (*BackendConfiguration,
}, nil
}

func (b *BackendConfiguration) RemoveBackend(host string) {
func (b *BackendConfiguration) RemoveBackendsForHost(host string) {
if oldBackends := b.backends[host]; len(oldBackends) > 0 {
for _, backend := range oldBackends {
log.Printf("Backend %s removed for %s", backend.id, backend.url)
}
}
delete(b.backends, host)
}

func (b *BackendConfiguration) UpsertHost(host string, backends []*Backend) {
existingIndex := 0
for _, existingBackend := range b.backends[host] {
for existingIndex, existingBackend := range b.backends[host] {
found := false
index := 0
for _, newBackend := range backends {
if reflect.DeepEqual(existingBackend, newBackend) { // otherwise we could manually compare the struct members here
found = true
backends = append(backends[:index], backends[index+1:]...)
break
} else if newBackend.id == existingBackend.id {
found = true
b.backends[host][existingIndex] = newBackend
backends = append(backends[:index], backends[index+1:]...)
log.Printf("Backend %s updated for %s", newBackend.id, newBackend.url)
break
}
index++
}
if !found {
removed := b.backends[host][existingIndex]
log.Printf("Backend %s removed for %s", removed.id, removed.url)
b.backends[host] = append(b.backends[host][:existingIndex], b.backends[host][existingIndex+1:]...)
}
existingIndex++
}

b.backends[host] = append(b.backends[host], backends...)
for _, added := range backends {
log.Printf("Backend %s added for %s", added.id, added.url)
}
}

func getConfiguredBackendIDs(backendIds string) (ids []string) {
Expand Down Expand Up @@ -211,7 +225,7 @@ func (b *BackendConfiguration) Reload(config *goconf.ConfigFile) {
// remove backends that are no longer configured
for hostname := range b.backends {
if _, ok := configuredHosts[hostname]; !ok {
b.RemoveBackend(hostname)
b.RemoveBackendsForHost(hostname)
}
}

Expand Down

0 comments on commit 5797111

Please sign in to comment.