From 4f62e4836cee45a0646fe36fb453a53390276b1e Mon Sep 17 00:00:00 2001 From: Sanket Mundra <97032782+sanket-mundra@users.noreply.github.com> Date: Sun, 11 Aug 2024 08:20:00 +0530 Subject: [PATCH] fix: correctly get string label value for each jsonNode types (#204) --- .../metric/BaseDocStoreMetricProviderImpl.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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..f1dd0f62 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,18 @@ public List getCustomMetrics(final CustomMetricConfig customMetr return emptyList(); } } + + private String getStringLabelValue(JsonNode jsonNode) { + switch (jsonNode.getNodeType()) { + case STRING: + return jsonNode.textValue(); + case NUMBER: + return String.valueOf(jsonNode.numberValue()); + case BOOLEAN: + return String.valueOf(jsonNode.booleanValue()); + default: + throw new IllegalArgumentException( + String.format("Unsupported JSON node type: %s", jsonNode.getNodeType())); + } + } }