Skip to content

Commit

Permalink
Added better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Cellebyte committed Apr 23, 2024
1 parent 877f59b commit 430a58e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/monitoring/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type basicCollector struct {
logger logr.Logger
}

// only use with Lock called before
// only use with Lock called before.
func (c *basicCollector) clearChannels() {
defer c.mu.Unlock()
c.channels = []chan<- prometheus.Metric{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/monitoring/frr.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ func (c *frrCollector) Update(ch chan<- prometheus.Metric) error {
if len(c.channels) == 1 {
c.wg = sync.WaitGroup{}
c.wg.Add(1)
// Ensure all other function calls will wait
// Ensure all other function calls will wait.
c.mu.Unlock()
routes, neighbors, vrfs := func() ([]route.Information, frr.BGPVrfSummary, []frr.VrfVniSpec) {
return c.getRoutes(), c.getBGPNeighbors(), c.getVrfs()
}()
go func(routes []route.Information, neighbors frr.BGPVrfSummary, vrfs []frr.VrfVniSpec) {
c.mu.Lock()
// unlock is done after return using defer
// unlock is done after return using defer.
defer c.wg.Done()
c.updateChannels(vrfs, routes, neighbors)
}(routes, neighbors, vrfs)
Expand Down
4 changes: 2 additions & 2 deletions pkg/monitoring/nl.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ func (c *netlinkCollector) Update(ch chan<- prometheus.Metric) error {
if len(c.channels) == 1 {
c.wg = sync.WaitGroup{}
c.wg.Add(1)
// Ensure all other function calls will wait
// Ensure all other function calls will wait.
c.mu.Unlock()
routes, neighbors := func() ([]route.Information, []nl.NeighborInformation) {
return c.getRoutes(), c.getNeighbors()
}()
go func(routes []route.Information, neighbors []nl.NeighborInformation) {
c.mu.Lock()
// unlock is done after return using defer
// unlock is done after return using defer.
defer c.wg.Done()
c.updateChannels(neighbors, routes)
}(routes, neighbors)
Expand Down

0 comments on commit 430a58e

Please sign in to comment.