Skip to content

Commit

Permalink
Fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
pleshakov committed Nov 5, 2021
1 parent 4b8eb16 commit 6b2e372
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
4 changes: 4 additions & 0 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,10 @@ func (lbc *LoadBalancerController) updateVirtualServerMetrics() {
}

func (lbc *LoadBalancerController) updateTransportServerMetrics() {
if !lbc.areCustomResourcesEnabled {
return
}

metrics := lbc.configuration.GetTransportServerMetrics()
lbc.metricsCollector.SetTransportServers(metrics.TotalTLSPassthrough, metrics.TotalTCP, metrics.TotalUDP)
}
Expand Down
71 changes: 38 additions & 33 deletions internal/metrics/collectors/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,56 @@ func NewControllerMetricsCollector(crdsEnabled bool, constLabels map[string]stri
labelNamesController,
)

if !crdsEnabled {
return &ControllerMetricsCollector{ingressesTotal: ingResTotal}
var vsResTotal, vsrResTotal prometheus.Gauge
var tsResTotal *prometheus.GaugeVec

if crdsEnabled {
vsResTotal = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "virtualserver_resources_total",
Namespace: metricsNamespace,
Help: "Number of handled VirtualServer resources",
ConstLabels: constLabels,
},
)

vsrResTotal = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "virtualserverroute_resources_total",
Namespace: metricsNamespace,
Help: "Number of handled VirtualServerRoute resources",
ConstLabels: constLabels,
},
)

tsResTotal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "transportserver_resources_total",
Namespace: metricsNamespace,
Help: "Number of handled TransportServer resources",
ConstLabels: constLabels,
},
labelNamesController,
)
}

vsResTotal := prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "virtualserver_resources_total",
Namespace: metricsNamespace,
Help: "Number of handled VirtualServer resources",
ConstLabels: constLabels,
},
)

vsrResTotal := prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "virtualserverroute_resources_total",
Namespace: metricsNamespace,
Help: "Number of handled VirtualServerRoute resources",
ConstLabels: constLabels,
},
)

tsResTotal := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "transportserver_resources_total",
Namespace: metricsNamespace,
Help: "Number of handled TransportServer resources",
ConstLabels: constLabels,
},
labelNamesController,
)

c := &ControllerMetricsCollector{
crdsEnabled: true,
crdsEnabled: crdsEnabled,
ingressesTotal: ingResTotal,
virtualServersTotal: vsResTotal,
virtualServerRoutesTotal: vsrResTotal,
transportServersTotal: tsResTotal,
}

// if we don't set to 0 metrics with types, the metrics will not be created initially
// if we don't set to 0 metrics with the label type, the metrics will not be created initially

c.SetIngresses("regular", 0)
c.SetIngresses("master", 0)
c.SetIngresses("minion", 0)
c.SetTransportServers(0, 0, 0)

if crdsEnabled {
c.SetTransportServers(0, 0, 0)
}

return c
}
Expand Down

0 comments on commit 6b2e372

Please sign in to comment.