Skip to content

Commit

Permalink
[JENKINS-73788] Reduce metrics bloat relating to provisioning requests (
Browse files Browse the repository at this point in the history
#1604)

Co-authored-by: Bas van Erp <bas.van.erp@politie.nl>
  • Loading branch information
PayBas and Bas van Erp committed Sep 17, 2024
1 parent 7345138 commit 1719f9d
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -599,7 +598,6 @@ public Collection<NodeProvisioner.PlannedNode> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.csanchez.jenkins.plugins.kubernetes;

import hudson.model.Label;
import java.util.Locale;

public class MetricNames {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.csanchez.jenkins.plugins.kubernetes;

import hudson.model.labels.LabelAtom;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1719f9d

Please sign in to comment.