Skip to content

Commit

Permalink
pkg/start: Register metrics directly
Browse files Browse the repository at this point in the history
Pulling this up out of cvo.New() while working to decouple metrics
handling from the core CVO goroutine.
  • Loading branch information
wking committed Apr 21, 2020
1 parent 2d1e35a commit f158967
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 0 additions & 6 deletions pkg/cvo/cvo.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func New(
proxyInformer configinformersv1.ProxyInformer,
client clientset.Interface,
kubeClient kubernetes.Interface,
enableMetrics bool,
exclude string,
) *Operator {
eventBroadcaster := record.NewBroadcaster()
Expand Down Expand Up @@ -214,11 +213,6 @@ func New(
// make sure this is initialized after all the listers are initialized
optr.upgradeableChecks = optr.defaultUpgradeableChecks()

if enableMetrics {
if err := optr.registerMetrics(coInformer.Informer()); err != nil {
panic(err)
}
}
return optr
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/cvo/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
"github.com/openshift/cluster-version-operator/pkg/internal"
)

func (optr *Operator) registerMetrics(coInformer cache.SharedInformer) error {
// RegisterMetrics initializes metrics and registers them with the
// Prometheus implementation.
func (optr *Operator) RegisterMetrics(coInformer cache.SharedInformer) error {
m := newOperatorMetrics(optr)
coInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: m.clusterOperatorChanged,
Expand Down
11 changes: 9 additions & 2 deletions pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ func (o *Options) Run() error {

func (o *Options) run(ctx context.Context, controllerCtx *Context, lock *resourcelock.ConfigMapLock) {
runContext, runCancel := context.WithCancel(ctx)
defer runCancel()
shutdownContext, shutdownCancel := context.WithCancel(ctx)
defer shutdownCancel()
errorChannel := make(chan error, 1)
errorChannelCount := 0
if o.ListenAddr != "" {
Expand Down Expand Up @@ -351,6 +353,7 @@ func (o *Options) NewControllerContext(cb *ClientBuilder) *Context {

sharedInformers := externalversions.NewSharedInformerFactory(client, resyncPeriod(o.ResyncInterval)())

coInformer := sharedInformers.Config().V1().ClusterOperators()
ctx := &Context{
CVInformerFactory: cvInformer,
OpenshiftConfigInformerFactory: openshiftConfigInformer,
Expand All @@ -364,12 +367,11 @@ func (o *Options) NewControllerContext(cb *ClientBuilder) *Context {
o.PayloadOverride,
resyncPeriod(o.ResyncInterval)(),
cvInformer.Config().V1().ClusterVersions(),
sharedInformers.Config().V1().ClusterOperators(),
coInformer,
openshiftConfigInformer.Core().V1().ConfigMaps(),
sharedInformers.Config().V1().Proxies(),
cb.ClientOrDie(o.Namespace),
cb.KubeClientOrDie(o.Namespace, useProtobuf),
o.ListenAddr != "",
o.Exclude,
),
}
Expand All @@ -382,6 +384,11 @@ func (o *Options) NewControllerContext(cb *ClientBuilder) *Context {
cb.KubeClientOrDie(o.Namespace),
)
}
if o.ListenAddr != "" {
if err := ctx.CVO.RegisterMetrics(coInformer.Informer()); err != nil {
panic(err)
}
}
return ctx
}

Expand Down

0 comments on commit f158967

Please sign in to comment.