diff --git a/cmd/converge/notifier.go b/cmd/converge/notifier.go index 241b804..87eb9bb 100644 --- a/cmd/converge/notifier.go +++ b/cmd/converge/notifier.go @@ -15,6 +15,6 @@ func NewStateNotifier() *StateNotifier { } func (notifier StateNotifier) Publish(state *models.State) { - notifier.webNotificationChannel <- state - notifier.prometheusNotificationChannel <- state + notifier.webNotificationChannel <- state.Copy() + notifier.prometheusNotificationChannel <- state.Copy() } diff --git a/pkg/models/state.go b/pkg/models/state.go index 74c7aa5..74044fc 100644 --- a/pkg/models/state.go +++ b/pkg/models/state.go @@ -1,6 +1,18 @@ package models +// State is a description of the current state of converge. +// Created by the server and used for updating the web client +// and prometheus metrics. type State struct { Agents []Agent Clients []Client } + +func (state *State) Copy() *State { + c := State{} + c.Agents = make([]Agent, len(state.Agents)) + c.Clients = make([]Client, len(state.Clients)) + copy(c.Agents, state.Agents) + copy(c.Clients, state.Clients) + return &c +}