Skip to content

Commit

Permalink
correctly get string label value for each jsonNode types
Browse files Browse the repository at this point in the history
  • Loading branch information
sanket-mundra committed Aug 10, 2024
1 parent 39ea48e commit 910fc4e
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public List<DocStoreMetric> 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()
Expand All @@ -119,4 +121,17 @@ public List<DocStoreMetric> 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());

Check warning on line 131 in document-store/src/main/java/org/hypertrace/core/documentstore/metric/BaseDocStoreMetricProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

document-store/src/main/java/org/hypertrace/core/documentstore/metric/BaseDocStoreMetricProviderImpl.java#L131

Added line #L131 was not covered by tests
default:
throw new IllegalArgumentException(
String.format("Unsupported JSON node type: %s", jsonNode.getNodeType()));

Check warning on line 134 in document-store/src/main/java/org/hypertrace/core/documentstore/metric/BaseDocStoreMetricProviderImpl.java

View check run for this annotation

Codecov / codecov/patch

document-store/src/main/java/org/hypertrace/core/documentstore/metric/BaseDocStoreMetricProviderImpl.java#L133-L134

Added lines #L133 - L134 were not covered by tests
}
}
}

0 comments on commit 910fc4e

Please sign in to comment.