Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.PrometheusNames;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -34,7 +34,7 @@ protected MetricSnapshots collectMetricSnapshots(PrometheusScrapeRequest scrapeR
gaugeBuilder.name("x_load").help("process load");

CounterSnapshot.Builder counterBuilder = CounterSnapshot.builder();
counterBuilder.name(PrometheusNaming.sanitizeMetricName("x_calls_total")).help("invocations");
counterBuilder.name(PrometheusNames.sanitizeMetricName("x_calls_total")).help("invocations");

String[] targetNames = scrapeRequest.getParameterValues("target");
String targetName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private Builder(PrometheusProperties properties) {
* Prometheus.
*
* <p>Throws an {@link IllegalArgumentException} if {@link
* io.prometheus.metrics.model.snapshots.PrometheusNaming#isValidMetricName(String)
* io.prometheus.metrics.model.snapshots.PrometheusNames#isValidMetricName(String)
* MetricMetadata.isValidMetricName(name)} is {@code false}.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private Builder(PrometheusProperties properties) {
* Prometheus.
*
* <p>Throws an {@link IllegalArgumentException} if {@link
* io.prometheus.metrics.model.snapshots.PrometheusNaming#isValidMetricName(String)
* io.prometheus.metrics.model.snapshots.PrometheusNames#isValidMetricName(String)
* MetricMetadata.isValidMetricName(name)} is {@code false}.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private Builder(PrometheusProperties config) {
* "runtime_info"} in Prometheus.
*
* <p>Throws an {@link IllegalArgumentException} if {@link
* io.prometheus.metrics.model.snapshots.PrometheusNaming#isValidMetricName(String)
* io.prometheus.metrics.model.snapshots.PrometheusNames#isValidMetricName(String)
* MetricMetadata.isValidMetricName(name)} is {@code false}.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.prometheus.metrics.config.PrometheusProperties;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.MetricMetadata;
import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.PrometheusNames;
import io.prometheus.metrics.model.snapshots.Unit;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -61,7 +61,7 @@ protected Builder(List<String> illegalLabelNames, PrometheusProperties propertie
}

public B name(String name) {
String error = PrometheusNaming.validateMetricName(name);
String error = PrometheusNames.validateMetricName(name);
if (error != null) {
throw new IllegalArgumentException("'" + name + "': Illegal metric name: " + error);
}
Expand All @@ -81,7 +81,7 @@ public B help(String help) {

public B labelNames(String... labelNames) {
for (String labelName : labelNames) {
if (!PrometheusNaming.isValidLabelName(labelName)) {
if (!PrometheusNames.isValidLabelName(labelName)) {
throw new IllegalArgumentException(labelName + ": illegal label name");
}
if (illegalLabelNames.contains(labelName)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.prometheus.metrics.core.metrics;

import static io.prometheus.metrics.model.snapshots.PrometheusNaming.prometheusName;
import static io.prometheus.metrics.model.snapshots.PrometheusNames.prometheusName;

import io.prometheus.metrics.config.PrometheusProperties;
import io.prometheus.metrics.core.datapoints.StateSetDataPoint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.prometheus.metrics.exporter.pushgateway;

import static io.prometheus.metrics.exporter.pushgateway.Scheme.HTTP;
import static io.prometheus.metrics.model.snapshots.PrometheusNaming.escapeName;
import static io.prometheus.metrics.model.snapshots.NameEscaper.escapeName;
import static java.util.Objects.requireNonNull;

import io.prometheus.metrics.config.EscapingScheme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.prometheus.metrics.model.snapshots.MetricMetadata;
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.PrometheusNames;
import io.prometheus.metrics.model.snapshots.Quantile;
import io.prometheus.metrics.model.snapshots.SnapshotEscaper;
import io.prometheus.metrics.model.snapshots.StateSetSnapshot;
Expand Down Expand Up @@ -396,7 +396,7 @@ private void writeNameAndLabels(
boolean metricInsideBraces = false;
// If the name does not pass the legacy validity check, we must put the
// metric name inside the braces.
if (!PrometheusNaming.isValidLegacyMetricName(name)) {
if (!PrometheusNames.isValidLegacyMetricName(name)) {
metricInsideBraces = true;
writer.write('{');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.prometheus.metrics.model.snapshots.MetricMetadata;
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.PrometheusNames;
import io.prometheus.metrics.model.snapshots.Quantile;
import io.prometheus.metrics.model.snapshots.StateSetSnapshot;
import io.prometheus.metrics.model.snapshots.SummarySnapshot;
Expand Down Expand Up @@ -396,7 +396,7 @@ private void writeNameAndLabels(
boolean metricInsideBraces = false;
// If the name does not pass the legacy validity check, we must put the
// metric name inside the braces.
if (!PrometheusNaming.isValidLegacyLabelName(name)) {
if (!PrometheusNames.isValidLegacyLabelName(name)) {
metricInsideBraces = true;
writer.write('{');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.prometheus.metrics.config.EscapingScheme;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.PrometheusNames;
import io.prometheus.metrics.model.snapshots.SnapshotEscaper;
import java.io.IOException;
import java.io.Writer;
Expand Down Expand Up @@ -137,13 +137,13 @@ static void writeLabels(
static void writeName(Writer writer, String name, NameType nameType) throws IOException {
switch (nameType) {
case Metric:
if (PrometheusNaming.isValidLegacyMetricName(name)) {
if (PrometheusNames.isValidLegacyMetricName(name)) {
writer.write(name);
return;
}
break;
case Label:
if (PrometheusNaming.isValidLegacyLabelName(name)) {
if (PrometheusNames.isValidLegacyLabelName(name)) {
writer.write(name);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.model.snapshots.NativeHistogramBuckets;
import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.PrometheusNames;
import io.prometheus.metrics.model.snapshots.Quantiles;
import io.prometheus.metrics.model.snapshots.StateSetSnapshot;
import io.prometheus.metrics.model.snapshots.SummarySnapshot;
Expand Down Expand Up @@ -2707,7 +2707,7 @@ public void testUnknownWithDots() throws IOException {
// @formatter:on
UnknownSnapshot unknown =
UnknownSnapshot.builder()
.name(PrometheusNaming.sanitizeMetricName("some.unknown.metric", Unit.BYTES))
.name(PrometheusNames.sanitizeMetricName("some.unknown.metric", Unit.BYTES))
.help("help message")
.unit(Unit.BYTES)
.dataPoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.prometheus.metrics.model.snapshots.MetricMetadata;
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.PrometheusNames;
import io.prometheus.metrics.model.snapshots.Quantiles;
import io.prometheus.metrics.model.snapshots.SummarySnapshot;
import java.util.Collections;
Expand Down Expand Up @@ -101,7 +101,7 @@ private static String getHelpMessage(String metricName, Metric metric) {
private MetricMetadata getMetricMetaData(String metricName, Metric metric) {
String name = labelMapper != null ? labelMapper.getName(metricName) : metricName;
return new MetricMetadata(
PrometheusNaming.sanitizeMetricName(name), getHelpMessage(metricName, metric));
PrometheusNames.sanitizeMetricName(name), getHelpMessage(metricName, metric));
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ MetricSnapshot fromGauge(String dropwizardName, Gauge<?> gauge) {
Level.FINE,
String.format(
"Invalid type for Gauge %s: %s",
PrometheusNaming.sanitizeMetricName(dropwizardName),
PrometheusNames.sanitizeMetricName(dropwizardName),
obj == null ? "null" : obj.getClass().getName()));
return null;
}
Expand Down Expand Up @@ -170,7 +170,7 @@ MetricSnapshot fromSnapshotAndCount(

String name = labelMapper != null ? labelMapper.getName(dropwizardName) : dropwizardName;
MetricMetadata metadata =
new MetricMetadata(PrometheusNaming.sanitizeMetricName(name), helpMessage);
new MetricMetadata(PrometheusNames.sanitizeMetricName(name), helpMessage);
SummarySnapshot.SummaryDataPointSnapshot.Builder dataPointBuilder =
SummarySnapshot.SummaryDataPointSnapshot.builder().quantiles(quantiles).count(count);
if (labelMapper != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.prometheus.metrics.model.snapshots.MetricMetadata;
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.model.snapshots.PrometheusNaming;
import io.prometheus.metrics.model.snapshots.PrometheusNames;
import io.prometheus.metrics.model.snapshots.Quantiles;
import io.prometheus.metrics.model.snapshots.SummarySnapshot;
import java.util.Collections;
Expand Down Expand Up @@ -101,7 +101,7 @@ private static String getHelpMessage(String metricName, Metric metric) {
private MetricMetadata getMetricMetaData(String metricName, Metric metric) {
String name = labelMapper != null ? labelMapper.getName(metricName) : metricName;
return new MetricMetadata(
PrometheusNaming.sanitizeMetricName(name), getHelpMessage(metricName, metric));
PrometheusNames.sanitizeMetricName(name), getHelpMessage(metricName, metric));
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ MetricSnapshot fromGauge(String dropwizardName, Gauge<?> gauge) {
Level.FINE,
String.format(
"Invalid type for Gauge %s: %s",
PrometheusNaming.sanitizeMetricName(dropwizardName),
PrometheusNames.sanitizeMetricName(dropwizardName),
obj == null ? "null" : obj.getClass().getName()));
return null;
}
Expand Down Expand Up @@ -170,7 +170,7 @@ MetricSnapshot fromSnapshotAndCount(

String name = labelMapper != null ? labelMapper.getName(dropwizardName) : dropwizardName;
MetricMetadata metadata =
new MetricMetadata(PrometheusNaming.sanitizeMetricName(name), helpMessage);
new MetricMetadata(PrometheusNames.sanitizeMetricName(name), helpMessage);
SummarySnapshot.SummaryDataPointSnapshot.Builder dataPointBuilder =
SummarySnapshot.SummaryDataPointSnapshot.builder().quantiles(quantiles).count(count);
if (labelMapper != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.prometheus.metrics.model.registry;

import static io.prometheus.metrics.model.snapshots.PrometheusNaming.prometheusName;
import static io.prometheus.metrics.model.snapshots.PrometheusNames.prometheusName;

import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.prometheus.metrics.model.snapshots;

import static io.prometheus.metrics.model.snapshots.PrometheusNaming.isValidLabelName;
import static io.prometheus.metrics.model.snapshots.PrometheusNaming.prometheusName;
import static io.prometheus.metrics.model.snapshots.PrometheusNames.isValidLabelName;
import static io.prometheus.metrics.model.snapshots.PrometheusNames.prometheusName;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -48,8 +48,8 @@ public boolean isEmpty() {
* Labels.of(...)} methods, or you can use the {@link Labels#builder()}.
*
* @param keyValuePairs as in {@code {name1, value1, name2, value2}}. Length must be even. {@link
* PrometheusNaming#isValidLabelName(String)} must be true for each name. Use {@link
* PrometheusNaming#sanitizeLabelName(String)} to convert arbitrary strings to valid label
* PrometheusNames#isValidLabelName(String)} must be true for each name. Use {@link
* PrometheusNames#sanitizeLabelName(String)} to convert arbitrary strings to valid label
* names. Label names must be unique (no duplicate label names).
*/
public static Labels of(String... keyValuePairs) {
Expand All @@ -75,8 +75,8 @@ public static Labels of(String... keyValuePairs) {
* Create a new Labels instance. You can either create Labels with one of the static {@code
* Labels.of(...)} methods, or you can use the {@link Labels#builder()}.
*
* @param names label names. {@link PrometheusNaming#isValidLabelName(String)} must be true for
* each name. Use {@link PrometheusNaming#sanitizeLabelName(String)} to convert arbitrary
* @param names label names. {@link PrometheusNames#isValidLabelName(String)} must be true for
* each name. Use {@link PrometheusNames#sanitizeLabelName(String)} to convert arbitrary
* strings to valid label names. Label names must be unique (no duplicate label names).
* @param values label values. {@code names.size()} must be equal to {@code values.size()}.
*/
Expand All @@ -98,8 +98,8 @@ public static Labels of(List<String> names, List<String> values) {
* Create a new Labels instance. You can either create Labels with one of the static {@code
* Labels.of(...)} methods, or you can use the {@link Labels#builder()}.
*
* @param names label names. {@link PrometheusNaming#isValidLabelName(String)} must be true for
* each name. Use {@link PrometheusNaming#sanitizeLabelName(String)} to convert arbitrary
* @param names label names. {@link PrometheusNames#isValidLabelName(String)} must be true for
* each name. Use {@link PrometheusNames#sanitizeLabelName(String)} to convert arbitrary
* strings to valid label names. Label names must be unique (no duplicate label names).
* @param values label values. {@code names.length} must be equal to {@code values.length}.
*/
Expand All @@ -121,11 +121,11 @@ static String[] makePrometheusNames(String[] names) {
String[] prometheusNames = names;
for (int i = 0; i < names.length; i++) {
String name = names[i];
if (!PrometheusNaming.isValidLegacyLabelName(name)) {
if (!PrometheusNames.isValidLegacyLabelName(name)) {
if (prometheusNames == names) {
prometheusNames = Arrays.copyOf(names, names.length);
}
prometheusNames[i] = PrometheusNaming.prometheusName(name);
prometheusNames[i] = PrometheusNames.prometheusName(name);
}
}
return prometheusNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public MetricMetadata(String name, String help) {
/**
* Constructor.
*
* @param name must not be {@code null}. {@link PrometheusNaming#isValidMetricName(String)
* @param name must not be {@code null}. {@link PrometheusNames#isValidMetricName(String)
* isValidMetricName(name)} must be {@code true}. Use {@link
* PrometheusNaming#sanitizeMetricName(String)} to convert arbitrary strings into valid names.
* PrometheusNames#sanitizeMetricName(String)} to convert arbitrary strings into valid names.
* @param help optional. May be {@code null}.
* @param unit optional. May be {@code null}.
*/
Expand All @@ -56,7 +56,7 @@ public MetricMetadata(String name, @Nullable String help, @Nullable Unit unit) {
this.help = help;
this.unit = unit;
validate();
this.prometheusName = PrometheusNaming.prometheusName(name);
this.prometheusName = PrometheusNames.prometheusName(name);
}

/**
Expand Down Expand Up @@ -97,15 +97,15 @@ private void validate() {
if (name == null) {
throw new IllegalArgumentException("Missing required field: name is null");
}
String error = PrometheusNaming.validateMetricName(name);
String error = PrometheusNames.validateMetricName(name);
if (error != null) {
throw new IllegalArgumentException(
"'"
+ name
+ "': Illegal metric name. "
+ error
+ " Call "
+ PrometheusNaming.class.getSimpleName()
+ PrometheusNames.class.getSimpleName()
+ ".sanitizeMetricName(name) to avoid this error.");
}
if (hasUnit()) {
Expand All @@ -118,13 +118,13 @@ private void validate() {
+ unit
+ "."
+ " Call "
+ PrometheusNaming.class.getSimpleName()
+ PrometheusNames.class.getSimpleName()
+ ".sanitizeMetricName(name, unit) to avoid this error.");
}
}
}

MetricMetadata escape(EscapingScheme escapingScheme) {
return new MetricMetadata(PrometheusNaming.escapeName(name, escapingScheme), help, unit);
return new MetricMetadata(NameEscaper.escapeName(name, escapingScheme), help, unit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract static class Builder<T extends Builder<T>> {

/**
* The name is required. If the name is missing or invalid, {@code build()} will throw an {@link
* IllegalArgumentException}. See {@link PrometheusNaming#isValidMetricName(String)} for info on
* IllegalArgumentException}. See {@link PrometheusNames#isValidMetricName(String)} for info on
* valid metric names.
*/
public T name(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.prometheus.metrics.model.snapshots;

import static io.prometheus.metrics.model.snapshots.PrometheusNaming.prometheusName;
import static io.prometheus.metrics.model.snapshots.PrometheusNames.prometheusName;
import static java.util.Collections.unmodifiableList;
import static java.util.Comparator.comparing;

Expand Down
Loading
Loading