001package io.prometheus.metrics.config;
002
003import java.util.Map;
004
005/**
006 * Properties starting with io.prometheus.exporter
007 */
008public class ExporterProperties {
009
010    private static final String INCLUDE_CREATED_TIMESTAMPS = "includeCreatedTimestamps";
011    private static final String EXEMPLARS_ON_ALL_METRIC_TYPES = "exemplarsOnAllMetricTypes";
012
013    private final Boolean includeCreatedTimestamps;
014    private final Boolean exemplarsOnAllMetricTypes;
015
016    private ExporterProperties(Boolean includeCreatedTimestamps, Boolean exemplarsOnAllMetricTypes) {
017        this.includeCreatedTimestamps = includeCreatedTimestamps;
018        this.exemplarsOnAllMetricTypes = exemplarsOnAllMetricTypes;
019    }
020
021    /**
022     * Include the {@code _created} timestamps in text format? Default is {@code false}.
023     */
024    public boolean getIncludeCreatedTimestamps() {
025        return includeCreatedTimestamps != null && includeCreatedTimestamps;
026    }
027
028    /**
029     * Allow Exemplars on all metric types in OpenMetrics format?
030     * Default is {@code false}, which means Exemplars will only be added for Counters and Histograms.
031     */
032    public boolean getExemplarsOnAllMetricTypes() {
033        return exemplarsOnAllMetricTypes != null && exemplarsOnAllMetricTypes;
034    }
035
036    /**
037     * Note that this will remove entries from {@code properties}.
038     * This is because we want to know if there are unused properties remaining after all properties have been loaded.
039     */
040    static ExporterProperties load(String prefix, Map<Object, Object> properties) throws PrometheusPropertiesException {
041        Boolean includeCreatedTimestamps = Util.loadBoolean(prefix + "." + INCLUDE_CREATED_TIMESTAMPS, properties);
042        Boolean exemplarsOnAllMetricTypes = Util.loadBoolean(prefix + "." + EXEMPLARS_ON_ALL_METRIC_TYPES, properties);
043        return new ExporterProperties(includeCreatedTimestamps, exemplarsOnAllMetricTypes);
044    }
045
046    public static Builder newBuilder() {
047        return new Builder();
048    }
049
050    public static class Builder {
051
052        private Boolean includeCreatedTimestamps;
053        private Boolean exemplarsOnAllMetricTypes;
054
055        private Builder() {
056        }
057
058        /**
059         * See {@link #getIncludeCreatedTimestamps()}
060         */
061        public Builder withIncludeCreatedTimestamps(boolean includeCreatedTimestamps) {
062            this.includeCreatedTimestamps = includeCreatedTimestamps;
063            return this;
064        }
065
066        /**
067         * See {@link #getExemplarsOnAllMetricTypes()}.
068         */
069        public Builder withExemplarsOnAllMetricTypes(boolean exemplarsOnAllMetricTypes) {
070            this.exemplarsOnAllMetricTypes = exemplarsOnAllMetricTypes;
071            return this;
072        }
073
074        public ExporterProperties build() {
075            return new ExporterProperties(includeCreatedTimestamps, exemplarsOnAllMetricTypes);
076        }
077    }
078}