use cancelable context instead of context.TODO()
This commit is contained in:
parent
ab1415677a
commit
cd5711c8f4
5
main.go
5
main.go
|
|
@ -60,6 +60,9 @@ func main() {
|
|||
opts := options.NewOptions()
|
||||
opts.AddFlags()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
err := opts.Parse()
|
||||
if err != nil {
|
||||
glog.Fatalf("Error: %s", err)
|
||||
|
|
@ -75,7 +78,7 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
collectorBuilder := kcoll.NewBuilder(context.TODO())
|
||||
collectorBuilder := kcoll.NewBuilder(ctx)
|
||||
|
||||
if len(opts.Collectors) == 0 {
|
||||
glog.Info("Using default collectors")
|
||||
|
|
|
|||
|
|
@ -54,8 +54,9 @@ func BenchmarkKubeStateMetrics(b *testing.B) {
|
|||
if err := injectFixtures(kubeClient, fixtureMultiplier); err != nil {
|
||||
b.Errorf("error injecting resources: %v", err)
|
||||
}
|
||||
|
||||
builder := kcoll.NewBuilder(context.TODO())
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
builder := kcoll.NewBuilder(ctx)
|
||||
builder.WithEnabledCollectors(options.DefaultCollectors.AsSlice())
|
||||
builder.WithKubeClient(kubeClient)
|
||||
builder.WithNamespaces(options.DefaultNamespaces)
|
||||
|
|
@ -113,7 +114,9 @@ func TestFullScrapeCycle(t *testing.T) {
|
|||
t.Fatalf("failed to insert sample pod %v", err.Error())
|
||||
}
|
||||
|
||||
builder := kcoll.NewBuilder(context.TODO())
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
builder := kcoll.NewBuilder(ctx)
|
||||
builder.WithEnabledCollectors(options.DefaultCollectors.AsSlice())
|
||||
builder.WithKubeClient(kubeClient)
|
||||
builder.WithNamespaces(options.DefaultNamespaces)
|
||||
|
|
|
|||
Loading…
Reference in New Issue