Gitlab Community Edition Instance

Commit d3f0d3e9 authored by mhellka's avatar mhellka
Browse files

Added (undocumented) /v3/_gc endpoint.

Triggering full GCs should not be required. Only for testing.
parent 1a9f15e7
Pipeline #115891 passed with stages
in 10 minutes and 3 seconds
......@@ -14,6 +14,7 @@ public class ApiV3Module implements RestBlueprint {
cfg.install(new ServiceEndpoint());
cfg.install(new ServiceHealthEndpoint());
cfg.install(new ServiceMetricsEndpoint());
cfg.install(new ServiceGCEndpoint());
cfg.install(new TransactionEndpoint());
cfg.install(new VaultEndpoint());
cfg.install(new ArchiveEndpoint());
......
package de.gwdg.cdstar.rest.v3;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import de.gwdg.cdstar.rest.api.RestBlueprint;
import de.gwdg.cdstar.rest.api.RestConfig;
import de.gwdg.cdstar.rest.api.RestContext;
import de.gwdg.cdstar.rest.utils.SessionHelper;
import de.gwdg.cdstar.runtime.client.auth.ServicePermission;
/**
* Undocumented API to trigger a full GC run.
*/
public class ServiceGCEndpoint implements RestBlueprint {
@Override
public void configure(RestConfig cfg) {
cfg.route("/_gc").POST(this::handlePostGC);
}
public GCResult handlePostGC(RestContext ctx) throws IOException {
SessionHelper.ensurePermitted(ctx, ServicePermission.HEALTH.asStringPermission());
return new GCResult(ManagementFactory.getMemoryMXBean());
}
public class GCResult {
public final MemoryUsage before;
public final MemoryUsage after;
public final double time;
public GCResult(MemoryMXBean mem) {
before = mem.getHeapMemoryUsage();
final long t1 = System.nanoTime();
System.gc();
time = ((double) (System.nanoTime() - t1)) / 1000000000;
after = mem.getHeapMemoryUsage();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment