All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.prometheus.client.dropwizard.samplebuilder.DefaultSampleBuilder Maven / Gradle / Ivy

The newest version!
package io.prometheus.client.dropwizard.samplebuilder;

import io.prometheus.client.Collector;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


/**
 * Default implementation of {@link SampleBuilder}.
 * Sanitises the metric name if necessary.
 *
 * @see io.prometheus.client.Collector#sanitizeMetricName(String)
 */
public class DefaultSampleBuilder implements SampleBuilder {
    @Override
    public Collector.MetricFamilySamples.Sample createSample(final String dropwizardName, final String nameSuffix, final List additionalLabelNames, final List additionalLabelValues, final double value) {
        final String suffix = nameSuffix == null ? "" : nameSuffix;
        final List labelNames = additionalLabelNames == null ? Collections.emptyList() : additionalLabelNames;
        final List labelValues = additionalLabelValues == null ? Collections.emptyList() : additionalLabelValues;
        return new Collector.MetricFamilySamples.Sample(
                Collector.sanitizeMetricName(dropwizardName + suffix),
                new ArrayList(labelNames),
                new ArrayList(labelValues),
                value
        );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy