How to use Calc method of metrics Package

Best K6 code snippet using metrics.Calc

replica_calculator_test.go

Source:replica_calculator_test.go Github

copy

Full Screen

...50 singleObject *autoscalingv2.CrossVersionObjectReference51 targetUtilization int6452 expectedUtilization int6453}54type replicaCalcTestCase struct {55 currentReplicas int3256 expectedReplicas int3257 expectedError error58 timestamp time.Time59 resource *resourceInfo60 metric *metricInfo61 podReadiness []v1.ConditionStatus62}63const (64 testNamespace = "test-namespace"65 podNamePrefix = "test-pod"66 numContainersPerPod = 267)68func (tc *replicaCalcTestCase) prepareTestClient(t *testing.T) (*fake.Clientset, *metricsfake.Clientset, *cmfake.FakeCustomMetricsClient) {69 fakeClient := &fake.Clientset{}70 fakeClient.AddReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) {71 obj := &v1.PodList{}72 for i := 0; i < int(tc.currentReplicas); i++ {73 podReadiness := v1.ConditionTrue74 if tc.podReadiness != nil {75 podReadiness = tc.podReadiness[i]76 }77 podName := fmt.Sprintf("%s-%d", podNamePrefix, i)78 pod := v1.Pod{79 Status: v1.PodStatus{80 Phase: v1.PodRunning,81 Conditions: []v1.PodCondition{82 {83 Type: v1.PodReady,84 Status: podReadiness,85 },86 },87 },88 ObjectMeta: metav1.ObjectMeta{89 Name: podName,90 Namespace: testNamespace,91 Labels: map[string]string{92 "name": podNamePrefix,93 },94 },95 Spec: v1.PodSpec{96 Containers: []v1.Container{{}, {}},97 },98 }99 if tc.resource != nil && i < len(tc.resource.requests) {100 pod.Spec.Containers[0].Resources = v1.ResourceRequirements{101 Requests: v1.ResourceList{102 tc.resource.name: tc.resource.requests[i],103 },104 }105 pod.Spec.Containers[1].Resources = v1.ResourceRequirements{106 Requests: v1.ResourceList{107 tc.resource.name: tc.resource.requests[i],108 },109 }110 }111 obj.Items = append(obj.Items, pod)112 }113 return true, obj, nil114 })115 fakeMetricsClient := &metricsfake.Clientset{}116 // NB: we have to sound like Gollum due to gengo's inability to handle already-plural resource names117 fakeMetricsClient.AddReactor("list", "pods", func(action core.Action) (handled bool, ret runtime.Object, err error) {118 if tc.resource != nil {119 metrics := &metricsapi.PodMetricsList{}120 for i, resValue := range tc.resource.levels {121 podName := fmt.Sprintf("%s-%d", podNamePrefix, i)122 if len(tc.resource.podNames) > i {123 podName = tc.resource.podNames[i]124 }125 // NB: the list reactor actually does label selector filtering for us,126 // so we have to make sure our results match the label selector127 podMetric := metricsapi.PodMetrics{128 ObjectMeta: metav1.ObjectMeta{129 Name: podName,130 Namespace: testNamespace,131 Labels: map[string]string{"name": podNamePrefix},132 },133 Timestamp: metav1.Time{Time: tc.timestamp},134 Containers: make([]metricsapi.ContainerMetrics, numContainersPerPod),135 }136 for i := 0; i < numContainersPerPod; i++ {137 podMetric.Containers[i] = metricsapi.ContainerMetrics{138 Name: fmt.Sprintf("container%v", i),139 Usage: clientv1.ResourceList{140 clientv1.ResourceName(tc.resource.name): *resource.NewMilliQuantity(141 int64(resValue),142 resource.DecimalSI),143 },144 }145 }146 metrics.Items = append(metrics.Items, podMetric)147 }148 return true, metrics, nil149 }150 return true, nil, fmt.Errorf("no pod resource metrics specified in test client")151 })152 fakeCMClient := &cmfake.FakeCustomMetricsClient{}153 fakeCMClient.AddReactor("get", "*", func(action core.Action) (handled bool, ret runtime.Object, err error) {154 getForAction, wasGetFor := action.(cmfake.GetForAction)155 if !wasGetFor {156 return true, nil, fmt.Errorf("expected a get-for action, got %v instead", action)157 }158 if tc.metric == nil {159 return true, nil, fmt.Errorf("no custom metrics specified in test client")160 }161 assert.Equal(t, tc.metric.name, getForAction.GetMetricName(), "the metric requested should have matched the one specified")162 if getForAction.GetName() == "*" {163 metrics := cmapi.MetricValueList{}164 // multiple objects165 assert.Equal(t, "pods", getForAction.GetResource().Resource, "the type of object that we requested multiple metrics for should have been pods")166 for i, level := range tc.metric.levels {167 podMetric := cmapi.MetricValue{168 DescribedObject: clientv1.ObjectReference{169 Kind: "Pod",170 Name: fmt.Sprintf("%s-%d", podNamePrefix, i),171 Namespace: testNamespace,172 },173 Timestamp: metav1.Time{Time: tc.timestamp},174 MetricName: tc.metric.name,175 Value: *resource.NewMilliQuantity(level, resource.DecimalSI),176 }177 metrics.Items = append(metrics.Items, podMetric)178 }179 return true, &metrics, nil180 } else {181 name := getForAction.GetName()182 mapper := api.Registry.RESTMapper()183 metrics := &cmapi.MetricValueList{}184 assert.NotNil(t, tc.metric.singleObject, "should have only requested a single-object metric when calling GetObjectMetricReplicas")185 gk := schema.FromAPIVersionAndKind(tc.metric.singleObject.APIVersion, tc.metric.singleObject.Kind).GroupKind()186 mapping, err := mapper.RESTMapping(gk)187 if err != nil {188 return true, nil, fmt.Errorf("unable to get mapping for %s: %v", gk.String(), err)189 }190 groupResource := schema.GroupResource{Group: mapping.GroupVersionKind.Group, Resource: mapping.Resource}191 assert.Equal(t, groupResource.String(), getForAction.GetResource().Resource, "should have requested metrics for the resource matching the GroupKind passed in")192 assert.Equal(t, tc.metric.singleObject.Name, name, "should have requested metrics for the object matching the name passed in")193 metrics.Items = []cmapi.MetricValue{194 {195 DescribedObject: clientv1.ObjectReference{196 Kind: tc.metric.singleObject.Kind,197 APIVersion: tc.metric.singleObject.APIVersion,198 Name: name,199 },200 Timestamp: metav1.Time{Time: tc.timestamp},201 MetricName: tc.metric.name,202 Value: *resource.NewMilliQuantity(int64(tc.metric.levels[0]), resource.DecimalSI),203 },204 }205 return true, metrics, nil206 }207 })208 return fakeClient, fakeMetricsClient, fakeCMClient209}210func (tc *replicaCalcTestCase) runTest(t *testing.T) {211 testClient, testMetricsClient, testCMClient := tc.prepareTestClient(t)212 metricsClient := metrics.NewRESTMetricsClient(testMetricsClient.MetricsV1alpha1(), testCMClient)213 replicaCalc := &ReplicaCalculator{214 metricsClient: metricsClient,215 podsGetter: testClient.Core(),216 }217 selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{218 MatchLabels: map[string]string{"name": podNamePrefix},219 })220 if err != nil {221 require.Nil(t, err, "something went horribly wrong...")222 }223 if tc.resource != nil {224 outReplicas, outUtilization, outRawValue, outTimestamp, err := replicaCalc.GetResourceReplicas(tc.currentReplicas, tc.resource.targetUtilization, tc.resource.name, testNamespace, selector)225 if tc.expectedError != nil {226 require.Error(t, err, "there should be an error calculating the replica count")227 assert.Contains(t, err.Error(), tc.expectedError.Error(), "the error message should have contained the expected error message")228 return229 }230 require.NoError(t, err, "there should not have been an error calculating the replica count")231 assert.Equal(t, tc.expectedReplicas, outReplicas, "replicas should be as expected")232 assert.Equal(t, tc.resource.expectedUtilization, outUtilization, "utilization should be as expected")233 assert.Equal(t, tc.resource.expectedValue, outRawValue, "raw value should be as expected")234 assert.True(t, tc.timestamp.Equal(outTimestamp), "timestamp should be as expected")235 } else {236 var outReplicas int32237 var outUtilization int64238 var outTimestamp time.Time239 var err error240 if tc.metric.singleObject != nil {241 outReplicas, outUtilization, outTimestamp, err = replicaCalc.GetObjectMetricReplicas(tc.currentReplicas, tc.metric.targetUtilization, tc.metric.name, testNamespace, tc.metric.singleObject)242 } else {243 outReplicas, outUtilization, outTimestamp, err = replicaCalc.GetMetricReplicas(tc.currentReplicas, tc.metric.targetUtilization, tc.metric.name, testNamespace, selector)244 }245 if tc.expectedError != nil {246 require.Error(t, err, "there should be an error calculating the replica count")247 assert.Contains(t, err.Error(), tc.expectedError.Error(), "the error message should have contained the expected error message")248 return249 }250 require.NoError(t, err, "there should not have been an error calculating the replica count")251 assert.Equal(t, tc.expectedReplicas, outReplicas, "replicas should be as expected")252 assert.Equal(t, tc.metric.expectedUtilization, outUtilization, "utilization should be as expected")253 assert.True(t, tc.timestamp.Equal(outTimestamp), "timestamp should be as expected")254 }255}256func TestReplicaCalcDisjointResourcesMetrics(t *testing.T) {257 tc := replicaCalcTestCase{258 currentReplicas: 1,259 expectedError: fmt.Errorf("no metrics returned matched known pods"),260 resource: &resourceInfo{261 name: v1.ResourceCPU,262 requests: []resource.Quantity{resource.MustParse("1.0")},263 levels: []int64{100},264 podNames: []string{"an-older-pod-name"},265 targetUtilization: 100,266 },267 }268 tc.runTest(t)269}270func TestReplicaCalcScaleUp(t *testing.T) {271 tc := replicaCalcTestCase{272 currentReplicas: 3,273 expectedReplicas: 5,274 resource: &resourceInfo{275 name: v1.ResourceCPU,276 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},277 levels: []int64{300, 500, 700},278 targetUtilization: 30,279 expectedUtilization: 50,280 expectedValue: numContainersPerPod * 500,281 },282 }283 tc.runTest(t)284}285func TestReplicaCalcScaleUpUnreadyLessScale(t *testing.T) {286 tc := replicaCalcTestCase{287 currentReplicas: 3,288 expectedReplicas: 4,289 podReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},290 resource: &resourceInfo{291 name: v1.ResourceCPU,292 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},293 levels: []int64{300, 500, 700},294 targetUtilization: 30,295 expectedUtilization: 60,296 expectedValue: numContainersPerPod * 600,297 },298 }299 tc.runTest(t)300}301func TestReplicaCalcScaleUpUnreadyNoScale(t *testing.T) {302 tc := replicaCalcTestCase{303 currentReplicas: 3,304 expectedReplicas: 3,305 podReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},306 resource: &resourceInfo{307 name: v1.ResourceCPU,308 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},309 levels: []int64{400, 500, 700},310 targetUtilization: 30,311 expectedUtilization: 40,312 expectedValue: numContainersPerPod * 400,313 },314 }315 tc.runTest(t)316}317func TestReplicaCalcScaleUpCM(t *testing.T) {318 tc := replicaCalcTestCase{319 currentReplicas: 3,320 expectedReplicas: 4,321 metric: &metricInfo{322 name: "qps",323 levels: []int64{20000, 10000, 30000},324 targetUtilization: 15000,325 expectedUtilization: 20000,326 },327 }328 tc.runTest(t)329}330func TestReplicaCalcScaleUpCMUnreadyLessScale(t *testing.T) {331 tc := replicaCalcTestCase{332 currentReplicas: 3,333 expectedReplicas: 4,334 podReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionTrue, v1.ConditionFalse},335 metric: &metricInfo{336 name: "qps",337 levels: []int64{50000, 10000, 30000},338 targetUtilization: 15000,339 expectedUtilization: 30000,340 },341 }342 tc.runTest(t)343}344func TestReplicaCalcScaleUpCMUnreadyNoScaleWouldScaleDown(t *testing.T) {345 tc := replicaCalcTestCase{346 currentReplicas: 3,347 expectedReplicas: 3,348 podReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionFalse},349 metric: &metricInfo{350 name: "qps",351 levels: []int64{50000, 15000, 30000},352 targetUtilization: 15000,353 expectedUtilization: 15000,354 },355 }356 tc.runTest(t)357}358func TestReplicaCalcScaleUpCMObject(t *testing.T) {359 tc := replicaCalcTestCase{360 currentReplicas: 3,361 expectedReplicas: 4,362 metric: &metricInfo{363 name: "qps",364 levels: []int64{20000},365 targetUtilization: 15000,366 expectedUtilization: 20000,367 singleObject: &autoscalingv2.CrossVersionObjectReference{368 Kind: "Deployment",369 APIVersion: "extensions/v1beta1",370 Name: "some-deployment",371 },372 },373 }374 tc.runTest(t)375}376func TestReplicaCalcScaleDown(t *testing.T) {377 tc := replicaCalcTestCase{378 currentReplicas: 5,379 expectedReplicas: 3,380 resource: &resourceInfo{381 name: v1.ResourceCPU,382 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},383 levels: []int64{100, 300, 500, 250, 250},384 targetUtilization: 50,385 expectedUtilization: 28,386 expectedValue: numContainersPerPod * 280,387 },388 }389 tc.runTest(t)390}391func TestReplicaCalcScaleDownCM(t *testing.T) {392 tc := replicaCalcTestCase{393 currentReplicas: 5,394 expectedReplicas: 3,395 metric: &metricInfo{396 name: "qps",397 levels: []int64{12000, 12000, 12000, 12000, 12000},398 targetUtilization: 20000,399 expectedUtilization: 12000,400 },401 }402 tc.runTest(t)403}404func TestReplicaCalcScaleDownCMObject(t *testing.T) {405 tc := replicaCalcTestCase{406 currentReplicas: 5,407 expectedReplicas: 3,408 metric: &metricInfo{409 name: "qps",410 levels: []int64{12000},411 targetUtilization: 20000,412 expectedUtilization: 12000,413 singleObject: &autoscalingv2.CrossVersionObjectReference{414 Kind: "Deployment",415 APIVersion: "extensions/v1beta1",416 Name: "some-deployment",417 },418 },419 }420 tc.runTest(t)421}422func TestReplicaCalcScaleDownIgnoresUnreadyPods(t *testing.T) {423 tc := replicaCalcTestCase{424 currentReplicas: 5,425 expectedReplicas: 2,426 podReadiness: []v1.ConditionStatus{v1.ConditionTrue, v1.ConditionTrue, v1.ConditionTrue, v1.ConditionFalse, v1.ConditionFalse},427 resource: &resourceInfo{428 name: v1.ResourceCPU,429 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},430 levels: []int64{100, 300, 500, 250, 250},431 targetUtilization: 50,432 expectedUtilization: 30,433 expectedValue: numContainersPerPod * 300,434 },435 }436 tc.runTest(t)437}438func TestReplicaCalcTolerance(t *testing.T) {439 tc := replicaCalcTestCase{440 currentReplicas: 3,441 expectedReplicas: 3,442 resource: &resourceInfo{443 name: v1.ResourceCPU,444 requests: []resource.Quantity{resource.MustParse("0.9"), resource.MustParse("1.0"), resource.MustParse("1.1")},445 levels: []int64{1010, 1030, 1020},446 targetUtilization: 100,447 expectedUtilization: 102,448 expectedValue: numContainersPerPod * 1020,449 },450 }451 tc.runTest(t)452}453func TestReplicaCalcToleranceCM(t *testing.T) {454 tc := replicaCalcTestCase{455 currentReplicas: 3,456 expectedReplicas: 3,457 metric: &metricInfo{458 name: "qps",459 levels: []int64{20000, 21000, 21000},460 targetUtilization: 20000,461 expectedUtilization: 20666,462 },463 }464 tc.runTest(t)465}466func TestReplicaCalcToleranceCMObject(t *testing.T) {467 tc := replicaCalcTestCase{468 currentReplicas: 3,469 expectedReplicas: 3,470 metric: &metricInfo{471 name: "qps",472 levels: []int64{20666},473 targetUtilization: 20000,474 expectedUtilization: 20666,475 singleObject: &autoscalingv2.CrossVersionObjectReference{476 Kind: "Deployment",477 APIVersion: "extensions/v1beta1",478 Name: "some-deployment",479 },480 },481 }482 tc.runTest(t)483}484func TestReplicaCalcSuperfluousMetrics(t *testing.T) {485 tc := replicaCalcTestCase{486 currentReplicas: 4,487 expectedReplicas: 24,488 resource: &resourceInfo{489 name: v1.ResourceCPU,490 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},491 levels: []int64{4000, 9500, 3000, 7000, 3200, 2000},492 targetUtilization: 100,493 expectedUtilization: 587,494 expectedValue: numContainersPerPod * 5875,495 },496 }497 tc.runTest(t)498}499func TestReplicaCalcMissingMetrics(t *testing.T) {500 tc := replicaCalcTestCase{501 currentReplicas: 4,502 expectedReplicas: 3,503 resource: &resourceInfo{504 name: v1.ResourceCPU,505 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},506 levels: []int64{400, 95},507 targetUtilization: 100,508 expectedUtilization: 24,509 expectedValue: 495, // numContainersPerPod * 247, for sufficiently large values of 247510 },511 }512 tc.runTest(t)513}514func TestReplicaCalcEmptyMetrics(t *testing.T) {515 tc := replicaCalcTestCase{516 currentReplicas: 4,517 expectedError: fmt.Errorf("unable to get metrics for resource cpu: no metrics returned from heapster"),518 resource: &resourceInfo{519 name: v1.ResourceCPU,520 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},521 levels: []int64{},522 targetUtilization: 100,523 },524 }525 tc.runTest(t)526}527func TestReplicaCalcEmptyCPURequest(t *testing.T) {528 tc := replicaCalcTestCase{529 currentReplicas: 1,530 expectedError: fmt.Errorf("missing request for"),531 resource: &resourceInfo{532 name: v1.ResourceCPU,533 requests: []resource.Quantity{},534 levels: []int64{200},535 targetUtilization: 100,536 },537 }538 tc.runTest(t)539}540func TestReplicaCalcMissingMetricsNoChangeEq(t *testing.T) {541 tc := replicaCalcTestCase{542 currentReplicas: 2,543 expectedReplicas: 2,544 resource: &resourceInfo{545 name: v1.ResourceCPU,546 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0")},547 levels: []int64{1000},548 targetUtilization: 100,549 expectedUtilization: 100,550 expectedValue: numContainersPerPod * 1000,551 },552 }553 tc.runTest(t)554}555func TestReplicaCalcMissingMetricsNoChangeGt(t *testing.T) {556 tc := replicaCalcTestCase{557 currentReplicas: 2,558 expectedReplicas: 2,559 resource: &resourceInfo{560 name: v1.ResourceCPU,561 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0")},562 levels: []int64{1900},563 targetUtilization: 100,564 expectedUtilization: 190,565 expectedValue: numContainersPerPod * 1900,566 },567 }568 tc.runTest(t)569}570func TestReplicaCalcMissingMetricsNoChangeLt(t *testing.T) {571 tc := replicaCalcTestCase{572 currentReplicas: 2,573 expectedReplicas: 2,574 resource: &resourceInfo{575 name: v1.ResourceCPU,576 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0")},577 levels: []int64{600},578 targetUtilization: 100,579 expectedUtilization: 60,580 expectedValue: numContainersPerPod * 600,581 },582 }583 tc.runTest(t)584}585func TestReplicaCalcMissingMetricsUnreadyNoChange(t *testing.T) {586 tc := replicaCalcTestCase{587 currentReplicas: 3,588 expectedReplicas: 3,589 podReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},590 resource: &resourceInfo{591 name: v1.ResourceCPU,592 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},593 levels: []int64{100, 450},594 targetUtilization: 50,595 expectedUtilization: 45,596 expectedValue: numContainersPerPod * 450,597 },598 }599 tc.runTest(t)600}601func TestReplicaCalcMissingMetricsUnreadyScaleUp(t *testing.T) {602 tc := replicaCalcTestCase{603 currentReplicas: 3,604 expectedReplicas: 4,605 podReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue},606 resource: &resourceInfo{607 name: v1.ResourceCPU,608 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},609 levels: []int64{100, 2000},610 targetUtilization: 50,611 expectedUtilization: 200,612 expectedValue: numContainersPerPod * 2000,613 },614 }615 tc.runTest(t)616}617func TestReplicaCalcMissingMetricsUnreadyScaleDown(t *testing.T) {618 tc := replicaCalcTestCase{619 currentReplicas: 4,620 expectedReplicas: 3,621 podReadiness: []v1.ConditionStatus{v1.ConditionFalse, v1.ConditionTrue, v1.ConditionTrue, v1.ConditionTrue},622 resource: &resourceInfo{623 name: v1.ResourceCPU,624 requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},625 levels: []int64{100, 100, 100},626 targetUtilization: 50,627 expectedUtilization: 10,628 expectedValue: numContainersPerPod * 100,629 },630 }631 tc.runTest(t)632}633// TestComputedToleranceAlgImplementation is a regression test which634// back-calculates a minimal percentage for downscaling based on a small percentage635// increase in pod utilization which is calibrated against the tolerance value.636func TestReplicaCalcComputedToleranceAlgImplementation(t *testing.T) {637 startPods := int32(10)638 // 150 mCPU per pod.639 totalUsedCPUOfAllPods := int64(startPods * 150)640 // Each pod starts out asking for 2X what is really needed.641 // This means we will have a 50% ratio of used/requested642 totalRequestedCPUOfAllPods := int32(2 * totalUsedCPUOfAllPods)643 requestedToUsed := float64(totalRequestedCPUOfAllPods / int32(totalUsedCPUOfAllPods))644 // Spread the amount we ask over 10 pods. We can add some jitter later in reportedLevels.645 perPodRequested := totalRequestedCPUOfAllPods / startPods646 // Force a minimal scaling event by satisfying (tolerance < 1 - resourcesUsedRatio).647 target := math.Abs(1/(requestedToUsed*(1-tolerance))) + .01648 finalCpuPercentTarget := int32(target * 100)649 resourcesUsedRatio := float64(totalUsedCPUOfAllPods) / float64(float64(totalRequestedCPUOfAllPods)*target)650 // i.e. .60 * 20 -> scaled down expectation.651 finalPods := int32(math.Ceil(resourcesUsedRatio * float64(startPods)))652 // To breach tolerance we will create a utilization ratio difference of tolerance to usageRatioToleranceValue)653 tc := replicaCalcTestCase{654 currentReplicas: startPods,655 expectedReplicas: finalPods,656 resource: &resourceInfo{657 name: v1.ResourceCPU,658 levels: []int64{659 totalUsedCPUOfAllPods / 10,660 totalUsedCPUOfAllPods / 10,661 totalUsedCPUOfAllPods / 10,662 totalUsedCPUOfAllPods / 10,663 totalUsedCPUOfAllPods / 10,664 totalUsedCPUOfAllPods / 10,665 totalUsedCPUOfAllPods / 10,666 totalUsedCPUOfAllPods / 10,667 totalUsedCPUOfAllPods / 10,...

Full Screen

Full Screen

Calc

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := metrics.New(10.0, 20.0)4 fmt.Println(c.Calc())5}6import (7func main() {8 c := metrics.New(10.0, 20.0)9 fmt.Println(c.Calc())10}11import (12func main() {13 c := metrics.New(10.0, 20.0)14 fmt.Println(c.Calc())15}16import (17func main() {18 c := metrics.New(10.0, 20.0)19 fmt.Println(c.Calc())20}21import (22func main() {23 c := metrics.New(10.0, 20.0)24 fmt.Println(c.Calc())25}26import (27func main() {28 c := metrics.New(10.0, 20.0)29 fmt.Println(c.Calc())30}31import (32func main() {33 c := metrics.New(10.0, 20.0)34 fmt.Println(c.Calc())35}36import (37func main() {38 c := metrics.New(10.0, 20.0)39 fmt.Println(c.Calc())40}41import (42func main() {43 c := metrics.New(10.0, 20.0)44 fmt.Println(c.Calc())45}

Full Screen

Full Screen

Calc

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(stringutil.Reverse("Hello, world."))4}5import (6func main() {7 fmt.Println(stringutil.Reverse("Hello, world."))8}9import (10func main() {11 beego.Run()12}13 /usr/local/go/src/github.com/astaxie/beego (from $GOROOT)14 /home/username/go/src/github.com/astaxie/beego (from $GOPATH)15import (16func main() {17 beego.Run()18}19 /usr/local/go/src/github.com/astaxie/beego (from $GOROOT)

Full Screen

Full Screen

Calc

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 m := metrics.New(3.14, 10.0)5 fmt.Println(m.Area())6 fmt.Println(m.Perimeter())7}8We can also import the metrics package as follows:9import (10In the above example, we have imported the metrics package and renamed it to metrics. This helps us to avoid the name collision with other packages. We can now use the Calc method of the metrics package as follows:11fmt.Println(metrics.Calc(3.14, 10.0))12In the above example, we have imported the metrics package and renamed it to metrics. This helps us to avoid the name collision with other packages. We can now use the Calc method of the metrics package as follows:13fmt.Println(metrics.Calc(3.14, 10.0))14In the above example, we have imported the metrics package and renamed it to metrics. This helps us to avoid the name collision with other packages. We can now use the Calc method of the metrics package as follows:15fmt.Println(metrics.Calc(3.14, 10.0))16In the above example, we have imported the metrics package and renamed it to metrics. This helps us to avoid the name collision with other packages. We can now use the Calc method of the metrics package as follows:17fmt.Println(metrics.Calc(3.14, 10.0))18In the above example, we have imported the metrics package and renamed it to metrics. This helps us to avoid the name collision with other packages. We can now use the Calc method of the metrics package as follows:19fmt.Println(metrics.Calc(3.14, 10.0))

Full Screen

Full Screen

Calc

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "metrics"3func main() {4 fmt.Println("Hello World")5 fmt.Println(metrics.Calc(10, 5))6}7func Calc(x int, y int) int {8}9func Calc(x int, y int) int {10}11./1.go:3:2: imported and not used: "fmt"12import "fmt"13import "calc"14func main() {15 fmt.Println("Hello World")16 fmt.Println(calc.Calc(10, 5))17}18import "fmt"19import _ "calc"20func main() {21 fmt.Println("Hello World")22}

Full Screen

Full Screen

Calc

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello from main")4 fmt.Println("Result is ", metrics.Calc(5, 2))5}6import (7func main() {8 fmt.Println("Hello from main")9 fmt.Println("Result is ", metrics.Calc(5, 2))10}11import (12func main() {13 fmt.Println("Hello from main")14 fmt.Println("Result is ", metrics.Calc(5, 2))15}16import (17func main() {18 fmt.Println("Hello from main")19 fmt.Println("Result is ", metrics.Calc(5, 2))20}21import (22func main() {23 fmt.Println("Hello from main")24 fmt.Println("Result is ", metrics.Calc(5, 2))25}26import (27func main() {28 fmt.Println("Hello from main")29 fmt.Println("Result is ", metrics.Calc(5, 2))30}31import (32func main() {33 fmt.Println("Hello from main")34 fmt.Println("Result is ", metrics.Calc(5, 2))35}36import (37func main() {38 fmt.Println("

Full Screen

Full Screen

Calc

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(metrics.Calc(10, 20))4}5import (6func main() {7 fmt.Println(metrics.Calc(100, 200))8}9import (10func main() {11 fmt.Println(metrics.Calc(10, 20))12}13import (14func main() {15 fmt.Println(metrics.Calc(100, 200))16}

Full Screen

Full Screen

Calc

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/rahul-golang/rahulmetrics"3func main() {4 result = m.Calc(10, 5)5 fmt.Println("Result is ", result)6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful