Skip to content

Commit f1c0989

Browse files
author
Jeff Peeler
committed
fix(metrics): create another endpoint for prometheus
Make the resources that are updated by the catalog operator be served from there too (and remove them from olm). Update the prometheus http handler to use the non-deprecated version, and do it on port 8081. Also, actually serve the health check in OLM.
1 parent 4748249 commit f1c0989

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

cmd/catalog/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"strings"
99
"time"
1010

11+
"github.com/prometheus/client_golang/prometheus/promhttp"
1112
log "github.com/sirupsen/logrus"
1213
v1 "k8s.io/api/core/v1"
1314

1415
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
1516
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
17+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
1618
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
1719
)
1820

@@ -45,6 +47,10 @@ var (
4547
version = flag.Bool("version", false, "displays olm version")
4648
)
4749

50+
func init() {
51+
metrics.RegisterCatalog()
52+
}
53+
4854
func main() {
4955
stopCh := signals.SetupSignalHandler()
5056

@@ -87,6 +93,10 @@ func main() {
8793
log.Panicf("error configuring operator: %s", err.Error())
8894
}
8995

96+
http.Handle("/metrics", promhttp.Handler())
97+
go http.ListenAndServe(":8081", nil)
98+
9099
_, done := catalogOperator.Run(stopCh)
91100
<-done
92101
}
102+

cmd/olm/main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/prometheus/client_golang/prometheus"
11+
"github.com/prometheus/client_golang/prometheus/promhttp"
1212
log "github.com/sirupsen/logrus"
1313
v1 "k8s.io/api/core/v1"
1414

@@ -45,7 +45,7 @@ var (
4545
)
4646

4747
func init() {
48-
metrics.Register()
48+
metrics.RegisterOLM()
4949
}
5050

5151
// main function - entrypoint to OLM operator
@@ -100,12 +100,11 @@ func main() {
100100
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
101101
w.WriteHeader(http.StatusOK)
102102
})
103-
// TODO: both of the following require vendor updates (add k8s.io/apiserver and update prometheus)
104-
//healthz.InstallHandler(mux) //(less code)
105-
//mux.Handle("/metrics", promhttp.Handler()) //other form is deprecated
106-
http.Handle("/metrics", prometheus.Handler())
107103
go http.ListenAndServe(":8080", nil)
108104

105+
http.Handle("/metrics", promhttp.Handler())
106+
go http.ListenAndServe(":8081", nil)
107+
109108
_, done := operator.Run(stopCh)
110109
<-done
111110
}

pkg/metrics/metrics.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,18 @@ var (
129129
CSVUpgradeCount = prometheus.NewCounter(
130130
prometheus.CounterOpts{
131131
Name: "csv_upgrade_count",
132-
Help: "Monotonic count of catalog sources",
132+
Help: "Monotonic count of CSV upgrades",
133133
},
134134
)
135135
)
136136

137-
func Register() {
137+
func RegisterOLM() {
138138
prometheus.MustRegister(csvCount)
139+
prometheus.MustRegister(CSVUpgradeCount)
140+
}
141+
142+
func RegisterCatalog() {
139143
prometheus.MustRegister(installPlanCount)
140144
prometheus.MustRegister(subscriptionCount)
141145
prometheus.MustRegister(catalogSourceCount)
142-
prometheus.MustRegister(CSVUpgradeCount)
143146
}

0 commit comments

Comments
 (0)