Skip to content

Commit

Permalink
fix(metrics): create another endpoint for prometheus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jeff Peeler committed Dec 19, 2018
1 parent c53c51a commit 99d05f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
10 changes: 10 additions & 0 deletions cmd/catalog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"strings"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"

"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
)

Expand Down Expand Up @@ -45,6 +47,10 @@ var (
version = flag.Bool("version", false, "displays olm version")
)

func init() {
metrics.RegisterCatalog()
}

func main() {
stopCh := signals.SetupSignalHandler()

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

http.Handle("/metrics", promhttp.Handler())
go http.ListenAndServe(":8081", nil)

_, done := catalogOperator.Run(stopCh)
<-done
}

11 changes: 5 additions & 6 deletions cmd/olm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -45,7 +45,7 @@ var (
)

func init() {
metrics.Register()
metrics.RegisterOLM()
}

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

http.Handle("/metrics", promhttp.Handler())
go http.ListenAndServe(":8081", nil)

_, done := operator.Run(stopCh)
<-done
}
9 changes: 6 additions & 3 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ var (
CSVUpgradeCount = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "csv_upgrade_count",
Help: "Monotonic count of catalog sources",
Help: "Monotonic count of CSV upgrades",
},
)
)

func Register() {
func RegisterOLM() {
prometheus.MustRegister(csvCount)
prometheus.MustRegister(CSVUpgradeCount)
}

func RegisterCatalog() {
prometheus.MustRegister(installPlanCount)
prometheus.MustRegister(subscriptionCount)
prometheus.MustRegister(catalogSourceCount)
prometheus.MustRegister(CSVUpgradeCount)
}

0 comments on commit 99d05f9

Please sign in to comment.