001package io.prometheus.metrics.config; 002 003import javax.annotation.Nullable; 004 005/** 006 * Properties starting with io.prometheus.openmetrics2. These properties are experimental and 007 * subject to change. 008 */ 009public class OpenMetrics2Properties { 010 011 private static final String PREFIX = "io.prometheus.openmetrics2"; 012 private static final String CONTENT_NEGOTIATION = "content_negotiation"; 013 private static final String COMPOSITE_VALUES = "composite_values"; 014 private static final String EXEMPLAR_COMPLIANCE = "exemplar_compliance"; 015 private static final String NATIVE_HISTOGRAMS = "native_histograms"; 016 017 @Nullable private final Boolean contentNegotiation; 018 @Nullable private final Boolean compositeValues; 019 @Nullable private final Boolean exemplarCompliance; 020 @Nullable private final Boolean nativeHistograms; 021 022 private OpenMetrics2Properties( 023 @Nullable Boolean contentNegotiation, 024 @Nullable Boolean compositeValues, 025 @Nullable Boolean exemplarCompliance, 026 @Nullable Boolean nativeHistograms) { 027 this.contentNegotiation = contentNegotiation; 028 this.compositeValues = compositeValues; 029 this.exemplarCompliance = exemplarCompliance; 030 this.nativeHistograms = nativeHistograms; 031 } 032 033 /** Gate OM2 features behind content negotiation. Default is {@code false}. */ 034 public boolean getContentNegotiation() { 035 return contentNegotiation != null && contentNegotiation; 036 } 037 038 /** Single-line histogram/summary with {@code st@}. Default is {@code false}. */ 039 public boolean getCompositeValues() { 040 return compositeValues != null && compositeValues; 041 } 042 043 /** Mandatory timestamps, no 128-char limit for exemplars. Default is {@code false}. */ 044 public boolean getExemplarCompliance() { 045 return exemplarCompliance != null && exemplarCompliance; 046 } 047 048 /** Exponential buckets support for native histograms. Default is {@code false}. */ 049 public boolean getNativeHistograms() { 050 return nativeHistograms != null && nativeHistograms; 051 } 052 053 /** 054 * Note that this will remove entries from {@code propertySource}. This is because we want to know 055 * if there are unused properties remaining after all properties have been loaded. 056 */ 057 static OpenMetrics2Properties load(PropertySource propertySource) 058 throws PrometheusPropertiesException { 059 Boolean contentNegotiation = Util.loadBoolean(PREFIX, CONTENT_NEGOTIATION, propertySource); 060 Boolean compositeValues = Util.loadBoolean(PREFIX, COMPOSITE_VALUES, propertySource); 061 Boolean exemplarCompliance = Util.loadBoolean(PREFIX, EXEMPLAR_COMPLIANCE, propertySource); 062 Boolean nativeHistograms = Util.loadBoolean(PREFIX, NATIVE_HISTOGRAMS, propertySource); 063 return new OpenMetrics2Properties( 064 contentNegotiation, compositeValues, exemplarCompliance, nativeHistograms); 065 } 066 067 public static Builder builder() { 068 return new Builder(); 069 } 070 071 public static class Builder { 072 073 @Nullable private Boolean contentNegotiation; 074 @Nullable private Boolean compositeValues; 075 @Nullable private Boolean exemplarCompliance; 076 @Nullable private Boolean nativeHistograms; 077 078 private Builder() {} 079 080 /** See {@link #getContentNegotiation()} */ 081 public Builder contentNegotiation(boolean contentNegotiation) { 082 this.contentNegotiation = contentNegotiation; 083 return this; 084 } 085 086 /** See {@link #getCompositeValues()} */ 087 public Builder compositeValues(boolean compositeValues) { 088 this.compositeValues = compositeValues; 089 return this; 090 } 091 092 /** See {@link #getExemplarCompliance()} */ 093 public Builder exemplarCompliance(boolean exemplarCompliance) { 094 this.exemplarCompliance = exemplarCompliance; 095 return this; 096 } 097 098 /** See {@link #getNativeHistograms()} */ 099 public Builder nativeHistograms(boolean nativeHistograms) { 100 this.nativeHistograms = nativeHistograms; 101 return this; 102 } 103 104 /** Enable all OpenMetrics 2.0 features */ 105 public Builder enableAll() { 106 this.contentNegotiation = true; 107 this.compositeValues = true; 108 this.exemplarCompliance = true; 109 this.nativeHistograms = true; 110 return this; 111 } 112 113 public OpenMetrics2Properties build() { 114 return new OpenMetrics2Properties( 115 contentNegotiation, compositeValues, exemplarCompliance, nativeHistograms); 116 } 117 } 118}