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