File tree Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change 15
15
package metrics
16
16
17
17
import (
18
- "fmt"
19
18
"sync"
20
19
21
20
prom "github.com/prometheus/client_golang/prometheus"
21
+ logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
22
22
)
23
23
24
24
const (
@@ -42,6 +42,7 @@ const (
42
42
43
43
var (
44
44
once sync.Once
45
+ log = logf .Log .WithName ("metrics" )
45
46
)
46
47
47
48
// Collector - metric collector for all the metrics the sdk will watch
@@ -65,15 +66,13 @@ func New() *Collector {
65
66
}
66
67
67
68
// RegisterCollector - add collector safely to prometheus
68
- func RegisterCollector (c * Collector ) error {
69
- errCh := make (chan error )
69
+ func RegisterCollector (c * Collector ) {
70
70
once .Do (func () {
71
- errCh <- prom .Register (c )
71
+ err := prom .Register (c )
72
+ if err != nil {
73
+ log .Error (err , "unable to register collector with prometheus" )
74
+ }
72
75
})
73
- if err := <- errCh ; err != nil {
74
- return fmt .Errorf ("unable to register collector with prometheus: %v" , err )
75
- }
76
- return nil
77
76
}
78
77
79
78
// Describe returns all the descriptions of the collector
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ package sdk
16
16
17
17
import (
18
18
"context"
19
- "fmt"
20
19
"net/http"
21
20
"strconv"
22
21
@@ -33,13 +32,13 @@ import (
33
32
var log = logf .Log .WithName ("metrics" )
34
33
35
34
// ExposeMetricsPort generate a Kubernetes Service to expose metrics port
36
- func ExposeMetricsPort () ( * v1.Service , error ) {
35
+ func ExposeMetricsPort () * v1.Service {
37
36
http .Handle ("/" + k8sutil .PrometheusMetricsPortName , promhttp .Handler ())
38
37
go http .ListenAndServe (":" + strconv .Itoa (k8sutil .PrometheusMetricsPort ), nil )
39
38
40
39
service , err := k8sutil .InitOperatorService ()
41
40
if err != nil {
42
- return nil , fmt . Errorf ( "failed to initialize service object for operator metrics: %v" , err )
41
+ return nil
43
42
}
44
43
kubeconfig , err := config .GetConfig ()
45
44
if err != nil {
@@ -51,9 +50,9 @@ func ExposeMetricsPort() (*v1.Service, error) {
51
50
}
52
51
err = runtimeClient .Create (context .TODO (), service )
53
52
if err != nil && ! errors .IsAlreadyExists (err ) {
54
- return nil , fmt . Errorf ( "failed to create service for operator metrics: %v" , err )
53
+ return nil
55
54
}
56
55
57
56
log .Info ("Metrics service created." , "ServiceName" , service .Name )
58
- return service , nil
57
+ return service
59
58
}
You can’t perform that action at this time.
0 commit comments