From 64be5de2793c81f42848f28f8b65bd2f417cc175 Mon Sep 17 00:00:00 2001
From: Simon Entholzer <33342534+SimonEntholzer@users.noreply.github.com>
Date: Thu, 19 Sep 2024 22:26:10 +0200
Subject: [PATCH] Development: Add admin metrics page tests (#9249)
---
.../metrics-garbagecollector.component.html | 42 ++++++++++-------
.../artemis/JhiMetricsIntegrationTest.java | 45 +++++++++++++++++++
2 files changed, 70 insertions(+), 17 deletions(-)
create mode 100644 src/test/java/de/tum/cit/aet/artemis/JhiMetricsIntegrationTest.java
diff --git a/src/main/webapp/app/admin/metrics/blocks/metrics-garbagecollector/metrics-garbagecollector.component.html b/src/main/webapp/app/admin/metrics/blocks/metrics-garbagecollector/metrics-garbagecollector.component.html
index 680ebefc10d8..725183033342 100644
--- a/src/main/webapp/app/admin/metrics/blocks/metrics-garbagecollector/metrics-garbagecollector.component.html
+++ b/src/main/webapp/app/admin/metrics/blocks/metrics-garbagecollector/metrics-garbagecollector.component.html
@@ -1,7 +1,7 @@
-
+
- @if (garbageCollectorMetrics) {
+ @if (garbageCollectorMetrics && garbageCollectorMetrics['jvm.gc.live.data.size']) {
GC Live Data Size/GC Max Data Size ({{ garbageCollectorMetrics['jvm.gc.live.data.size'] / 1048576 | number: '1.0-0' }}M /
@@ -19,8 +19,10 @@
}
-
- @if (garbageCollectorMetrics) {
+
+
+ @if (garbageCollectorMetrics && garbageCollectorMetrics['jvm.gc.memory.promoted']) {
+
GC Memory Promoted/GC Memory Allocated ({{ garbageCollectorMetrics['jvm.gc.memory.promoted'] / 1048576 | number: '1.0-0' }}M /
@@ -36,8 +38,10 @@
{{ (100 * garbageCollectorMetrics['jvm.gc.memory.promoted']) / garbageCollectorMetrics['jvm.gc.memory.allocated'] | number: '1.0-2' }}%
- }
-
+
+ }
+
+
@if (garbageCollectorMetrics) {
@@ -50,6 +54,8 @@
}
+
+
@if (!updating && garbageCollectorMetrics) {
@@ -67,17 +73,19 @@
-
- jvm.gc.pause |
- {{ garbageCollectorMetrics['jvm.gc.pause'].count }} |
- {{ garbageCollectorMetrics['jvm.gc.pause'].mean | number: '1.0-3' }} |
- {{ garbageCollectorMetrics['jvm.gc.pause']['0.0'] | number: '1.0-3' }} |
- {{ garbageCollectorMetrics['jvm.gc.pause']['0.5'] | number: '1.0-3' }} |
- {{ garbageCollectorMetrics['jvm.gc.pause']['0.75'] | number: '1.0-3' }} |
- {{ garbageCollectorMetrics['jvm.gc.pause']['0.95'] | number: '1.0-3' }} |
- {{ garbageCollectorMetrics['jvm.gc.pause']['0.99'] | number: '1.0-3' }} |
- {{ garbageCollectorMetrics['jvm.gc.pause'].max | number: '1.0-3' }} |
-
+ @if (garbageCollectorMetrics['jvm.gc.pause']) {
+
+ jvm.gc.pause |
+ {{ garbageCollectorMetrics['jvm.gc.pause'].count }} |
+ {{ garbageCollectorMetrics['jvm.gc.pause'].mean | number: '1.0-3' }} |
+ {{ garbageCollectorMetrics['jvm.gc.pause']['0.0'] | number: '1.0-3' }} |
+ {{ garbageCollectorMetrics['jvm.gc.pause']['0.5'] | number: '1.0-3' }} |
+ {{ garbageCollectorMetrics['jvm.gc.pause']['0.75'] | number: '1.0-3' }} |
+ {{ garbageCollectorMetrics['jvm.gc.pause']['0.95'] | number: '1.0-3' }} |
+ {{ garbageCollectorMetrics['jvm.gc.pause']['0.99'] | number: '1.0-3' }} |
+ {{ garbageCollectorMetrics['jvm.gc.pause'].max | number: '1.0-3' }} |
+
+ }
diff --git a/src/test/java/de/tum/cit/aet/artemis/JhiMetricsIntegrationTest.java b/src/test/java/de/tum/cit/aet/artemis/JhiMetricsIntegrationTest.java
new file mode 100644
index 000000000000..a5ddcf176a6d
--- /dev/null
+++ b/src/test/java/de/tum/cit/aet/artemis/JhiMetricsIntegrationTest.java
@@ -0,0 +1,45 @@
+package de.tum.cit.aet.artemis;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.security.test.context.support.WithMockUser;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+class JhiMetricsIntegrationTest extends AbstractSpringIntegrationIndependentTest {
+
+ @Autowired
+ private ObjectMapper objectMapper;
+
+ @Test
+ @WithMockUser(username = "admin", roles = "ADMIN")
+ void getMetricsTest() throws Exception {
+ var result = request.get("/management/jhimetrics", HttpStatus.OK, String.class);
+
+ JsonNode rootNode = objectMapper.readTree(result);
+
+ assertThat(rootNode.has("jvm")).isTrue();
+ assertThat(rootNode.path("jvm").has("G1 Old Gen")).isTrue();
+ assertThat(rootNode.path("jvm").path("G1 Old Gen").has("committed")).isTrue();
+ assertThat(rootNode.path("jvm").path("G1 Old Gen").has("max")).isTrue();
+ assertThat(rootNode.path("jvm").path("G1 Old Gen").has("used")).isTrue();
+
+ assertThat(rootNode.has("http.server.requests")).isTrue();
+ assertThat(rootNode.path("http.server.requests").path("all").has("count")).isTrue();
+
+ assertThat(rootNode.has("cache")).isTrue();
+
+ assertThat(rootNode.has("garbageCollector")).isTrue();
+ assertThat(rootNode.path("garbageCollector").has("jvm.gc.max.data.size")).isTrue();
+ assertThat(rootNode.path("garbageCollector").path("jvm.gc.pause").has("max")).isTrue();
+
+ assertThat(rootNode.has("processMetrics")).isTrue();
+ assertThat(rootNode.path("processMetrics").has("process.cpu.usage")).isTrue();
+
+ assertThat(rootNode.has("customMetrics")).isTrue();
+ }
+}