Skip to content

Commit

Permalink
Add build durations metric
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyVMarkelov committed Jan 13, 2020
1 parent ec163a7 commit d5d2a93
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [1.0.7] (v5.8.x-6.10.x)

- Added new metric: bamboo_build_duration_histogram [#5](https://github.com/AndreyVMarkelov/bamboo-prometheus-exporter/issues/5)

## [1.0.6] (v5.8.x-6.10.x)

- Added new metric: bamboo_lifecycle_state_gauge
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ru.andreymarkelov.atlas.plugins</groupId>
<artifactId>prom-bamboo-exporter</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
<packaging>atlassian-plugin</packaging>

<name>Prometheus Exporter For Bamboo</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public MetricListener(

@EventListener
public void buildFinishedEvent(BuildFinishedEvent buildFinishedEvent) {
long duration = 0;
if (buildFinishedEvent.getBuildContext() != null) {
duration = buildFinishedEvent.getTimestamp() - buildFinishedEvent.getBuildContext().getCurrentResult().getTasksStartDate().getTime();
}
metricCollector.finishedBuildsCounter(buildFinishedEvent.getBuildPlanKey(), buildFinishedEvent.getBuildState().name());
metricCollector.finishedBuildsDuration(buildFinishedEvent.getBuildPlanKey(), duration);
}

@EventListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ public interface MetricCollector {
CollectorRegistry getRegistry();
void errorsCounter(boolean isNew);
void finishedBuildsCounter(String planKey, String state);

/**
* Duration of plan in milliseconds.
*
* @param planKey - plan key.
* @param duration - plan duration to complete (any state) in milliseconds.
*/
void finishedBuildsDuration(String planKey, long duration);

void canceledBuildsCounter(String planKey);
void finishedDeploysCounter(String planKey, String state);
void buildQueueTimeoutCounter(String planKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import com.atlassian.bamboo.plan.TopLevelPlan;
import com.atlassian.bamboo.plan.branch.ChainBranch;
import com.atlassian.extras.api.bamboo.BambooLicense;
import io.prometheus.client.Collector;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.Gauge;
import io.prometheus.client.*;
import io.prometheus.client.hotspot.DefaultExports;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -74,6 +71,12 @@ public class MetricCollectorImpl extends Collector implements MetricCollector, I
.labelNames("planKey", "state")
.create();

private final Histogram finishedBuildsDuration = Histogram.build()
.name("bamboo_build_duration_histogram")
.help("Finished Builds Duration in ms")
.labelNames("planKey")
.create();

private final Counter canceledBuildsCounter = Counter.build()
.name("bamboo_canceled_build_count")
.help("Canceled Builds Count")
Expand Down Expand Up @@ -166,6 +169,11 @@ public void finishedBuildsCounter(String planKey, String state) {
finishedBuildsCounter.labels(planKey, state).inc();
}

@Override
public void finishedBuildsDuration(String planKey, long duration) {
finishedBuildsDuration.labels(planKey).observe(duration);
}

@Override
public void canceledBuildsCounter(String planKey) {
canceledBuildsCounter.labels(planKey).inc();
Expand Down Expand Up @@ -223,6 +231,7 @@ private List<MetricFamilySamples> collectInternal() {
result.addAll(lifecycleStateGauge.collect());
result.addAll(errorsCounter.collect());
result.addAll(finishedBuildsCounter.collect());
result.addAll(finishedBuildsDuration.collect());
result.addAll(canceledBuildsCounter.collect());
result.addAll(finishedDeploysCounter.collect());
result.addAll(buildQueueTimeoutCounter.collect());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/atlassian-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<param name="plugin-icon">/ru/andreymarkelov/atlas/plugins/prombambooexporter/images/prom-exporter-sm.png</param>
<param name="vendor-icon">/ru/andreymarkelov/atlas/plugins/prombambooexporter/images/32.jpg</param>
<param name="vendor-logo">/ru/andreymarkelov/atlas/plugins/prombambooexporter/images/144.jpg</param>
<param name="plugin-banner">/ru/andreymarkelov/atlas/plugins/prombambooexporter/images/banner.png</param>
<param name="configure.url">/admin/prommetrics/settings.action</param>
<param name="atlassian-data-center-compatible">true</param>
</plugin-info>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d5d2a93

Please sign in to comment.