Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Set provider only if all methods are implemented (#26)
Browse files Browse the repository at this point in the history
* Set provider only if all methods of interface are implemented
  • Loading branch information
anandswaminathan authored Jul 2, 2019
1 parent 8786594 commit 2577ff2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion promutils/workqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package promutils

import (
"fmt"

"k8s.io/client-go/util/workqueue"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -26,7 +28,14 @@ import (
// prometheus metrics. To use this package, you just have to import it.

func init() {
workqueue.SetProvider(prometheusMetricsProvider{})
var provider interface{} //nolint
provider = prometheusMetricsProvider{}
if p, casted := provider.(workqueue.MetricsProvider); casted {
workqueue.SetProvider(p)
} else {
// This case happens in future versions of client-go where the interface has added methods
fmt.Println("Warn: No metricsProvider set for the workqueue")
}
}

type prometheusMetricsProvider struct{}
Expand Down

0 comments on commit 2577ff2

Please sign in to comment.