From 6ffb599c0992dda46d0ba70d919290543f05c550 Mon Sep 17 00:00:00 2001 From: Jonathan Innis Date: Fri, 8 Nov 2024 15:15:13 -0800 Subject: [PATCH] chore: Abstract prometheus metrics to interfaces (#7357) --- .../templates/karpenter.sh_nodeclaims.yaml | 2 +- .../templates/karpenter.sh_nodepools.yaml | 2 +- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- pkg/apis/crds/karpenter.sh_nodeclaims.yaml | 2 +- pkg/apis/crds/karpenter.sh_nodepools.yaml | 2 +- pkg/batcher/batcher.go | 5 ++--- pkg/batcher/metrics.go | 9 +++------ pkg/cloudprovider/suite_test.go | 2 +- pkg/controllers/interruption/controller.go | 11 +++++------ pkg/controllers/interruption/metrics.go | 16 +++++++++------- pkg/providers/instancetype/instancetype.go | 17 ++++++++--------- pkg/providers/instancetype/metrics.go | 17 +++++++++-------- pkg/providers/instancetype/suite_test.go | 2 +- pkg/providers/launchtemplate/suite_test.go | 2 +- 15 files changed, 55 insertions(+), 58 deletions(-) diff --git a/charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml b/charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml index 02fa4861acf5..7976cfe0f45a 100644 --- a/charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml +++ b/charts/karpenter-crd/templates/karpenter.sh_nodeclaims.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.16.5 name: nodeclaims.karpenter.sh spec: group: karpenter.sh diff --git a/charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml b/charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml index 0894d11feecb..f20e73cd0d55 100644 --- a/charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml +++ b/charts/karpenter-crd/templates/karpenter.sh_nodepools.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.16.5 name: nodepools.karpenter.sh spec: group: karpenter.sh diff --git a/go.mod b/go.mod index f8fd1c4a9f50..1cd04f829683 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/aws/karpenter-provider-aws/tools/kompat v0.0.0-20240410220356-6b868db24881 github.com/aws/smithy-go v1.22.0 github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647 - github.com/awslabs/operatorpkg v0.0.0-20240920182301-771460b3160b + github.com/awslabs/operatorpkg v0.0.0-20241108183842-a2ebef231d52 github.com/go-logr/zapr v1.3.0 github.com/imdario/mergo v0.3.16 github.com/mitchellh/hashstructure/v2 v2.0.2 @@ -42,7 +42,7 @@ require ( k8s.io/klog/v2 v2.130.1 k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 sigs.k8s.io/controller-runtime v0.19.1 - sigs.k8s.io/karpenter v1.0.1-0.20241007233822-633135958bc4 + sigs.k8s.io/karpenter v1.0.1-0.20241108203843-2f8035457601 sigs.k8s.io/yaml v1.4.0 ) @@ -117,9 +117,9 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/cloud-provider v0.31.1 // indirect + k8s.io/cloud-provider v0.31.2 // indirect k8s.io/component-base v0.31.2 // indirect - k8s.io/csi-translation-lib v0.31.1 // indirect + k8s.io/csi-translation-lib v0.31.2 // indirect k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect diff --git a/go.sum b/go.sum index b995c9676f5c..bc3214c80ea5 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647 h1:8yRBVsjGmI7qQsPWtIrbWP+XfwHO9Wq7gdLVzjqiZFs= github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647/go.mod h1:9NafTAUHL0FlMeL6Cu5PXnMZ1q/LnC9X2emLXHsVbM8= -github.com/awslabs/operatorpkg v0.0.0-20240920182301-771460b3160b h1:aG1+YRmKIf5nLTZJNhw1NmuxvjUprWYyluqJ2jmVqiU= -github.com/awslabs/operatorpkg v0.0.0-20240920182301-771460b3160b/go.mod h1:RI+iNDn57c3WX0tsZg4rvkmM58lWsEC5cc6E4vJJld8= +github.com/awslabs/operatorpkg v0.0.0-20241108183842-a2ebef231d52 h1:k8f1ukVs49+nC6JbN8r8bxs8g1TPE3Iki/dK/LGwf3A= +github.com/awslabs/operatorpkg v0.0.0-20241108183842-a2ebef231d52/go.mod h1:nq1PLBLCojzjfqSK8SG3ymxqwW6e/cHLJvddKOSFkfw= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -307,12 +307,12 @@ k8s.io/apimachinery v0.31.2 h1:i4vUt2hPK56W6mlT7Ry+AO8eEsyxMD1U44NR22CLTYw= k8s.io/apimachinery v0.31.2/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc= k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs= -k8s.io/cloud-provider v0.31.1 h1:40b6AgDizwm5eWratZbqubTHMob25VWr6NX2Ei5TwZA= -k8s.io/cloud-provider v0.31.1/go.mod h1:xAdkE7fdZdu9rKLuOZUMBfagu7bM+bas3iPux/2nLGg= +k8s.io/cloud-provider v0.31.2 h1:ZdstxJOcHzP45j8giE79VJmgNckBbw1ldtIqnhZvKIA= +k8s.io/cloud-provider v0.31.2/go.mod h1:+4L8YpYCEx1Ko5EKS/PzXyBY5YREwDKChsJjAxHRf08= k8s.io/component-base v0.31.2 h1:Z1J1LIaC0AV+nzcPRFqfK09af6bZ4D1nAOpWsy9owlA= k8s.io/component-base v0.31.2/go.mod h1:9PeyyFN/drHjtJZMCTkSpQJS3U9OXORnHQqMLDz0sUQ= -k8s.io/csi-translation-lib v0.31.1 h1:ps9kya8+ih0CVL59JO2B4AYH8U/e3WLQxl9sx19NjjM= -k8s.io/csi-translation-lib v0.31.1/go.mod h1:VeYSucPZJbAt6RT25AzfG7WjyxCcmqxtr4V/CaDdNZc= +k8s.io/csi-translation-lib v0.31.2 h1:nCOE28rTUVOjwUKs4wl8wIZBHEnbQU5MkI0P6YM/Ylg= +k8s.io/csi-translation-lib v0.31.2/go.mod h1:X0paKG/WAqDyrfpiTyj8ga4srG0guOm2Sj2pNi4kP10= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= @@ -323,8 +323,8 @@ sigs.k8s.io/controller-runtime v0.19.1 h1:Son+Q40+Be3QWb+niBXAg2vFiYWolDjjRfO8hn sigs.k8s.io/controller-runtime v0.19.1/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= -sigs.k8s.io/karpenter v1.0.1-0.20241007233822-633135958bc4 h1:9j4MtUlunojW56lQxngksTsbOf1xTo6GBrvCWjskFaI= -sigs.k8s.io/karpenter v1.0.1-0.20241007233822-633135958bc4/go.mod h1:yJpNex/ZqhiL8TMck91gsDqAQJ+yg0hv4Y2Y90egL2o= +sigs.k8s.io/karpenter v1.0.1-0.20241108203843-2f8035457601 h1:X6L2Da47OoPcEAyoA2TCpdW3+X9G5cL1JfANRv09TUg= +sigs.k8s.io/karpenter v1.0.1-0.20241108203843-2f8035457601/go.mod h1:bnHSuhilh2JTejYG0F0dD/rqLuO4EU1VmoR/ZnoVrAA= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= diff --git a/pkg/apis/crds/karpenter.sh_nodeclaims.yaml b/pkg/apis/crds/karpenter.sh_nodeclaims.yaml index 02fa4861acf5..7976cfe0f45a 100644 --- a/pkg/apis/crds/karpenter.sh_nodeclaims.yaml +++ b/pkg/apis/crds/karpenter.sh_nodeclaims.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.16.5 name: nodeclaims.karpenter.sh spec: group: karpenter.sh diff --git a/pkg/apis/crds/karpenter.sh_nodepools.yaml b/pkg/apis/crds/karpenter.sh_nodepools.yaml index 0894d11feecb..f20e73cd0d55 100644 --- a/pkg/apis/crds/karpenter.sh_nodepools.yaml +++ b/pkg/apis/crds/karpenter.sh_nodepools.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.16.3 + controller-gen.kubebuilder.io/version: v0.16.5 name: nodepools.karpenter.sh spec: group: karpenter.sh diff --git a/pkg/batcher/batcher.go b/pkg/batcher/batcher.go index cbc0dddd76f1..d7a19e72266e 100644 --- a/pkg/batcher/batcher.go +++ b/pkg/batcher/batcher.go @@ -22,7 +22,6 @@ import ( "time" "github.com/mitchellh/hashstructure/v2" - "github.com/prometheus/client_golang/prometheus" "github.com/samber/lo" "golang.org/x/sync/errgroup" @@ -139,7 +138,7 @@ func (b *Batcher[T, U]) run() { return case <-b.trigger: // wait to start the batch of create fleet calls - measureDuration = metrics.Measure(batchWindowDuration.WithLabelValues(b.options.Name)) + measureDuration = metrics.Measure(BatchWindowDuration, map[string]string{batcherNameLabel: b.options.Name}) } b.waitForIdle() measureDuration() // Observe the length of time between the start of the batch and now @@ -184,7 +183,7 @@ func (b *Batcher[T, U]) waitForIdle() { func (b *Batcher[T, U]) runCalls(requests []*request[T, U]) { // Measure the size of the request batch - batchSize.With(prometheus.Labels{batcherNameLabel: b.options.Name}).Observe(float64(len(requests))) + BatchSize.Observe(float64(len(requests)), map[string]string{batcherNameLabel: b.options.Name}) requestIdx := 0 for _, result := range b.options.BatchExecutor(requests[0].ctx, lo.Map(requests, func(req *request[T, U], _ int) *T { return req.input })) { requests[requestIdx].requestor <- result diff --git a/pkg/batcher/metrics.go b/pkg/batcher/metrics.go index b0a1a8b0b318..2f49847e2015 100644 --- a/pkg/batcher/metrics.go +++ b/pkg/batcher/metrics.go @@ -15,6 +15,7 @@ limitations under the License. package batcher import ( + opmetrics "github.com/awslabs/operatorpkg/metrics" "github.com/prometheus/client_golang/prometheus" crmetrics "sigs.k8s.io/controller-runtime/pkg/metrics" @@ -34,14 +35,14 @@ func SizeBuckets() []float64 { } var ( - batchWindowDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ + BatchWindowDuration = opmetrics.NewPrometheusHistogram(crmetrics.Registry, prometheus.HistogramOpts{ Namespace: metrics.Namespace, Subsystem: batcherSubsystem, Name: "batch_time_seconds", Help: "Duration of the batching window per batcher", Buckets: metrics.DurationBuckets(), }, []string{batcherNameLabel}) - batchSize = prometheus.NewHistogramVec(prometheus.HistogramOpts{ + BatchSize = opmetrics.NewPrometheusHistogram(crmetrics.Registry, prometheus.HistogramOpts{ Namespace: metrics.Namespace, Subsystem: batcherSubsystem, Name: "batch_size", @@ -49,7 +50,3 @@ var ( Buckets: SizeBuckets(), }, []string{batcherNameLabel}) ) - -func init() { - crmetrics.Registry.MustRegister(batchWindowDuration, batchSize) -} diff --git a/pkg/cloudprovider/suite_test.go b/pkg/cloudprovider/suite_test.go index b27f1e3a7606..d6cddb6f6fec 100644 --- a/pkg/cloudprovider/suite_test.go +++ b/pkg/cloudprovider/suite_test.go @@ -90,7 +90,7 @@ var _ = BeforeSuite(func() { cloudProvider = cloudprovider.New(awsEnv.InstanceTypesProvider, awsEnv.InstanceProvider, recorder, env.Client, awsEnv.AMIProvider, awsEnv.SecurityGroupProvider) cluster = state.NewCluster(fakeClock, env.Client) - prov = provisioning.NewProvisioner(env.Client, recorder, cloudProvider, cluster) + prov = provisioning.NewProvisioner(env.Client, recorder, cloudProvider, cluster, fakeClock) }) var _ = AfterSuite(func() { diff --git a/pkg/controllers/interruption/controller.go b/pkg/controllers/interruption/controller.go index ea069255c9f5..c411c87a4b98 100644 --- a/pkg/controllers/interruption/controller.go +++ b/pkg/controllers/interruption/controller.go @@ -19,7 +19,6 @@ import ( "fmt" "time" - "github.com/prometheus/client_golang/prometheus" "sigs.k8s.io/karpenter/pkg/metrics" ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" @@ -150,7 +149,7 @@ func (c *Controller) handleMessage(ctx context.Context, nodeClaimInstanceIDMap m nodeInstanceIDMap map[string]*corev1.Node, msg messages.Message) (err error) { ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("messageKind", msg.Kind())) - receivedMessages.WithLabelValues(string(msg.Kind())).Inc() + ReceivedMessages.Inc(map[string]string{messageTypeLabel: string(msg.Kind())}) if msg.Kind() == messages.NoOpKind { return nil @@ -165,7 +164,7 @@ func (c *Controller) handleMessage(ctx context.Context, nodeClaimInstanceIDMap m err = multierr.Append(err, e) } } - messageLatency.Observe(time.Since(msg.StartTime()).Seconds()) + MessageLatency.Observe(time.Since(msg.StartTime()).Seconds(), nil) if err != nil { return fmt.Errorf("acting on NodeClaims, %w", err) } @@ -177,7 +176,7 @@ func (c *Controller) deleteMessage(ctx context.Context, msg *sqstypes.Message) e if err := c.sqsProvider.DeleteSQSMessage(ctx, msg); err != nil { return fmt.Errorf("deleting sqs message, %w", err) } - deletedMessages.Inc() + DeletedMessages.Inc(nil) return nil } @@ -216,11 +215,11 @@ func (c *Controller) deleteNodeClaim(ctx context.Context, msg messages.Message, } log.FromContext(ctx).Info("initiating delete from interruption message") c.recorder.Publish(interruptionevents.TerminatingOnInterruption(node, nodeClaim)...) - metrics.NodeClaimsDisruptedTotal.With(prometheus.Labels{ + metrics.NodeClaimsDisruptedTotal.Inc(map[string]string{ metrics.ReasonLabel: string(msg.Kind()), metrics.NodePoolLabel: nodeClaim.Labels[karpv1.NodePoolLabelKey], metrics.CapacityTypeLabel: nodeClaim.Labels[karpv1.CapacityTypeLabelKey], - }).Inc() + }) return nil } diff --git a/pkg/controllers/interruption/metrics.go b/pkg/controllers/interruption/metrics.go index 7b3f92468751..655183f4190b 100644 --- a/pkg/controllers/interruption/metrics.go +++ b/pkg/controllers/interruption/metrics.go @@ -15,6 +15,7 @@ limitations under the License. package interruption import ( + opmetrics "github.com/awslabs/operatorpkg/metrics" "github.com/prometheus/client_golang/prometheus" crmetrics "sigs.k8s.io/controller-runtime/pkg/metrics" @@ -27,7 +28,8 @@ const ( ) var ( - receivedMessages = prometheus.NewCounterVec( + ReceivedMessages = opmetrics.NewPrometheusCounter( + crmetrics.Registry, prometheus.CounterOpts{ Namespace: metrics.Namespace, Subsystem: interruptionSubsystem, @@ -36,15 +38,18 @@ var ( }, []string{messageTypeLabel}, ) - deletedMessages = prometheus.NewCounter( + DeletedMessages = opmetrics.NewPrometheusCounter( + crmetrics.Registry, prometheus.CounterOpts{ Namespace: metrics.Namespace, Subsystem: interruptionSubsystem, Name: "deleted_messages_total", Help: "Count of messages deleted from the SQS queue.", }, + []string{}, ) - messageLatency = prometheus.NewHistogram( + MessageLatency = opmetrics.NewPrometheusHistogram( + crmetrics.Registry, prometheus.HistogramOpts{ Namespace: metrics.Namespace, Subsystem: interruptionSubsystem, @@ -52,9 +57,6 @@ var ( Help: "Amount of time an interruption message is on the queue before it is processed by karpenter.", Buckets: metrics.DurationBuckets(), }, + []string{}, ) ) - -func init() { - crmetrics.Registry.MustRegister(receivedMessages, deletedMessages, messageLatency) -} diff --git a/pkg/providers/instancetype/instancetype.go b/pkg/providers/instancetype/instancetype.go index 81ff8ab5a730..fa3f561b7c8c 100644 --- a/pkg/providers/instancetype/instancetype.go +++ b/pkg/providers/instancetype/instancetype.go @@ -29,7 +29,6 @@ import ( "github.com/mitchellh/hashstructure/v2" "github.com/patrickmn/go-cache" - "github.com/prometheus/client_golang/prometheus" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/log" karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1" @@ -147,12 +146,12 @@ func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass) return s.Zone, s.ZoneID }) result := lo.Map(p.instanceTypesInfo, func(i ec2types.InstanceTypeInfo, _ int) *cloudprovider.InstanceType { - instanceTypeVCPU.With(prometheus.Labels{ + InstanceTypeVCPU.Set(float64(lo.FromPtr(i.VCpuInfo.DefaultVCpus)), map[string]string{ instanceTypeLabel: string(i.InstanceType), - }).Set(float64(lo.FromPtr(i.VCpuInfo.DefaultVCpus))) - instanceTypeMemory.With(prometheus.Labels{ + }) + InstanceTypeMemory.Set(float64(lo.FromPtr(i.MemoryInfo.SizeInMiB)*1024*1024), map[string]string{ instanceTypeLabel: string(i.InstanceType), - }).Set(float64(lo.FromPtr(i.MemoryInfo.SizeInMiB) * 1024 * 1024)) + }) zoneData := lo.Map(allZones.UnsortedList(), func(zoneName string, _ int) ZoneData { if !p.instanceTypesOfferings[string(i.InstanceType)].Has(zoneName) || !subnetZones.Has(zoneName) { @@ -173,16 +172,16 @@ func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass) it.Capacity[corev1.ResourceMemory] = cached.(resource.Quantity) } for _, of := range it.Offerings { - instanceTypeOfferingAvailable.With(prometheus.Labels{ + InstanceTypeOfferingAvailable.Set(float64(lo.Ternary(of.Available, 1, 0)), map[string]string{ instanceTypeLabel: it.Name, capacityTypeLabel: of.Requirements.Get(karpv1.CapacityTypeLabelKey).Any(), zoneLabel: of.Requirements.Get(corev1.LabelTopologyZone).Any(), - }).Set(float64(lo.Ternary(of.Available, 1, 0))) - instanceTypeOfferingPriceEstimate.With(prometheus.Labels{ + }) + InstanceTypeOfferingPriceEstimate.Set(of.Price, map[string]string{ instanceTypeLabel: it.Name, capacityTypeLabel: of.Requirements.Get(karpv1.CapacityTypeLabelKey).Any(), zoneLabel: of.Requirements.Get(corev1.LabelTopologyZone).Any(), - }).Set(of.Price) + }) } return it }) diff --git a/pkg/providers/instancetype/metrics.go b/pkg/providers/instancetype/metrics.go index 5b505e8f813a..726c851e13b8 100644 --- a/pkg/providers/instancetype/metrics.go +++ b/pkg/providers/instancetype/metrics.go @@ -15,6 +15,7 @@ limitations under the License. package instancetype import ( + opmetrics "github.com/awslabs/operatorpkg/metrics" "github.com/prometheus/client_golang/prometheus" crmetrics "sigs.k8s.io/controller-runtime/pkg/metrics" @@ -29,7 +30,8 @@ const ( ) var ( - instanceTypeVCPU = prometheus.NewGaugeVec( + InstanceTypeVCPU = opmetrics.NewPrometheusGauge( + crmetrics.Registry, prometheus.GaugeOpts{ Namespace: metrics.Namespace, Subsystem: cloudProviderSubsystem, @@ -40,7 +42,8 @@ var ( instanceTypeLabel, }, ) - instanceTypeMemory = prometheus.NewGaugeVec( + InstanceTypeMemory = opmetrics.NewPrometheusGauge( + crmetrics.Registry, prometheus.GaugeOpts{ Namespace: metrics.Namespace, Subsystem: cloudProviderSubsystem, @@ -51,7 +54,8 @@ var ( instanceTypeLabel, }, ) - instanceTypeOfferingAvailable = prometheus.NewGaugeVec( + InstanceTypeOfferingAvailable = opmetrics.NewPrometheusGauge( + crmetrics.Registry, prometheus.GaugeOpts{ Namespace: metrics.Namespace, Subsystem: cloudProviderSubsystem, @@ -64,7 +68,8 @@ var ( zoneLabel, }, ) - instanceTypeOfferingPriceEstimate = prometheus.NewGaugeVec( + InstanceTypeOfferingPriceEstimate = opmetrics.NewPrometheusGauge( + crmetrics.Registry, prometheus.GaugeOpts{ Namespace: metrics.Namespace, Subsystem: cloudProviderSubsystem, @@ -77,7 +82,3 @@ var ( zoneLabel, }) ) - -func init() { - crmetrics.Registry.MustRegister(instanceTypeVCPU, instanceTypeMemory, instanceTypeOfferingAvailable, instanceTypeOfferingPriceEstimate) -} diff --git a/pkg/providers/instancetype/suite_test.go b/pkg/providers/instancetype/suite_test.go index f1fc9d77ae5f..76e1abfa114f 100644 --- a/pkg/providers/instancetype/suite_test.go +++ b/pkg/providers/instancetype/suite_test.go @@ -89,7 +89,7 @@ var _ = BeforeSuite(func() { cloudProvider = cloudprovider.New(awsEnv.InstanceTypesProvider, awsEnv.InstanceProvider, events.NewRecorder(&record.FakeRecorder{}), env.Client, awsEnv.AMIProvider, awsEnv.SecurityGroupProvider) cluster = state.NewCluster(fakeClock, env.Client) - prov = provisioning.NewProvisioner(env.Client, events.NewRecorder(&record.FakeRecorder{}), cloudProvider, cluster) + prov = provisioning.NewProvisioner(env.Client, events.NewRecorder(&record.FakeRecorder{}), cloudProvider, cluster, fakeClock) }) var _ = AfterSuite(func() { diff --git a/pkg/providers/launchtemplate/suite_test.go b/pkg/providers/launchtemplate/suite_test.go index 79412d204883..bddfc1e56e09 100644 --- a/pkg/providers/launchtemplate/suite_test.go +++ b/pkg/providers/launchtemplate/suite_test.go @@ -99,7 +99,7 @@ var _ = BeforeSuite(func() { cloudProvider = cloudprovider.New(awsEnv.InstanceTypesProvider, awsEnv.InstanceProvider, events.NewRecorder(&record.FakeRecorder{}), env.Client, awsEnv.AMIProvider, awsEnv.SecurityGroupProvider) cluster = state.NewCluster(fakeClock, env.Client) - prov = provisioning.NewProvisioner(env.Client, events.NewRecorder(&record.FakeRecorder{}), cloudProvider, cluster) + prov = provisioning.NewProvisioner(env.Client, events.NewRecorder(&record.FakeRecorder{}), cloudProvider, cluster, fakeClock) }) var _ = AfterSuite(func() {