Skip to content

Commit

Permalink
Only report VS/VSRs handled by the Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean-Coakley committed Oct 15, 2019
1 parent 4bfe9aa commit ecb479c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
18 changes: 18 additions & 0 deletions internal/configs/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Configurator struct {
templateExecutorV2 *version2.TemplateExecutor
ingresses map[string]*IngressEx
minions map[string]map[string]bool
virtualServers map[string]*VirtualServerEx
isWildcardEnabled bool
isPlus bool
}
Expand All @@ -49,6 +50,7 @@ func NewConfigurator(nginxManager nginx.Manager, staticCfgParams *StaticConfigPa
staticCfgParams: staticCfgParams,
cfgParams: config,
ingresses: make(map[string]*IngressEx),
virtualServers: make(map[string]*VirtualServerEx),
templateExecutor: templateExecutor,
templateExecutorV2: templateExecutorV2,
minions: make(map[string]map[string]bool),
Expand Down Expand Up @@ -170,6 +172,8 @@ func (cnf *Configurator) addOrUpdateVirtualServer(virtualServerEx *VirtualServer
}
cnf.nginxManager.CreateConfig(name, content)

cnf.virtualServers[name] = virtualServerEx

return warnings, nil
}

Expand Down Expand Up @@ -339,6 +343,8 @@ func (cnf *Configurator) DeleteVirtualServer(key string) error {
name := getFileNameForVirtualServerFromKey(key)
cnf.nginxManager.DeleteConfig(name)

delete(cnf.virtualServers, name)

if err := cnf.nginxManager.Reload(); err != nil {
return fmt.Errorf("Error when removing VirtualServer %v: %v", key, err)
}
Expand Down Expand Up @@ -637,3 +643,15 @@ func (cnf *Configurator) GetIngressCounts() map[string]int {

return counters
}

// GetVSCounts returns the total count of Vs/Vsr resources that are handled by the Ingress Controller
func (cnf *Configurator) GetVSCounts() (vsCount int, vsrCount int) {
for _, vs := range cnf.virtualServers {
if vs != nil {
vsCount++
}
vsrCount += len(vs.VirtualServerRoutes)
}

return vsCount, vsrCount
}
12 changes: 4 additions & 8 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func (lbc *LoadBalancerController) sync(task task) {
lbc.updateVsMetrics()
case virtualServerRoute:
lbc.syncVirtualServerRoute(task)
lbc.updateVsrMetrics()
lbc.updateVsMetrics()
}
}

Expand Down Expand Up @@ -854,13 +854,9 @@ func (lbc *LoadBalancerController) updateIngressMetrics() {
}

func (lbc *LoadBalancerController) updateVsMetrics() {
count := len(lbc.getVirtualServers())
lbc.metricsCollector.SetVsResources(count)
}

func (lbc *LoadBalancerController) updateVsrMetrics() {
count := len(lbc.getVirtualServerRoutes())
lbc.metricsCollector.SetVsrResources(count)
vsCount, vsrCount := lbc.configurator.GetVSCounts()
lbc.metricsCollector.SetVsResources(vsCount)
lbc.metricsCollector.SetVsrResources(vsrCount)
}

// syncExternalService does not sync all services.
Expand Down
4 changes: 2 additions & 2 deletions internal/metrics/collectors/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func (cc *ControllerMetricsCollector) SetIngressResources(ingressType string, co
cc.ingressResourcesTotal.WithLabelValues(ingressType).Set(float64(count))
}

// SetVsResources sets the value of the VS resources gauge for a given type
// SetVsResources sets the value of the VS resources gauge
func (cc *ControllerMetricsCollector) SetVsResources(count int) {
cc.vsResourcesTotal.Set(float64(count))
}

// SetVsrResources sets the value of the VSR resources gauge for a given type
// SetVsrResources sets the value of the VSR resources gauge
func (cc *ControllerMetricsCollector) SetVsrResources(count int) {
cc.vsrResourcesTotal.Set(float64(count))
}
Expand Down

0 comments on commit ecb479c

Please sign in to comment.