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