Skip to content

Commit

Permalink
Development: Add admin metrics page tests (#9249)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonEntholzer authored Sep 19, 2024
1 parent bac8af9 commit 64be5de
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h3 id="garbageCollectorMetrics" jhiTranslate="metrics.jvm.gc.title"></h3>
<h3 id="garbageCollectorMetricsTitle" jhiTranslate="metrics.jvm.gc.title"></h3>
<div class="row">
<div class="col-md-4">
@if (garbageCollectorMetrics) {
@if (garbageCollectorMetrics && garbageCollectorMetrics['jvm.gc.live.data.size']) {
<div>
<span>
GC Live Data Size/GC Max Data Size ({{ garbageCollectorMetrics['jvm.gc.live.data.size'] / 1048576 | number: '1.0-0' }}M /
Expand All @@ -19,8 +19,10 @@ <h3 id="garbageCollectorMetrics" jhiTranslate="metrics.jvm.gc.title"></h3>
</div>
}
</div>
<div class="col-md-4">
@if (garbageCollectorMetrics) {
</div>
<div class="row">
@if (garbageCollectorMetrics && garbageCollectorMetrics['jvm.gc.memory.promoted']) {
<div class="col-md-4">
<div>
<span>
GC Memory Promoted/GC Memory Allocated ({{ garbageCollectorMetrics['jvm.gc.memory.promoted'] / 1048576 | number: '1.0-0' }}M /
Expand All @@ -36,8 +38,10 @@ <h3 id="garbageCollectorMetrics" jhiTranslate="metrics.jvm.gc.title"></h3>
<span> {{ (100 * garbageCollectorMetrics['jvm.gc.memory.promoted']) / garbageCollectorMetrics['jvm.gc.memory.allocated'] | number: '1.0-2' }}% </span>
</ngb-progressbar>
</div>
}
</div>
</div>
}
</div>
<div class="row">
<div id="garbageCollectorMetrics" class="col-md-4">
@if (garbageCollectorMetrics) {
<div class="row">
Expand All @@ -50,6 +54,8 @@ <h3 id="garbageCollectorMetrics" jhiTranslate="metrics.jvm.gc.title"></h3>
</div>
}
</div>
</div>
<div class="row">
@if (!updating && garbageCollectorMetrics) {
<div class="table-responsive">
<table class="table table-striped" aria-describedby="garbageCollectorMetrics">
Expand All @@ -67,17 +73,19 @@ <h3 id="garbageCollectorMetrics" jhiTranslate="metrics.jvm.gc.title"></h3>
</tr>
</thead>
<tbody>
<tr>
<td>jvm.gc.pause</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause'].count }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause'].mean | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.0'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.5'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.75'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.95'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.99'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause'].max | number: '1.0-3' }}</td>
</tr>
@if (garbageCollectorMetrics['jvm.gc.pause']) {
<tr>
<td>jvm.gc.pause</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause'].count }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause'].mean | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.0'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.5'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.75'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.95'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause']['0.99'] | number: '1.0-3' }}</td>
<td class="text-right">{{ garbageCollectorMetrics['jvm.gc.pause'].max | number: '1.0-3' }}</td>
</tr>
}
</tbody>
</table>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 64be5de

Please sign in to comment.