This commit is contained in:
Lee 2024-04-18 16:28:09 +01:00
parent 3ac4bfe2ee
commit 046df7fd1f
18 changed files with 22 additions and 35 deletions

View File

@ -174,7 +174,6 @@
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo.spring3x</artifactId>
<version>4.12.6</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -1,10 +1,8 @@
package xyz.mcutils.backend.config;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
@Configuration
@EnableMongoRepositories(basePackages = "xyz.mcutils.backend.repository.mongo")
public class MongoConfig {
}
public class MongoConfig { }

View File

@ -1,9 +1,6 @@
package xyz.mcutils.backend.repository.mongo;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.service.metric.Metric;
/**
@ -11,4 +8,4 @@ import xyz.mcutils.backend.service.metric.Metric;
*
* @author Braydon
*/
public interface MetricsRepository extends CrudRepository<Metric<?>, String> { }
public interface MetricsRepository extends MongoRepository<Metric<?>, String> { }

View File

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedEndpointStatus;
/**

View File

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedMinecraftServer;
/**

View File

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedPlayer;
import java.util.UUID;

View File

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedPlayerName;
/**

View File

@ -1,8 +1,6 @@
package xyz.mcutils.backend.repository.redis;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import xyz.mcutils.backend.model.cache.CachedPlayerSkinPart;
/**

View File

@ -7,6 +7,7 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.mcutils.backend.common.Timer;
import xyz.mcutils.backend.config.Config;
import xyz.mcutils.backend.repository.mongo.MetricsRepository;
import xyz.mcutils.backend.service.metric.Metric;
import xyz.mcutils.backend.service.metric.metrics.*;
@ -55,6 +56,7 @@ public class MetricService {
collectorEnabled.put(metric, metric.isCollector());
}
if (Config.INSTANCE.isProduction()) {
// Load the metrics from Redis
loadMetrics();
@ -67,6 +69,7 @@ public class MetricService {
writeToInflux();
}, saveInterval, saveInterval);
}
}
/**
* Register a metric.

View File

@ -9,7 +9,6 @@ import lombok.ToString;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import xyz.mcutils.backend.service.MetricService;
@AllArgsConstructor
@Getter @Setter @ToString

View File

@ -1,6 +1,5 @@
package xyz.mcutils.backend.service.metric.metrics;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.IntegerMetric;
import xyz.mcutils.backend.websocket.MetricsWebSocketHandler;

View File

@ -1,6 +1,5 @@
package xyz.mcutils.backend.service.metric.metrics;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.IntegerMetric;
import java.util.ArrayList;

View File

@ -1,6 +1,5 @@
package xyz.mcutils.backend.service.metric.metrics;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.IntegerMetric;
import java.util.ArrayList;

View File

@ -1,7 +1,6 @@
package xyz.mcutils.backend.service.metric.metrics.process;
import com.sun.management.OperatingSystemMXBean;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.DoubleMetric;
import java.lang.management.ManagementFactory;

View File

@ -1,6 +1,5 @@
package xyz.mcutils.backend.service.metric.metrics.process;
import xyz.mcutils.backend.service.MetricService;
import xyz.mcutils.backend.service.metric.impl.MapMetric;
public class MemoryMetric extends MapMetric<String, Long> {

View File

@ -4,8 +4,6 @@ import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.NonNull;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import redis.embedded.RedisServer;
import java.io.IOException;

View File

@ -1,7 +1,10 @@
package xyz.mcutils.backend.test.tests;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
@ -15,6 +18,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest(classes = { TestRedisConfig.class })
@AutoConfigureMockMvc
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class PlayerControllerTests {
private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";

View File

@ -1,7 +1,10 @@
package xyz.mcutils.backend.test.tests;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
@ -14,6 +17,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest(classes = { TestRedisConfig.class })
@AutoConfigureMockMvc
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class ServerControllerTests {
private final String testServer = "play.hypixel.net";