Skip to content

Commit

Permalink
Add tags and create verstion 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole Hochleiter committed Jun 5, 2019
1 parent 308baec commit 94a18a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
18 changes: 17 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>de.dmeiners</groupId>
<artifactId>sonar-prometheus-exporter</artifactId>
<packaging>sonar-plugin</packaging>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0</version>
<url>https://github.com/dmeiners88/sonarqube-prometheus-exporter</url>
<licenses>
<license>
Expand Down Expand Up @@ -38,6 +38,7 @@
<sonar.apiVersion>7.0</sonar.apiVersion>
<jdk.min.version>1.8</jdk.min.version>
<sonar.sources>src/main/java</sonar.sources>
<sonar.test>src/main/test</sonar.test>
</properties>

<dependencies>
Expand All @@ -62,6 +63,21 @@
<artifactId>simpleclient_common</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>



</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.dmeiners.sonar.prometheus;

import com.google.protobuf.ProtocolStringList;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Gauge;
import io.prometheus.client.exporter.common.TextFormat;
Expand All @@ -13,6 +14,7 @@
import org.sonarqube.ws.client.WsClient;
import org.sonarqube.ws.client.WsClientFactories;
import org.sonarqube.ws.client.components.SearchRequest;
import org.sonarqube.ws.client.components.ShowRequest;
import org.sonarqube.ws.client.measures.ComponentRequest;

import java.io.OutputStream;
Expand Down Expand Up @@ -74,8 +76,8 @@ public void define(Context context) {
wsResponse.getComponent().getMeasuresList().forEach(measure -> {

if (this.gauges.containsKey(measure.getMetric())) {

this.gauges.get(measure.getMetric()).labels(project.getKey(), project.getName()).set(Double.valueOf(measure.getValue()));
String tags = getTagsFromComponent(wsClient, project.getKey());
this.gauges.get(measure.getMetric()).labels(project.getKey(), project.getName(), tags).set(Double.valueOf(measure.getValue()));
}
});
});
Expand Down Expand Up @@ -112,11 +114,12 @@ private void updateEnabledGauges() {

CollectorRegistry.defaultRegistry.clear();

this.enabledMetrics.forEach(metric -> gauges.put(metric.getKey(), Gauge.build()
.name(METRIC_PREFIX + metric.getKey())
.help(metric.getDescription())
.labelNames("key", "name")
.register()));
this.enabledMetrics.forEach(metric -> gauges.put(
metric.getKey(), Gauge.build()
.name(METRIC_PREFIX + metric.getKey())
.help(metric.getDescription())
.labelNames("key", "name", "tags")
.register()));
}

private Measures.ComponentWsResponse getMeasures(WsClient wsClient, Components.Component project) {
Expand All @@ -137,4 +140,10 @@ private List<Components.Component> getProjects(WsClient wsClient) {
.setPs("500"))
.getComponentsList();
}

private String getTagsFromComponent(WsClient wsClient, String compId) {
ShowRequest request = new ShowRequest().setComponent(compId);
Components.Component result = wsClient.components().show(request).getComponent();
return result.getTagsOrBuilder().getTagsList().toString();
}
}

0 comments on commit 94a18a3

Please sign in to comment.