forked from prebid/prebid-server-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Support prometheus namespace and subsystem prefixes (prebid#1802)
- Loading branch information
Showing
13 changed files
with
529 additions
and
332 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
src/main/java/org/prebid/server/metric/prometheus/NamespaceSubsystemSampleBuilder.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,47 @@ | ||
package org.prebid.server.metric.prometheus; | ||
|
||
import io.prometheus.client.Collector; | ||
import io.prometheus.client.dropwizard.samplebuilder.SampleBuilder; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.regex.Pattern; | ||
|
||
public class NamespaceSubsystemSampleBuilder implements SampleBuilder { | ||
|
||
private static final String VALID_PREFIX_REGEX = "[a-zA-Z_:]?[a-zA-Z0-9_:]*"; | ||
|
||
private final SampleBuilder delegate; | ||
private final String prefix; | ||
|
||
public NamespaceSubsystemSampleBuilder(SampleBuilder sampleBuilder, String namespace, String subsystem) { | ||
delegate = Objects.requireNonNull(sampleBuilder); | ||
prefix = toPrefix(namespace) + toPrefix(subsystem); | ||
|
||
final Pattern prefixPattern = Pattern.compile(VALID_PREFIX_REGEX); | ||
if (!prefixPattern.matcher(prefix).matches()) { | ||
throw new IllegalArgumentException(String.format( | ||
"Invalid prefix: %s, namespace and subsystem should match regex: %s", prefix, VALID_PREFIX_REGEX)); | ||
} | ||
} | ||
|
||
@Override | ||
public Collector.MetricFamilySamples.Sample createSample(String dropwizardName, | ||
String nameSuffix, | ||
List<String> additionalLabelNames, | ||
List<String> additionalLabelValues, | ||
double value) { | ||
|
||
return delegate.createSample( | ||
prefix + dropwizardName, | ||
nameSuffix, | ||
additionalLabelNames, | ||
additionalLabelValues, | ||
value); | ||
} | ||
|
||
private static String toPrefix(String value) { | ||
return StringUtils.isNotEmpty(value) ? value + "_" : ""; | ||
} | ||
} |
271 changes: 0 additions & 271 deletions
271
src/main/java/org/prebid/server/spring/config/PrometheusMapperConfiguration.java
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
Oops, something went wrong.