diff --git a/discovery/kubernetes/client_metrics.go b/discovery/kubernetes/client_metrics.go index 992e16edc..a60ff48f2 100644 --- a/discovery/kubernetes/client_metrics.go +++ b/discovery/kubernetes/client_metrics.go @@ -109,19 +109,16 @@ func (noopMetric) Set(float64) {} type clientGoRequestMetricAdapter struct{} func (f *clientGoRequestMetricAdapter) Register(registerer prometheus.Registerer) { - metrics.Register(metrics.RegisterOpts{ - RequestLatency: f, - RequestResult: f, - }) + metrics.Register(f, f) registerer.MustRegister( clientGoRequestResultMetricVec, clientGoRequestLatencyMetricVec, ) } -func (clientGoRequestMetricAdapter) Increment(code string, _ string, _ string) { +func (clientGoRequestMetricAdapter) Increment(code string, method string, host string) { clientGoRequestResultMetricVec.WithLabelValues(code).Inc() } -func (clientGoRequestMetricAdapter) Observe(_ string, u url.URL, latency time.Duration) { +func (clientGoRequestMetricAdapter) Observe(verb string, u url.URL, latency time.Duration) { clientGoRequestLatencyMetricVec.WithLabelValues(u.EscapedPath()).Observe(latency.Seconds()) } diff --git a/discovery/kubernetes/endpoints_test.go b/discovery/kubernetes/endpoints_test.go index e73d8ba06..bc6250dc0 100644 --- a/discovery/kubernetes/endpoints_test.go +++ b/discovery/kubernetes/endpoints_test.go @@ -14,7 +14,6 @@ package kubernetes import ( - "context" "testing" "github.com/prometheus/common/model" @@ -80,7 +79,7 @@ func TestEndpointsDiscoveryBeforeRun(t *testing.T) { discovery: n, beforeRun: func() { obj := makeEndpoints() - c.CoreV1().Endpoints(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Endpoints(obj.Namespace).Create(obj) }, expectedMaxItems: 1, expectedRes: map[string]*targetgroup.Group{ @@ -186,7 +185,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) { }, }, } - c.CoreV1().Endpoints(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Endpoints(obj.Namespace).Create(obj) }, expectedMaxItems: 1, expectedRes: map[string]*targetgroup.Group{ @@ -243,7 +242,7 @@ func TestEndpointsDiscoveryDelete(t *testing.T) { discovery: n, afterStart: func() { obj := makeEndpoints() - c.CoreV1().Endpoints(obj.Namespace).Delete(context.Background(), obj.Name, metav1.DeleteOptions{}) + c.CoreV1().Endpoints(obj.Namespace).Delete(obj.Name, &metav1.DeleteOptions{}) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -296,7 +295,7 @@ func TestEndpointsDiscoveryUpdate(t *testing.T) { }, }, } - c.CoreV1().Endpoints(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{}) + c.CoreV1().Endpoints(obj.Namespace).Update(obj) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -338,7 +337,7 @@ func TestEndpointsDiscoveryEmptySubsets(t *testing.T) { }, Subsets: []v1.EndpointSubset{}, } - c.CoreV1().Endpoints(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{}) + c.CoreV1().Endpoints(obj.Namespace).Update(obj) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -368,7 +367,7 @@ func TestEndpointsDiscoveryWithService(t *testing.T) { }, }, } - c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Services(obj.Namespace).Create(obj) }, expectedMaxItems: 1, expectedRes: map[string]*targetgroup.Group{ @@ -423,7 +422,7 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) { }, }, } - c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Services(obj.Namespace).Create(obj) }, afterStart: func() { obj := &v1.Service{ @@ -436,7 +435,7 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) { }, }, } - c.CoreV1().Services(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{}) + c.CoreV1().Services(obj.Namespace).Update(obj) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ diff --git a/discovery/kubernetes/ingress_test.go b/discovery/kubernetes/ingress_test.go index 894cb460e..4159545a8 100644 --- a/discovery/kubernetes/ingress_test.go +++ b/discovery/kubernetes/ingress_test.go @@ -14,7 +14,6 @@ package kubernetes import ( - "context" "fmt" "testing" @@ -139,7 +138,7 @@ func TestIngressDiscoveryAdd(t *testing.T) { discovery: n, afterStart: func() { obj := makeIngress(TLSNo) - c.ExtensionsV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{}) + c.ExtensionsV1beta1().Ingresses("default").Create(obj) }, expectedMaxItems: 1, expectedRes: expectedTargetGroups("default", TLSNo), @@ -153,7 +152,7 @@ func TestIngressDiscoveryAddTLS(t *testing.T) { discovery: n, afterStart: func() { obj := makeIngress(TLSYes) - c.ExtensionsV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{}) + c.ExtensionsV1beta1().Ingresses("default").Create(obj) }, expectedMaxItems: 1, expectedRes: expectedTargetGroups("default", TLSYes), @@ -167,7 +166,7 @@ func TestIngressDiscoveryAddMixed(t *testing.T) { discovery: n, afterStart: func() { obj := makeIngress(TLSMixed) - c.ExtensionsV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{}) + c.ExtensionsV1beta1().Ingresses("default").Create(obj) }, expectedMaxItems: 1, expectedRes: expectedTargetGroups("default", TLSMixed), @@ -187,7 +186,7 @@ func TestIngressDiscoveryNamespaces(t *testing.T) { for _, ns := range []string{"ns1", "ns2"} { obj := makeIngress(TLSNo) obj.Namespace = ns - c.ExtensionsV1beta1().Ingresses(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.ExtensionsV1beta1().Ingresses(obj.Namespace).Create(obj) } }, expectedMaxItems: 2, diff --git a/discovery/kubernetes/kubernetes.go b/discovery/kubernetes/kubernetes.go index f39cf165d..9325794c7 100644 --- a/discovery/kubernetes/kubernetes.go +++ b/discovery/kubernetes/kubernetes.go @@ -317,12 +317,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { options.FieldSelector = d.selectors.endpoints.field options.LabelSelector = d.selectors.endpoints.label - return e.List(ctx, options) + return e.List(options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { options.FieldSelector = d.selectors.endpoints.field options.LabelSelector = d.selectors.endpoints.label - return e.Watch(ctx, options) + return e.Watch(options) }, } s := d.client.CoreV1().Services(namespace) @@ -330,12 +330,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { options.FieldSelector = d.selectors.service.field options.LabelSelector = d.selectors.service.label - return s.List(ctx, options) + return s.List(options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { options.FieldSelector = d.selectors.service.field options.LabelSelector = d.selectors.service.label - return s.Watch(ctx, options) + return s.Watch(options) }, } p := d.client.CoreV1().Pods(namespace) @@ -343,12 +343,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { options.FieldSelector = d.selectors.pod.field options.LabelSelector = d.selectors.pod.label - return p.List(ctx, options) + return p.List(options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { options.FieldSelector = d.selectors.pod.field options.LabelSelector = d.selectors.pod.label - return p.Watch(ctx, options) + return p.Watch(options) }, } eps := NewEndpoints( @@ -369,12 +369,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { options.FieldSelector = d.selectors.pod.field options.LabelSelector = d.selectors.pod.label - return p.List(ctx, options) + return p.List(options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { options.FieldSelector = d.selectors.pod.field options.LabelSelector = d.selectors.pod.label - return p.Watch(ctx, options) + return p.Watch(options) }, } pod := NewPod( @@ -391,12 +391,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { options.FieldSelector = d.selectors.service.field options.LabelSelector = d.selectors.service.label - return s.List(ctx, options) + return s.List(options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { options.FieldSelector = d.selectors.service.field options.LabelSelector = d.selectors.service.label - return s.Watch(ctx, options) + return s.Watch(options) }, } svc := NewService( @@ -413,12 +413,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { options.FieldSelector = d.selectors.ingress.field options.LabelSelector = d.selectors.ingress.label - return i.List(ctx, options) + return i.List(options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { options.FieldSelector = d.selectors.ingress.field options.LabelSelector = d.selectors.ingress.label - return i.Watch(ctx, options) + return i.Watch(options) }, } ingress := NewIngress( @@ -433,12 +433,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { options.FieldSelector = d.selectors.node.field options.LabelSelector = d.selectors.node.label - return d.client.CoreV1().Nodes().List(ctx, options) + return d.client.CoreV1().Nodes().List(options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { options.FieldSelector = d.selectors.node.field options.LabelSelector = d.selectors.node.label - return d.client.CoreV1().Nodes().Watch(ctx, options) + return d.client.CoreV1().Nodes().Watch(options) }, } node := NewNode( diff --git a/discovery/kubernetes/node_test.go b/discovery/kubernetes/node_test.go index 4a08eefc8..402b901a5 100644 --- a/discovery/kubernetes/node_test.go +++ b/discovery/kubernetes/node_test.go @@ -14,7 +14,6 @@ package kubernetes import ( - "context" "fmt" "testing" @@ -64,7 +63,7 @@ func TestNodeDiscoveryBeforeStart(t *testing.T) { map[string]string{"test-label": "testvalue"}, map[string]string{"test-annotation": "testannotationvalue"}, ) - c.CoreV1().Nodes().Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Nodes().Create(obj) }, expectedMaxItems: 1, expectedRes: map[string]*targetgroup.Group{ @@ -96,7 +95,7 @@ func TestNodeDiscoveryAdd(t *testing.T) { discovery: n, afterStart: func() { obj := makeEnumeratedNode(1) - c.CoreV1().Nodes().Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Nodes().Create(obj) }, expectedMaxItems: 1, expectedRes: map[string]*targetgroup.Group{ @@ -124,7 +123,7 @@ func TestNodeDiscoveryDelete(t *testing.T) { k8sDiscoveryTest{ discovery: n, afterStart: func() { - c.CoreV1().Nodes().Delete(context.Background(), obj.Name, metav1.DeleteOptions{}) + c.CoreV1().Nodes().Delete(obj.Name, &metav1.DeleteOptions{}) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -142,14 +141,14 @@ func TestNodeDiscoveryUpdate(t *testing.T) { discovery: n, afterStart: func() { obj1 := makeEnumeratedNode(0) - c.CoreV1().Nodes().Create(context.Background(), obj1, metav1.CreateOptions{}) + c.CoreV1().Nodes().Create(obj1) obj2 := makeNode( "test0", "1.2.3.4", map[string]string{"Unschedulable": "true"}, map[string]string{}, ) - c.CoreV1().Nodes().Update(context.Background(), obj2, metav1.UpdateOptions{}) + c.CoreV1().Nodes().Update(obj2) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ diff --git a/discovery/kubernetes/pod_test.go b/discovery/kubernetes/pod_test.go index b40cd58f3..f5aaac60f 100644 --- a/discovery/kubernetes/pod_test.go +++ b/discovery/kubernetes/pod_test.go @@ -14,7 +14,6 @@ package kubernetes import ( - "context" "fmt" "testing" @@ -197,7 +196,7 @@ func TestPodDiscoveryBeforeRun(t *testing.T) { discovery: n, beforeRun: func() { obj := makeMultiPortPods() - c.CoreV1().Pods(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Pods(obj.Namespace).Create(obj) }, expectedMaxItems: 1, expectedRes: map[string]*targetgroup.Group{ @@ -265,7 +264,7 @@ func TestPodDiscoveryInitContainer(t *testing.T) { discovery: n, beforeRun: func() { obj := makeInitContainerPods() - c.CoreV1().Pods(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Pods(obj.Namespace).Create(obj) }, expectedMaxItems: 1, expectedRes: expected, @@ -279,7 +278,7 @@ func TestPodDiscoveryAdd(t *testing.T) { discovery: n, afterStart: func() { obj := makePods() - c.CoreV1().Pods(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Pods(obj.Namespace).Create(obj) }, expectedMaxItems: 1, expectedRes: expectedPodTargetGroups("default"), @@ -294,7 +293,7 @@ func TestPodDiscoveryDelete(t *testing.T) { discovery: n, afterStart: func() { obj := makePods() - c.CoreV1().Pods(obj.Namespace).Delete(context.Background(), obj.Name, metav1.DeleteOptions{}) + c.CoreV1().Pods(obj.Namespace).Delete(obj.Name, &metav1.DeleteOptions{}) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -338,7 +337,7 @@ func TestPodDiscoveryUpdate(t *testing.T) { discovery: n, afterStart: func() { obj := makePods() - c.CoreV1().Pods(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{}) + c.CoreV1().Pods(obj.Namespace).Update(obj) }, expectedMaxItems: 2, expectedRes: expectedPodTargetGroups("default"), @@ -355,10 +354,10 @@ func TestPodDiscoveryUpdateEmptyPodIP(t *testing.T) { k8sDiscoveryTest{ discovery: n, beforeRun: func() { - c.CoreV1().Pods(initialPod.Namespace).Create(context.Background(), initialPod, metav1.CreateOptions{}) + c.CoreV1().Pods(initialPod.Namespace).Create(initialPod) }, afterStart: func() { - c.CoreV1().Pods(updatedPod.Namespace).Update(context.Background(), updatedPod, metav1.UpdateOptions{}) + c.CoreV1().Pods(updatedPod.Namespace).Update(updatedPod) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -382,7 +381,7 @@ func TestPodDiscoveryNamespaces(t *testing.T) { for _, ns := range []string{"ns1", "ns2"} { pod := makePods() pod.Namespace = ns - c.CoreV1().Pods(pod.Namespace).Create(context.Background(), pod, metav1.CreateOptions{}) + c.CoreV1().Pods(pod.Namespace).Create(pod) } }, expectedMaxItems: 2, diff --git a/discovery/kubernetes/service_test.go b/discovery/kubernetes/service_test.go index a54e084d2..7011aa24d 100644 --- a/discovery/kubernetes/service_test.go +++ b/discovery/kubernetes/service_test.go @@ -14,7 +14,6 @@ package kubernetes import ( - "context" "fmt" "testing" @@ -103,9 +102,9 @@ func TestServiceDiscoveryAdd(t *testing.T) { discovery: n, afterStart: func() { obj := makeService() - c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Services(obj.Namespace).Create(obj) obj = makeExternalService() - c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Services(obj.Namespace).Create(obj) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -152,7 +151,7 @@ func TestServiceDiscoveryDelete(t *testing.T) { discovery: n, afterStart: func() { obj := makeService() - c.CoreV1().Services(obj.Namespace).Delete(context.Background(), obj.Name, metav1.DeleteOptions{}) + c.CoreV1().Services(obj.Namespace).Delete(obj.Name, &metav1.DeleteOptions{}) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -170,7 +169,7 @@ func TestServiceDiscoveryUpdate(t *testing.T) { discovery: n, afterStart: func() { obj := makeMultiPortService() - c.CoreV1().Services(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{}) + c.CoreV1().Services(obj.Namespace).Update(obj) }, expectedMaxItems: 2, expectedRes: map[string]*targetgroup.Group{ @@ -214,7 +213,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) { for _, ns := range []string{"ns1", "ns2"} { obj := makeService() obj.Namespace = ns - c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{}) + c.CoreV1().Services(obj.Namespace).Create(obj) } }, expectedMaxItems: 2,