diff --git a/document-store/src/main/java/org/hypertrace/core/documentstore/metric/BaseDocStoreMetricProviderImpl.java b/document-store/src/main/java/org/hypertrace/core/documentstore/metric/BaseDocStoreMetricProviderImpl.java index 7ac6e2a1..3d74a9d4 100644 --- a/document-store/src/main/java/org/hypertrace/core/documentstore/metric/BaseDocStoreMetricProviderImpl.java +++ b/document-store/src/main/java/org/hypertrace/core/documentstore/metric/BaseDocStoreMetricProviderImpl.java @@ -101,7 +101,9 @@ public List getCustomMetrics(final CustomMetricConfig customMetr jsonNodeMap.entrySet().iterator(), Spliterator.ORDERED), false) .filter(entry -> !VALUE_KEY.equals(entry.getKey())) - .collect(toUnmodifiableMap(Entry::getKey, entry -> entry.getValue().textValue())); + .collect( + toUnmodifiableMap( + Entry::getKey, entry -> getStringLabelValue(entry.getValue()))); final DocStoreMetric metric = DocStoreMetric.builder() @@ -119,4 +121,17 @@ public List getCustomMetrics(final CustomMetricConfig customMetr return emptyList(); } } + + private String getStringLabelValue(JsonNode jsonNode) { + switch (jsonNode.getNodeType()) { + case STRING: + return jsonNode.textValue(); + case NUMBER: + case BOOLEAN: + return String.valueOf(jsonNode.numberValue()); + default: + throw new IllegalArgumentException( + String.format("Unsupported JSON node type: %s", jsonNode.getNodeType())); + } + } }