Skip to content

Commit

Permalink
Merge pull request #230 from sladkoff/revert-229-feature/health-checks
Browse files Browse the repository at this point in the history
Revert "feat: health checks"
  • Loading branch information
sladkoff authored Feb 29, 2024
2 parents 4dd4b45 + 416c464 commit 6cdd3c6
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 184 deletions.
28 changes: 0 additions & 28 deletions src/main/java/de/sldk/mc/HealthController.java

This file was deleted.

5 changes: 1 addition & 4 deletions src/main/java/de/sldk/mc/MetricsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ public class MetricsController extends Handler.Abstract {
private final MetricRegistry metricRegistry = MetricRegistry.getInstance();
private final PrometheusExporter exporter;

private MetricsController(PrometheusExporter exporter) {
public MetricsController(PrometheusExporter exporter) {
this.exporter = exporter;
}

public static Handler create(final PrometheusExporter exporter) {
return new MetricsController(exporter);
}

@Override
public boolean handle(Request request, Response response, Callback callback) throws Exception {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/de/sldk/mc/MetricsServer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.sldk.mc;

import org.eclipse.jetty.http.pathmap.PathSpec;
import de.sldk.mc.health.HealthChecks;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.PathMappingsHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
Expand All @@ -13,23 +12,20 @@ public class MetricsServer {
private final String host;
private final int port;
private final PrometheusExporter prometheusExporter;
private final HealthChecks healthChecks;

private Server server;

public MetricsServer(String host, int port, PrometheusExporter prometheusExporter, HealthChecks healthChecks) {
public MetricsServer(String host, int port, PrometheusExporter prometheusExporter) {
this.host = host;
this.port = port;
this.prometheusExporter = prometheusExporter;
this.healthChecks = healthChecks;
}
}

public void start() throws Exception {
GzipHandler gzipHandler = new GzipHandler();

var pathMappings = new PathMappingsHandler();
pathMappings.addMapping(PathSpec.from("/metrics"), MetricsController.create(prometheusExporter));
pathMappings.addMapping(PathSpec.from("/health"), HealthController.create(healthChecks));
pathMappings.addMapping(PathSpec.from("/metrics"), new MetricsController(prometheusExporter));

gzipHandler.setHandler(pathMappings);

Expand Down
33 changes: 0 additions & 33 deletions src/main/java/de/sldk/mc/health/ConcurrentHealthChecks.java

This file was deleted.

64 changes: 0 additions & 64 deletions src/main/java/de/sldk/mc/health/HealthCheck.java

This file was deleted.

21 changes: 0 additions & 21 deletions src/main/java/de/sldk/mc/health/HealthChecks.java

This file was deleted.

14 changes: 3 additions & 11 deletions src/main/kotlin/de/sldk/mc/PrometheusExporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
package de.sldk.mc

import de.sldk.mc.config.PrometheusExporterConfig
import de.sldk.mc.health.ConcurrentHealthChecks
import de.sldk.mc.health.HealthChecks
import org.bukkit.plugin.ServicePriority
import org.bukkit.plugin.java.JavaPlugin
import java.util.logging.Level


class PrometheusExporter : JavaPlugin() {
private val config: PrometheusExporterConfig = PrometheusExporterConfig(this)
private var server: MetricsServer? = null
Expand All @@ -18,18 +14,14 @@ class PrometheusExporter : JavaPlugin() {
override fun onEnable() {
config.loadDefaultsAndSave()
config.enableConfiguredMetrics()

val healthChecks = ConcurrentHealthChecks.create()
getServer().servicesManager.register(HealthChecks::class.java, healthChecks, this, ServicePriority.Normal)

startMetricsServer(healthChecks)
startMetricsServer()
}

private fun startMetricsServer(healthChecks: HealthChecks) {
private fun startMetricsServer() {
val host = config[PrometheusExporterConfig.HOST]
val port = config[PrometheusExporterConfig.PORT]

server = MetricsServer(host, port, this, healthChecks)
server = MetricsServer(host, port, this)

try {
server?.start()
Expand Down
19 changes: 3 additions & 16 deletions src/test/java/de/sldk/mc/exporter/PrometheusExporterTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package de.sldk.mc.exporter;


import static org.assertj.core.api.Assertions.assertThat;

import de.sldk.mc.MetricsServer;
import de.sldk.mc.PrometheusExporter;
import de.sldk.mc.health.ConcurrentHealthChecks;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.exporter.common.TextFormat;
Expand All @@ -20,8 +21,6 @@
import java.io.IOException;
import java.net.ServerSocket;

import static org.assertj.core.api.Assertions.assertThat;

@ExtendWith(MockitoExtension.class)
public class PrometheusExporterTest {

Expand All @@ -35,9 +34,7 @@ public class PrometheusExporterTest {
void setup() throws Exception {
CollectorRegistry.defaultRegistry.clear();
metricsServerPort = getRandomFreePort();
metricsServer = new MetricsServer(
"localhost", metricsServerPort, exporterMock, ConcurrentHealthChecks.create()
);
metricsServer = new MetricsServer("localhost", metricsServerPort, exporterMock);
metricsServer.start();
}

Expand Down Expand Up @@ -86,14 +83,4 @@ void metrics_server_should_return_404_on_unknown_paths() {
.statusCode(HttpStatus.NOT_FOUND_404);
}

@Test
void metrics_server_should_return_200_on_health_check() {
String requestPath = URIUtil.newURI("http", "localhost", metricsServerPort, "/health", null);

RestAssured.when()
.get(requestPath)
.then()
.statusCode(HttpStatus.OK_200);
}

}

0 comments on commit 6cdd3c6

Please sign in to comment.