Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/scripts/sync-api-diffs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ mkdir -p "$out_dir"
for report in "${reports[@]}"; do
# report path: <repo>/<module path>/target/japicmp/api-diff.diff
module="$(basename "$(dirname "$(dirname "$(dirname "$report")")")")"
# Japicmp emits a trailing blank line, which flint rejects in committed reports.
grep -vE '^(WARNING: You are using the option|Semantic versioning suggestion)' \
"$report" >"$out_dir/$module.txt"
"$report" | awk '
NF { last = NR }
{ lines[NR] = $0 }
END {
for (i = 1; i <= last; i++) print lines[i]
}
' >"$out_dir/$module.txt"
done

echo "Wrote ${#reports[@]} API diff report(s) to docs/apidiffs/current_vs_latest/."

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions docs/content/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,15 @@ scrape_configs:
static_configs:
- targets: ["localhost:9400"]
```

## Library version

Get the Maven version of the Prometheus Java Metrics Library's core artifact with
`PrometheusMetricsVersion.getVersion()`:

```java
String version = io.prometheus.metrics.core.PrometheusMetricsVersion.getVersion();
```

The result matches the `prometheus-metrics-core` artifact version, including a `-SNAPSHOT` suffix
when present. It is not the Prometheus server version.
47 changes: 47 additions & 0 deletions prometheus-metrics-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,53 @@

<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>generate-version-class</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/version</outputDirectory>
<resources>
<resource>
<directory>src/main/version-template</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-version-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/version</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<prometheus.metrics.core.version>${project.version}</prometheus.metrics.core.version>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.prometheus.metrics.core;

import io.prometheus.metrics.annotations.StableApi;

/** Provides the version of the Prometheus Java Metrics Library. */
@StableApi
public final class PrometheusMetricsVersion {

private PrometheusMetricsVersion() {}

/**
* Returns the Maven version of the {@code prometheus-metrics-core} artifact containing this
* class.
*
* @return the artifact version, including any suffix such as {@code -SNAPSHOT}
*/
public static String getVersion() {
return VersionInfo.VERSION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.prometheus.metrics.core;

/** Generated version metadata. */
final class VersionInfo {

static final String VERSION = "${project.version}";

private VersionInfo() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.prometheus.metrics.core;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

class PrometheusMetricsVersionTest {

@Test
void versionMatchesMavenProjectVersion() {
String version = PrometheusMetricsVersion.getVersion();

assertThat(version).isEqualTo(System.getProperty("prometheus.metrics.core.version"));
assertThat(version).isNotBlank().doesNotContain("${", "}");
}
}
Loading