Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Add admin metrics page tests #9249

Merged
merged 31 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8a8882a
ignore missing metric values
SimonEntholzer Aug 26, 2024
ad511e0
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Aug 30, 2024
e9ecfea
added jhimetrics endpoint test
SimonEntholzer Aug 31, 2024
58c4125
added jhimetrics endpoint test
SimonEntholzer Aug 31, 2024
7ccedf3
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Aug 31, 2024
8dd6297
rollback debugging console logs
SimonEntholzer Aug 31, 2024
5e5db85
rollback debugging console logs
SimonEntholzer Aug 31, 2024
ee10d35
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 1, 2024
d967089
Update src/main/webapp/app/admin/metrics/metrics.component.ts
SimonEntholzer Sep 1, 2024
fb1b6e1
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 1, 2024
51b71da
make test system independent
SimonEntholzer Sep 1, 2024
3a7b093
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 2, 2024
213a9a4
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 3, 2024
7789990
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 5, 2024
806cdc1
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 5, 2024
835aaad
remove public from test
SimonEntholzer Sep 5, 2024
dc3e6ba
removed awkward length check
SimonEntholzer Sep 6, 2024
4cf5c54
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 6, 2024
c351566
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 7, 2024
b338aac
remove empty line
SimonEntholzer Sep 7, 2024
bcdf06f
remove public from test
SimonEntholzer Sep 8, 2024
53e26e4
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 10, 2024
94b07b5
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 12, 2024
c53f737
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 13, 2024
850ccb5
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 13, 2024
0fe17e0
moved file into correct directory
SimonEntholzer Sep 14, 2024
b46a0c5
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 14, 2024
e531a7a
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 15, 2024
1b073f8
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 17, 2024
a77b9c9
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 18, 2024
3af61fc
Merge branch 'develop' into chore/bugfix/fix-metrics-page
SimonEntholzer Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h4 jhiTranslate="metrics.jvm.memory.title"></h4>
@if (!updating && jvmMemoryMetrics) {
@if (!updating && jvmMemoryMetrics && Object.keys(this.jvmMemoryMetrics!).length > 0) {
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
<div>
@for (entry of jvmMemoryMetrics | keyvalue; track entry) {
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export class JvmMemoryComponent {
* boolean field saying if the metrics are in the process of being updated
*/
@Input() updating?: boolean;

protected readonly Object = Object;
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
}
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
2 changes: 2 additions & 0 deletions src/main/webapp/app/admin/metrics/metrics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ export class MetricsComponent implements OnInit {
metricsKeyExistsAndObjectNotEmpty(key: keyof Metrics): boolean {
return Boolean(this.metrics?.[key] && JSON.stringify(this.metrics[key]) !== '{}');
}

SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
protected readonly console = console;
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
}
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.tum.in.www1.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;

public class JhiMetricsIntegrationTest extends AbstractSpringIntegrationIndependentTest {

@Autowired
private ObjectMapper objectMapper;

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public 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.path("cache").path("features").path("cache.size").asDouble()).isEqualTo(8.0);

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();
PaRangger marked this conversation as resolved.
Show resolved Hide resolved

assertThat(rootNode.has("processMetrics")).isTrue();
assertThat(rootNode.path("processMetrics").path("system.cpu.count").asInt()).isEqualTo(16);

Check failure on line 42 in src/test/java/de/tum/in/www1/artemis/JhiMetricsIntegrationTest.java

View workflow job for this annotation

GitHub Actions / H2 Tests

de.tum.in.www1.artemis.JhiMetricsIntegrationTest ► getMetricsTest()

Failed test found in: build/test-results/test/TEST-de.tum.in.www1.artemis.JhiMetricsIntegrationTest.xml Error: org.opentest4j.AssertionFailedError:
Raw output
org.opentest4j.AssertionFailedError: 
expected: 16
 but was: 4
	at app//de.tum.in.www1.artemis.JhiMetricsIntegrationTest.getMetricsTest(JhiMetricsIntegrationTest.java:42)
	at java.base@21.0.4/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base@21.0.4/java.lang.reflect.Method.invoke(Method.java:580)
	at app//org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:728)
	at app//org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at app//org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at app//org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at app//org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at app//org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at app//org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at app//org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at app//org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:218)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:214)
	at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:139)
	at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at app//org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:202)
	at app//org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService.invokeAll(ForkJoinPoolHierarchicalTestExecutorService.java:146)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at app//org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:202)
	at java.base@21.0.4/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
	at java.base@21.0.4/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base@21.0.4/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base@21.0.4/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base@21.0.4/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base@21.0.4/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
assertThat(rootNode.path("processMetrics").has("process.cpu.usage")).isTrue();

assertThat(rootNode.has("customMetrics")).isTrue();
assertThat(rootNode.path("customMetrics").path("activeUsers").asInt()).isEqualTo(0);
}
}
Loading