@@ -45,44 +45,47 @@ import (
45
45
"sigs.k8s.io/controller-runtime/pkg/metrics"
46
46
)
47
47
48
+ const (
49
+ operationCreateBranchENI = "create_branch_eni"
50
+ operationAnnotateBranchENI = "annotate_branch_eni"
51
+ operationInitTrunk = "init_trunk"
52
+ resourceCountLabel = "resource_count"
53
+ operationLabel = "branch_provider_operation"
54
+
55
+ ReasonSecurityGroupRequested = "SecurityGroupRequested"
56
+ ReasonResourceAllocated = "ResourceAllocated"
57
+ ReasonBranchAllocationFailed = "BranchAllocationFailed"
58
+ ReasonBranchENIAnnotationFailed = "BranchENIAnnotationFailed"
59
+
60
+ ReasonTrunkENICreationFailed = "TrunkENICreationFailed"
61
+ )
62
+
48
63
var (
49
64
branchProviderOperationsErrCount = prometheus .NewCounterVec (
50
65
prometheus.CounterOpts {
51
66
Name : "branch_provider_operations_err_count" ,
52
67
Help : "The number of errors encountered for branch provider operations" ,
53
68
},
54
- []string {"operation" },
69
+ []string {operationLabel },
55
70
)
56
71
57
72
branchProviderOperationLatency = prometheus .NewSummaryVec (
58
73
prometheus.SummaryOpts {
59
- Name : "branch_provider_operation_latency" ,
60
- Help : "Branch Provider operations latency in ms" ,
74
+ Name : "branch_provider_operation_latency" ,
75
+ Help : "Branch Provider operations latency in seconds" ,
76
+ Objectives : map [float64 ]float64 {0 : 0 , 0.5 : 0.05 , 0.9 : 0.01 , 0.99 : 0.001 , 1 : 0 },
61
77
},
62
- []string {"operation" , "resource_count" },
78
+ []string {operationLabel , resourceCountLabel },
63
79
)
64
80
65
- operationCreateBranchENI = "create_branch_eni"
66
- operationCreateBranchENIAndAnnotate = "create_and_annotate_branch_eni"
67
- operationInitTrunk = "init_trunk"
68
-
69
- ReasonSecurityGroupRequested = "SecurityGroupRequested"
70
- ReasonResourceAllocated = "ResourceAllocated"
71
- ReasonBranchAllocationFailed = "BranchAllocationFailed"
72
- ReasonBranchENIAnnotationFailed = "BranchENIAnnotationFailed"
73
-
74
- ReasonTrunkENICreationFailed = "TrunkENICreationFailed"
75
-
76
81
deleteQueueRequeueRequest = ctrl.Result {RequeueAfter : time .Second * 30 , Requeue : true }
77
82
78
83
// NodeDeleteRequeueRequestDelay represents the time after which the resources belonging to a node will be cleaned
79
84
// up after receiving the actual node delete event.
80
85
NodeDeleteRequeueRequestDelay = time .Minute * 5
81
86
82
87
prometheusRegistered = false
83
- )
84
88
85
- var (
86
89
ErrTrunkExistInCache = fmt .Errorf ("trunk eni already exist in cache" )
87
90
ErrTrunkNotInCache = fmt .Errorf ("trunk eni not present in cache" )
88
91
)
@@ -131,9 +134,9 @@ func prometheusRegister() {
131
134
}
132
135
}
133
136
134
- // timeSinceMs returns the time since MS from the start time
135
- func timeSinceMs (start time.Time ) float64 {
136
- return float64 (time .Since (start ).Milliseconds ())
137
+ // timeSinceSeconds returns the time elapsed in seconds from the start time
138
+ func timeSinceSeconds (start time.Time ) float64 {
139
+ return float64 (time .Since (start ).Seconds ())
137
140
}
138
141
139
142
// InitResources initialized the resource for the given node name. The initialized trunk ENI is stored in
@@ -172,9 +175,9 @@ func (b *branchENIProvider) InitResource(instance ec2.EC2Instance) error {
172
175
173
176
utils .SendNodeEventWithNodeName (b .apiWrapper .K8sAPI , nodeName , utils .NodeTrunkFailedInitializationReason , "The node failed initializing trunk interface" , v1 .EventTypeNormal , b .log )
174
177
branchProviderOperationsErrCount .WithLabelValues ("init" ).Inc ()
175
- return fmt .Errorf ("initalizing trunk, %w" , err )
178
+ return fmt .Errorf ("initializing trunk, %w" , err )
176
179
}
177
- branchProviderOperationLatency .WithLabelValues (operationInitTrunk , "1" ).Observe (timeSinceMs (start ))
180
+ branchProviderOperationLatency .WithLabelValues (operationInitTrunk , "1" ).Observe (timeSinceSeconds (start ))
178
181
179
182
// Add the Trunk ENI to cache
180
183
if err := b .addTrunkToCache (nodeName , trunkENI ); err != nil {
@@ -367,7 +370,7 @@ func (b *branchENIProvider) CreateAndAnnotateResources(podNamespace string, podN
367
370
}
368
371
369
372
branchProviderOperationLatency .WithLabelValues (operationCreateBranchENI , strconv .Itoa (resourceCount )).
370
- Observe (timeSinceMs (start ))
373
+ Observe (timeSinceSeconds (start ))
371
374
372
375
jsonBytes , err := json .Marshal (branchENIs )
373
376
if err != nil {
@@ -377,6 +380,7 @@ func (b *branchENIProvider) CreateAndAnnotateResources(podNamespace string, podN
377
380
return ctrl.Result {}, err
378
381
}
379
382
383
+ start = time .Now ()
380
384
// Annotate the pod with the created resources
381
385
err = b .apiWrapper .PodAPI .AnnotatePod (pod .Namespace , pod .Name , pod .UID ,
382
386
config .ResourceNamePodENI , string (jsonBytes ))
@@ -393,8 +397,8 @@ func (b *branchENIProvider) CreateAndAnnotateResources(podNamespace string, podN
393
397
b .apiWrapper .K8sAPI .BroadcastEvent (pod , ReasonResourceAllocated ,
394
398
fmt .Sprintf ("Allocated %s to the pod" , string (jsonBytes )), v1 .EventTypeNormal )
395
399
396
- branchProviderOperationLatency .WithLabelValues (operationCreateBranchENIAndAnnotate , strconv .Itoa (resourceCount )).
397
- Observe (timeSinceMs (start ))
400
+ branchProviderOperationLatency .WithLabelValues (operationAnnotateBranchENI , strconv .Itoa (resourceCount )).
401
+ Observe (timeSinceSeconds (start ))
398
402
399
403
log .Info ("created and annotated branch interface/s successfully" , "branches" , branchENIs )
400
404
0 commit comments