From c04fe8002371c84e557592a80584448e7a9978aa Mon Sep 17 00:00:00 2001 From: Em Sharnoff Date: Fri, 20 Oct 2023 23:30:13 -0700 Subject: [PATCH] agent/billing: Use autoscaling.neon.tech/billing-endpoint-id for events Sometimes we want to provide neon/endpoint-id but not have billing events generated for it. --- pkg/agent/billing/billing.go | 11 +++++------ pkg/agent/watch.go | 4 ++-- pkg/api/vminfo.go | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/agent/billing/billing.go b/pkg/agent/billing/billing.go index 86ae3f400..9cbf710d0 100644 --- a/pkg/agent/billing/billing.go +++ b/pkg/agent/billing/billing.go @@ -68,10 +68,6 @@ type vmMetricsSeconds struct { activeTime time.Duration } -const ( - EndpointLabel string = "neon/endpoint-id" -) - func RunBillingMetricsCollector( backgroundCtx context.Context, parentLogger *zap.Logger, @@ -152,10 +148,13 @@ func (s *metricsState) collect(logger *zap.Logger, store VMStoreForNode, metrics }) } for _, vm := range vmsOnThisNode { - endpointID, isEndpoint := vm.Labels[EndpointLabel] + if vm.Annotations == nil { + continue + } + endpointID, isEndpoint := vm.Annotations[api.AnnotationBillingEndpointID] metricsBatch.inc(isEndpointFlag(isEndpoint), autoscalingEnabledFlag(api.HasAutoscalingEnabled(vm)), vm.Status.Phase) if !isEndpoint { - // we're only reporting metrics for VMs with endpoint IDs, and this VM doesn't have one + // we're only reporting metrics for VMs with tenant IDs, and this VM doesn't have one continue } diff --git a/pkg/agent/watch.go b/pkg/agent/watch.go index 322b5d8dd..26b6506f5 100644 --- a/pkg/agent/watch.go +++ b/pkg/agent/watch.go @@ -151,8 +151,8 @@ func makeVMEvent(logger *zap.Logger, vm *vmapi.VirtualMachine, kind vmEventKind) } endpointID := "" - if vm.Labels != nil { - endpointID = vm.Labels[billing.EndpointLabel] // billing needs endpoint IDs anyways, just grab the label name from there + if vm.Annotations != nil { + endpointID = vm.Labels[api.AnnotationBillingEndpointID] // billing needs endpoint IDs anyways, just grab the label name from there } return vmEvent{ diff --git a/pkg/api/vminfo.go b/pkg/api/vminfo.go index 8e2f37af7..f9f710560 100644 --- a/pkg/api/vminfo.go +++ b/pkg/api/vminfo.go @@ -23,6 +23,7 @@ const ( LabelEnableAutoscaling = "autoscaling.neon.tech/enabled" AnnotationAutoscalingBounds = "autoscaling.neon.tech/bounds" AnnotationAutoscalingConfig = "autoscaling.neon.tech/config" + AnnotationBillingEndpointID = "autoscaling.neon.tech/billing-endpoint-id" ) // HasAutoscalingEnabled returns true iff the object has the label that enables autoscaling