From 8d45ba8cbdb941de259cc7075b157391f08c7913 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 14 Apr 2024 09:42:39 +0100 Subject: [PATCH] fix map metric --- .../mcutils/backend/service/MetricService.java | 2 ++ .../backend/service/metric/impl/MapMetric.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/mcutils/backend/service/MetricService.java b/src/main/java/xyz/mcutils/backend/service/MetricService.java index 3c8b231..07a7fe0 100644 --- a/src/main/java/xyz/mcutils/backend/service/MetricService.java +++ b/src/main/java/xyz/mcutils/backend/service/MetricService.java @@ -44,6 +44,8 @@ public class MetricService { registerMetric(new TotalRequestsMetric()); registerMetric(new RequestsPerRouteMetric()); + // todo: don't bother saving and loading metrics when running tests + // Load the metrics from Redis loadMetrics(); diff --git a/src/main/java/xyz/mcutils/backend/service/metric/impl/MapMetric.java b/src/main/java/xyz/mcutils/backend/service/metric/impl/MapMetric.java index 1f52a8a..dcd808c 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/impl/MapMetric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/impl/MapMetric.java @@ -16,7 +16,23 @@ public class MapMetric extends Metric> { public Point toPoint() { Point point = Point.measurement(getId()); for (Map.Entry entry : getValue().entrySet()) { - point.addField(entry.getKey().toString(), entry.getValue().toString()); + switch (entry.getValue().getClass().getSimpleName()) { + case "Integer": + point.addField(entry.getKey().toString(), (Integer) entry.getValue()); + break; + case "Double": + point.addField(entry.getKey().toString(), (Double) entry.getValue()); + break; + case "String": + point.addField(entry.getKey().toString(), (String) entry.getValue()); + break; + case "Boolean": + point.addField(entry.getKey().toString(), (Boolean) entry.getValue()); + break; + default: + point.addField(entry.getKey().toString(), entry.getValue().toString()); + break; + } } return point; }