001package io.prometheus.metrics.config;
002
003import java.util.Map;
004
005/**
006 * Properties starting with io.prometheus.exporter.httpServer
007 */
008public class ExporterHttpServerProperties {
009
010    private static final String PORT = "port";
011    private final Integer port;
012
013    private ExporterHttpServerProperties(Integer port) {
014        this.port = port;
015    }
016
017    public Integer getPort() {
018        return port;
019    }
020
021    /**
022     * Note that this will remove entries from {@code properties}.
023     * This is because we want to know if there are unused properties remaining after all properties have been loaded.
024     */
025    static ExporterHttpServerProperties load(String prefix, Map<Object, Object> properties) throws PrometheusPropertiesException {
026        Integer port = Util.loadInteger(prefix + "." + PORT, properties);
027        Util.assertValue(port, t -> t > 0, "Expecting value > 0", prefix, PORT);
028        return new ExporterHttpServerProperties(port);
029    }
030
031    public static Builder builder() {
032        return new Builder();
033    }
034
035    public static class Builder {
036
037        private Integer port;
038
039        private Builder() {}
040
041        public Builder port(int port) {
042            this.port = port;
043            return this;
044        }
045
046        public ExporterHttpServerProperties build() {
047            return new ExporterHttpServerProperties(port);
048        }
049    }
050}