Skip to content

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 b5e6bfd commit 00f5d1a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion flytestdlib/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 00f5d1a

Please sign in to comment.