use cancelable context instead of context.TODO()

This commit is contained in:
tariqibrahim 2019-02-13 10:13:21 -08:00
parent ab1415677a
commit cd5711c8f4
2 changed files with 10 additions and 4 deletions

View File

@ -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")

View File

@ -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)