1616
1717package io .prometheus .jmx ;
1818
19+ import io .prometheus .metrics .model .snapshots .Labels ;
1920import io .prometheus .metrics .model .snapshots .PrometheusNaming ;
2021import java .util .List ;
2122import java .util .Objects ;
@@ -31,8 +32,7 @@ public class MatchedRule {
3132 final String matchName ;
3233 final String type ;
3334 final String help ;
34- final List <String > labelNames ;
35- final List <String > labelValues ;
35+ final Labels labels ;
3636 final Double value ;
3737 final double valueFactor ;
3838
@@ -43,8 +43,7 @@ private MatchedRule() {
4343 this .matchName = null ;
4444 this .type = null ;
4545 this .help = null ;
46- this .labelNames = null ;
47- this .labelValues = null ;
46+ this .labels = null ;
4847 this .value = null ;
4948 this .valueFactor = 1.0 ;
5049 }
@@ -70,12 +69,39 @@ public MatchedRule(
7069 final List <String > labelValues ,
7170 final Double value ,
7271 double valueFactor ) {
72+ this .name = PrometheusNaming .sanitizeMetricName (name );
73+ this .matchName = matchName ;
74+ this .type = type ;
75+ this .help = help ;
76+ this .labels = Labels .of (labelNames , labelValues );
77+ this .value = value ;
78+ this .valueFactor = valueFactor ;
79+ }
80+
81+ /**
82+ * Constructor
83+ *
84+ * @param name name - has to be already sanitized (we ensure this by keeping the constructor private)
85+ * @param matchName matchName
86+ * @param type type
87+ * @param help help
88+ * @param labels labels
89+ * @param value value
90+ * @param valueFactor valueFactor
91+ */
92+ private MatchedRule (
93+ final String name ,
94+ final String matchName ,
95+ final String type ,
96+ final String help ,
97+ final Labels labels ,
98+ final Double value ,
99+ double valueFactor ) {
73100 this .name = name ;
74101 this .matchName = matchName ;
75102 this .type = type ;
76103 this .help = help ;
77- this .labelNames = labelNames ;
78- this .labelValues = labelValues ;
104+ this .labels = labels ;
79105 this .value = value ;
80106 this .valueFactor = valueFactor ;
81107 }
@@ -88,12 +114,11 @@ public MatchedRule(
88114 */
89115 public MatchedRule withValue (double value ) {
90116 return new MatchedRule (
91- PrometheusNaming . sanitizeMetricName ( this .name ) ,
117+ this .name ,
92118 this .matchName ,
93119 this .type ,
94120 this .help ,
95- this .labelNames ,
96- this .labelValues ,
121+ this .labels ,
97122 value ,
98123 this .valueFactor );
99124 }
@@ -142,10 +167,8 @@ public String toString() {
142167 + ", help='"
143168 + help
144169 + '\''
145- + ", labelNames="
146- + labelNames
147- + ", labelValues="
148- + labelValues
170+ + ", labels="
171+ + labels
149172 + ", value="
150173 + value
151174 + ", valueFactor="
@@ -163,14 +186,13 @@ public boolean equals(Object o) {
163186 && Objects .equals (matchName , that .matchName )
164187 && Objects .equals (type , that .type )
165188 && Objects .equals (help , that .help )
166- && Objects .equals (labelNames , that .labelNames )
167- && Objects .equals (labelValues , that .labelValues )
189+ && Objects .equals (labels , that .labels )
168190 && Objects .equals (value , that .value );
169191 }
170192
171193 @ Override
172194 public int hashCode () {
173195 return Objects .hash (
174- name , matchName , type , help , labelNames , labelValues , value , valueFactor );
196+ name , matchName , type , help , labels , value , valueFactor );
175197 }
176198}
0 commit comments