-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into buffer-sync
- Loading branch information
Showing
23 changed files
with
1,931 additions
and
1,825 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Build | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 17 | ||
distribution: temurin | ||
cache: 'maven' | ||
- name: Shaded dependencies | ||
run: | | ||
cd prometheus-metrics-shaded-dependencies | ||
../mvnw clean install | ||
- name: Run the Maven verify phase | ||
run: | | ||
./mvnw clean install | ||
./mvnw javadoc:jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
* Fabian Stäber <[email protected]> @fstab | ||
* Doug Hoard <[email protected]> @dhoard | ||
* Tom Wilkie <[email protected]> @tomwilkie | ||
* Gregor Zeitlinger <[email protected]> @zeitlinger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...mentation-jvm/src/test/java/io/prometheus/metrics/instrumentation/jvm/JvmMetricsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.prometheus.metrics.instrumentation.jvm; | ||
|
||
import io.prometheus.metrics.model.registry.PrometheusRegistry; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class JvmMetricsTest { | ||
|
||
@Test | ||
public void testRegisterIdempotent() { | ||
PrometheusRegistry registry = new PrometheusRegistry(); | ||
assertEquals(0, registry.scrape().size()); | ||
JvmMetrics.builder().register(registry); | ||
assertTrue(registry.scrape().size() > 0); | ||
JvmMetrics.builder().register(registry); | ||
} | ||
} |
123 changes: 62 additions & 61 deletions
123
prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/Collector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,77 @@ | ||
package io.prometheus.metrics.model.registry; | ||
|
||
import io.prometheus.metrics.model.snapshots.MetricSnapshot; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import static io.prometheus.metrics.model.snapshots.PrometheusNaming.prometheusName; | ||
|
||
/** | ||
* To be registered with the Prometheus collector registry. | ||
* See <i>Overall Structure</i> on | ||
* <a href="https://prometheus.io/docs/instrumenting/writing_clientlibs/">https://prometheus.io/docs/instrumenting/writing_clientlibs/</a>. | ||
* To be registered with the Prometheus collector registry. See <i>Overall Structure</i> on <a | ||
* href="https://prometheus.io/docs/instrumenting/writing_clientlibs/">https://prometheus.io/docs/instrumenting/writing_clientlibs/</a>. | ||
*/ | ||
@FunctionalInterface | ||
public interface Collector { | ||
|
||
/** | ||
* Called when the Prometheus server scrapes metrics. | ||
*/ | ||
MetricSnapshot collect(); | ||
/** Called when the Prometheus server scrapes metrics. */ | ||
MetricSnapshot collect(); | ||
|
||
/** | ||
* Provides Collector with the details of the request issued by Prometheus to allow multi-target pattern implementation | ||
* Override to implement request dependent logic to provide MetricSnapshot | ||
*/ | ||
default MetricSnapshot collect(PrometheusScrapeRequest scrapeRequest) { | ||
return collect(); | ||
} | ||
|
||
/** | ||
* Like {@link #collect()}, but returns {@code null} if {@code includedNames.test(name)} is {@code false}. | ||
* <p> | ||
* Override this if there is a more efficient way than first collecting the snapshot and then discarding it. | ||
*/ | ||
default MetricSnapshot collect(Predicate<String> includedNames) { | ||
MetricSnapshot result = collect(); | ||
if (includedNames.test(result.getMetadata().getPrometheusName())) { | ||
return result; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Like {@link #collect(Predicate)}, but with support for multi-target pattern. | ||
* <p> | ||
* Override this if there is a more efficient way than first collecting the snapshot and then discarding it. | ||
*/ | ||
default MetricSnapshot collect(Predicate<String> includedNames, PrometheusScrapeRequest scrapeRequest) { | ||
MetricSnapshot result = collect(scrapeRequest); | ||
if (includedNames.test(result.getMetadata().getPrometheusName())) { | ||
return result; | ||
} else { | ||
return null; | ||
} | ||
/** | ||
* Provides Collector with the details of the request issued by Prometheus to allow multi-target | ||
* pattern implementation Override to implement request dependent logic to provide MetricSnapshot | ||
*/ | ||
default MetricSnapshot collect(PrometheusScrapeRequest scrapeRequest) { | ||
return collect(); | ||
} | ||
|
||
/** | ||
* Like {@link #collect()}, but returns {@code null} if {@code includedNames.test(name)} is {@code | ||
* false}. | ||
* | ||
* <p>Override this if there is a more efficient way than first collecting the snapshot and then | ||
* discarding it. | ||
*/ | ||
default MetricSnapshot collect(Predicate<String> includedNames) { | ||
MetricSnapshot result = collect(); | ||
if (includedNames.test(result.getMetadata().getPrometheusName())) { | ||
return result; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* This is called in two places: | ||
* <ol> | ||
* <li>During registration to check if a metric with that name already exists.</li> | ||
* <li>During scrape to check if this collector can be skipped because a name filter is present and the metric name is excluded.</li> | ||
* </ol> | ||
* Returning {@code null} means checks are omitted (registration the metric always succeeds), | ||
* and the collector is always scraped (the result is dropped after scraping if a name filter is present and | ||
* the metric name is excluded). | ||
* <p> | ||
* If your metric has a name that does not change at runtime it is a good idea to overwrite this and return the name. | ||
* <p> | ||
* All metrics in {@code prometheus-metrics-core} override this. | ||
*/ | ||
default String getPrometheusName() { | ||
return null; | ||
/** | ||
* Like {@link #collect(Predicate)}, but with support for multi-target pattern. | ||
* | ||
* <p>Override this if there is a more efficient way than first collecting the snapshot and then | ||
* discarding it. | ||
*/ | ||
default MetricSnapshot collect( | ||
Predicate<String> includedNames, PrometheusScrapeRequest scrapeRequest) { | ||
MetricSnapshot result = collect(scrapeRequest); | ||
if (includedNames.test(result.getMetadata().getPrometheusName())) { | ||
return result; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* This is called in two places: | ||
* | ||
* <ol> | ||
* <li>During registration to check if a metric with that name already exists. | ||
* <li>During scrape to check if this collector can be skipped because a name filter is present | ||
* and the metric name is excluded. | ||
* </ol> | ||
* | ||
* Returning {@code null} means checks are omitted (registration the metric always succeeds), and | ||
* the collector is always scraped (the result is dropped after scraping if a name filter is | ||
* present and the metric name is excluded). | ||
* | ||
* <p>If your metric has a name that does not change at runtime it is a good idea to overwrite | ||
* this and return the name. | ||
* | ||
* <p>All metrics in {@code prometheus-metrics-core} override this. | ||
*/ | ||
default String getPrometheusName() { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.