Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide VS/VSR metrics when CRDs disabled #730

Merged
merged 2 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func main() {
if *enablePrometheusMetrics {
registry = prometheus.NewRegistry()
managerCollector = collectors.NewLocalManagerMetricsCollector()
controllerCollector = collectors.NewControllerMetricsCollector()
controllerCollector = collectors.NewControllerMetricsCollector(*enableCustomResources)

err = managerCollector.Register(registry)
if err != nil {
Expand Down
20 changes: 15 additions & 5 deletions internal/metrics/collectors/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ type ControllerCollector interface {

// ControllerMetricsCollector implements the ControllerCollector interface and prometheus.Collector interface
type ControllerMetricsCollector struct {
crdsEnabled bool
ingressesTotal *prometheus.GaugeVec
virtualServersTotal prometheus.Gauge
virtualServerRoutesTotal prometheus.Gauge
}

// NewControllerMetricsCollector creates a new ControllerMetricsCollector
func NewControllerMetricsCollector() *ControllerMetricsCollector {
func NewControllerMetricsCollector(crdsEnabled bool) *ControllerMetricsCollector {
ingResTotal := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ingress_resources_total",
Expand All @@ -30,6 +31,10 @@ func NewControllerMetricsCollector() *ControllerMetricsCollector {
labelNamesController,
)

if !crdsEnabled {
return &ControllerMetricsCollector{ingressesTotal: ingResTotal}
}

vsResTotal := prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "virtualserver_resources_total",
Expand All @@ -47,6 +52,7 @@ func NewControllerMetricsCollector() *ControllerMetricsCollector {
)

return &ControllerMetricsCollector{
crdsEnabled: true,
ingressesTotal: ingResTotal,
virtualServersTotal: vsResTotal,
virtualServerRoutesTotal: vsrResTotal,
Expand All @@ -71,15 +77,19 @@ func (cc *ControllerMetricsCollector) SetVirtualServerRoutes(count int) {
// Describe implements prometheus.Collector interface Describe method
func (cc *ControllerMetricsCollector) Describe(ch chan<- *prometheus.Desc) {
cc.ingressesTotal.Describe(ch)
cc.virtualServersTotal.Describe(ch)
cc.virtualServerRoutesTotal.Describe(ch)
if cc.crdsEnabled {
cc.virtualServersTotal.Describe(ch)
cc.virtualServerRoutesTotal.Describe(ch)
}
}

// Collect implements the prometheus.Collector interface Collect method
func (cc *ControllerMetricsCollector) Collect(ch chan<- prometheus.Metric) {
cc.ingressesTotal.Collect(ch)
cc.virtualServersTotal.Collect(ch)
cc.virtualServerRoutesTotal.Collect(ch)
if cc.crdsEnabled {
cc.virtualServersTotal.Collect(ch)
cc.virtualServerRoutesTotal.Collect(ch)
}
}

// Register registers all the metrics of the collector
Expand Down