From 1c685ca41411bebdbccd1356f599bcef5e064b21 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 18 Apr 2024 13:31:22 +0100 Subject: [PATCH] switch to mongo for metric storage --- pom.xml | 6 ++++++ .../xyz/mcutils/backend/repository/MetricsRepository.java | 4 ++-- .../java/xyz/mcutils/backend/service/MetricService.java | 2 +- .../java/xyz/mcutils/backend/service/metric/Metric.java | 4 ++-- src/main/resources/application.yml | 4 ++++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index d63c0ed..1079375 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,12 @@ jedis + + + org.springframework.boot + spring-boot-starter-data-mongodb + + org.projectlombok diff --git a/src/main/java/xyz/mcutils/backend/repository/MetricsRepository.java b/src/main/java/xyz/mcutils/backend/repository/MetricsRepository.java index 7f51ae7..1335f3b 100644 --- a/src/main/java/xyz/mcutils/backend/repository/MetricsRepository.java +++ b/src/main/java/xyz/mcutils/backend/repository/MetricsRepository.java @@ -1,6 +1,6 @@ package xyz.mcutils.backend.repository; -import org.springframework.data.repository.CrudRepository; +import org.springframework.data.mongodb.repository.MongoRepository; import xyz.mcutils.backend.service.metric.Metric; /** @@ -8,4 +8,4 @@ import xyz.mcutils.backend.service.metric.Metric; * * @author Braydon */ -public interface MetricsRepository extends CrudRepository, String> { } \ No newline at end of file +public interface MetricsRepository extends MongoRepository, String> { } \ No newline at end of file diff --git a/src/main/java/xyz/mcutils/backend/service/MetricService.java b/src/main/java/xyz/mcutils/backend/service/MetricService.java index 87bfd25..b247436 100644 --- a/src/main/java/xyz/mcutils/backend/service/MetricService.java +++ b/src/main/java/xyz/mcutils/backend/service/MetricService.java @@ -101,7 +101,7 @@ public class MetricService { for (Metric metric : metrics.values()) { saveMetric(metric); } - log.info("Saved {} metrics to Redis", metrics.size()); + log.info("Saved {} metrics to MongoDB", metrics.size()); } /** diff --git a/src/main/java/xyz/mcutils/backend/service/metric/Metric.java b/src/main/java/xyz/mcutils/backend/service/metric/Metric.java index 41b7c06..1b92943 100644 --- a/src/main/java/xyz/mcutils/backend/service/metric/Metric.java +++ b/src/main/java/xyz/mcutils/backend/service/metric/Metric.java @@ -7,12 +7,12 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; import org.springframework.data.annotation.Id; -import org.springframework.data.redis.core.RedisHash; +import org.springframework.data.mongodb.core.mapping.Document; import xyz.mcutils.backend.service.MetricService; @AllArgsConstructor @Getter @Setter @ToString -@RedisHash(value = "metric") +@Document("metrics") public abstract class Metric { /** * The id of the metric. diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 09a8b87..be960a4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,6 +17,10 @@ spring: database: 1 auth: "" # Leave blank for no auth + mongodb: + uri: mongodb://localhost:27017 + database: database + # Disable default metrics management: endpoints: