forked from operator-framework/operator-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
28 lines (24 loc) · 831 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package sdk
import (
"net/http"
"strconv"
k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
)
// ExposeMetricsPort generate a Kubernetes Service to expose metrics port
func ExposeMetricsPort() {
http.Handle("/"+k8sutil.PrometheusMetricsPortName, promhttp.Handler())
go http.ListenAndServe(":"+strconv.Itoa(k8sutil.PrometheusMetricsPort), nil)
service, err := k8sutil.InitOperatorService()
if err != nil {
logrus.Fatalf("Failed to init operator service: %v", err)
}
err = Create(service)
if err != nil && !errors.IsAlreadyExists(err) {
logrus.Infof("Failed to create operator service: %v", err)
return
}
logrus.Infof("Metrics service %s created", service.Name)
}