Skip to content

Commit 8e73f10

Browse files
committed
cleanup
1 parent e5ff7c5 commit 8e73f10

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/MetricStructure.java

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,6 @@ public void setUnit(String unit) {
6666
this.unit = validateUnit(unit.trim());
6767
}
6868

69-
void setStateMapping(Map<String, Object> stateMapping) {
70-
StateMapping.Builder builder = StateMapping.builder();
71-
for (Map.Entry<String, Object> entry : stateMapping.entrySet()) {
72-
String stateKey = entry.getKey();
73-
Object stateValue = entry.getValue();
74-
if (stateValue instanceof String) {
75-
addMappedValue(builder, (String) stateValue, stateKey);
76-
} else if (stateValue instanceof List) {
77-
for (Object listEntry : (List<?>) stateValue) {
78-
if (!(listEntry instanceof String)) {
79-
throw new IllegalArgumentException("unexpected state list value: " + stateKey);
80-
}
81-
addMappedValue(builder, (String) listEntry, stateKey);
82-
}
83-
} else {
84-
throw new IllegalArgumentException("unexpected state value: " + stateValue);
85-
}
86-
}
87-
this.stateMapping = builder.build();
88-
}
89-
9069
private static void addMappedValue(
9170
StateMapping.Builder builder, String stateValue, String stateKey) {
9271
if (stateValue.equals(STATE_MAPPING_WILDCARD)) {
@@ -147,6 +126,7 @@ private List<MetricAttribute> addMetricAttributes(Map<String, Object> metricAttr
147126
if (value instanceof String) {
148127
attribute = buildMetricAttribute(key, ((String) value).trim());
149128
} else if (value instanceof Map) {
129+
// here we use the structure to detect a state metric attribute and parse it.
150130
attribute = buildStateMetricAttribute(key, (Map<?, ?>) value);
151131
} else {
152132
throw new IllegalArgumentException("unexpected metric attribute: " + value);
@@ -194,7 +174,7 @@ private MetricAttribute buildStateMetricAttribute(String key, Map<?, ?> stateMap
194174
throw new IllegalArgumentException("state map is empty for key " + key);
195175
}
196176
if (!stateMapping.isEmpty()) {
197-
throw new IllegalStateException("state map already set for " + key);
177+
throw new IllegalStateException("only a single state map is expected");
198178
}
199179

200180
StateMapping.Builder builder = StateMapping.builder();

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/RuleParser.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,11 @@ private static void parseMetricStructure(
133133
if (type != null) {
134134
out.setType(type);
135135
}
136-
137-
Map<String, Object> stateMapping =
138-
(Map<String, Object>) metricStructureYaml.remove("stateMapping");
139-
if (stateMapping != null) {
140-
out.setStateMapping(stateMapping);
136+
Map<String, Object> metricAttribute =
137+
(Map<String, Object>) metricStructureYaml.remove("metricAttribute");
138+
if (metricAttribute != null) {
139+
out.setMetricAttribute(metricAttribute);
141140
}
142-
143141
String unit = (String) metricStructureYaml.remove("unit");
144142
if (unit != null) {
145143
out.setUnit(unit);

0 commit comments

Comments
 (0)