From 091152bac8dd67de415b9933512303a8f709510b Mon Sep 17 00:00:00 2001 From: Bas van Erp Date: Tue, 17 Sep 2024 13:35:06 +0200 Subject: [PATCH] JENKINS-73788 Reduce metrics bloat relating to provision.request --- .../plugins/kubernetes/KubernetesCloud.java | 2 -- .../jenkins/plugins/kubernetes/MetricNames.java | 6 ------ .../plugins/kubernetes/MetricNamesTest.java | 17 ----------------- .../pipeline/KubernetesPipelineTest.java | 4 ---- 4 files changed, 29 deletions(-) diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java index 10d30fcba6..81f5091db9 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesCloud.java @@ -2,7 +2,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.commons.lang.StringUtils.isEmpty; -import static org.csanchez.jenkins.plugins.kubernetes.MetricNames.metricNameForLabel; import com.cloudbees.plugins.credentials.CredentialsMatchers; import com.cloudbees.plugins.credentials.common.StandardCredentials; @@ -599,7 +598,6 @@ public Collection provision( @NonNull final Cloud.CloudState state, final int excessWorkload) { var limitRegistrationResults = new LimitRegistrationResults(this); try { - Metrics.metricRegistry().meter(metricNameForLabel(state.getLabel())).mark(excessWorkload); Label label = state.getLabel(); // Planned nodes, will be launched on the next round of NodeProvisioner int plannedCapacity = state.getAdditionalPlannedCapacity(); diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/MetricNames.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/MetricNames.java index ee586771d3..23a48bc445 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/MetricNames.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/MetricNames.java @@ -1,6 +1,5 @@ package org.csanchez.jenkins.plugins.kubernetes; -import hudson.model.Label; import java.util.Locale; public class MetricNames { @@ -21,9 +20,4 @@ public static String metricNameForPodStatus(String status) { String formattedStatus = status == null ? "null" : status.toLowerCase(Locale.getDefault()); return PREFIX + ".pods.launch.status." + formattedStatus; } - - public static String metricNameForLabel(Label label) { - String labelText = (label == null) ? "nolabel" : label.getDisplayName(); - return String.format("%s.%s.provision.request", PREFIX, labelText); - } } diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/MetricNamesTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/MetricNamesTest.java index 892125a133..6856045815 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/MetricNamesTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/MetricNamesTest.java @@ -1,6 +1,5 @@ package org.csanchez.jenkins.plugins.kubernetes; -import hudson.model.labels.LabelAtom; import org.junit.Assert; import org.junit.Test; @@ -29,20 +28,4 @@ public void metricNameForPodStatusChangeStatusToLowercase() { Assert.assertEquals(expected, actual); } - - @Test - public void metricNameForLabelAddsNoLabelIfLabelIsNull() { - String expected = "kubernetes.cloud.nolabel.provision.request"; - String actual = MetricNames.metricNameForLabel(null); - - Assert.assertEquals(expected, actual); - } - - @Test - public void metricNameForLabelAddsLabelValue() { - String expected = "kubernetes.cloud.java.provision.request"; - String actual = MetricNames.metricNameForLabel(new LabelAtom("java")); - - Assert.assertEquals(expected, actual); - } } diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java index b5b23ac122..a7b43a9158 100644 --- a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java @@ -252,10 +252,6 @@ public void runInPod() throws Exception { emptyIterable()); assertTrue(Metrics.metricRegistry().counter(MetricNames.PODS_LAUNCHED).getCount() > 0); - assertTrue(Metrics.metricRegistry() - .meter(MetricNames.metricNameForLabel(Label.parseExpression("runInPod"))) - .getCount() - > 0); } @Test