Skip to content

Commit

Permalink
agent/billing: Use autoscaling.neon.tech/billing-endpoint-id for events
Browse files Browse the repository at this point in the history
Sometimes we want to provide neon/endpoint-id but not have billing
events generated for it.
  • Loading branch information
sharnoff committed Oct 21, 2023
1 parent c5db42b commit c04fe80
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
11 changes: 5 additions & 6 deletions pkg/agent/billing/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ type vmMetricsSeconds struct {
activeTime time.Duration
}

const (
EndpointLabel string = "neon/endpoint-id"
)

func RunBillingMetricsCollector(
backgroundCtx context.Context,
parentLogger *zap.Logger,
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions pkg/api/vminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c04fe80

Please sign in to comment.