From ee76d172a984f79b6acdc479ffeea867562bb219 Mon Sep 17 00:00:00 2001 From: yasmin-aumeeruddy Date: Tue, 25 Jul 2023 17:09:18 +0100 Subject: [PATCH] Initial metrics update --- frontend/Dockerfile | 3 ++ game-service/build.gradle | 3 +- .../org/libertybikes/game/core/GameRound.java | 3 +- .../libertybikes/game/metric/GameMetrics.java | 40 ++++++++++--------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index de28128..9723011 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,6 +1,9 @@ FROM icr.io/appcafe/open-liberty:kernel-slim-java11-openj9-ubi ADD --chown=1001:0 build/libs/frontend.war /config/apps COPY --chown=1001:0 src/main/liberty/config /config/ +# Install necessary features +RUN features.sh + RUN printf 'httpPort=12000\n\ httpsPort=12005\n\ application.name=frontend.war' > /config/bootstrap.properties diff --git a/game-service/build.gradle b/game-service/build.gradle index 4fb16c8..511b876 100644 --- a/game-service/build.gradle +++ b/game-service/build.gradle @@ -1,5 +1,6 @@ dependencies { - implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' + implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5' + runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' } ext { diff --git a/game-service/src/main/java/org/libertybikes/game/core/GameRound.java b/game-service/src/main/java/org/libertybikes/game/core/GameRound.java index a7b6a43..b6b8e0b 100644 --- a/game-service/src/main/java/org/libertybikes/game/core/GameRound.java +++ b/game-service/src/main/java/org/libertybikes/game/core/GameRound.java @@ -35,7 +35,7 @@ import jakarta.websocket.Session; import org.eclipse.microprofile.metrics.Timer.Context; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.libertybikes.game.core.Player.STATUS; -//import org.libertybikes.game.metric.GameMetrics; +import org.libertybikes.game.metric.GameMetrics; import org.libertybikes.restclient.PlayerService; import io.jsonwebtoken.Claims; @@ -199,6 +199,7 @@ public class GameRound implements Runnable { clients.put(s, c); log("Player " + playerId + " has joined."); + GameMetrics.incPlayerCount(); /* Increment player counter metrics GameMetrics.counterInc(GameMetrics.currentPlayersCounter); GameMetrics.counterInc(GameMetrics.totalPlayersCounter); diff --git a/game-service/src/main/java/org/libertybikes/game/metric/GameMetrics.java b/game-service/src/main/java/org/libertybikes/game/metric/GameMetrics.java index f632e66..13b80d0 100644 --- a/game-service/src/main/java/org/libertybikes/game/metric/GameMetrics.java +++ b/game-service/src/main/java/org/libertybikes/game/metric/GameMetrics.java @@ -5,69 +5,73 @@ package org.libertybikes.game.metric; import jakarta.enterprise.inject.spi.CDI; -import org.eclipse.microprofile.metrics.MetricRegistry; import org.eclipse.microprofile.metrics.MetricUnits; import org.eclipse.microprofile.metrics.Timer.Context; import org.eclipse.microprofile.metrics.annotation.Counted; +import org.eclipse.microprofile.metrics.Metadata; +import org.eclipse.microprofile.metrics.MetadataBuilder; +import org.eclipse.microprofile.metrics.MetricRegistry; +import org.eclipse.microprofile.metrics.annotation.Gauge; public class GameMetrics { // MpMetric Metadatas -/* public static final Metadata totalRoundsCounter = new MetadataBuilder() + private static int totalPlayers = 0; + + @Gauge(unit = MetricUnits.NONE, + name = "playerNumberGauge", + absolute = true, + description = "Number of players in the game") + public static int getPlayerCount() { + return totalPlayers; + } + + public static void incPlayerCount(){ + totalPlayers = totalPlayers + 1; + } + + public static void decPlayerCount(){ + totalPlayers = totalPlayers -1 ; + } + /*public static final Metadata totalRoundsCounter = new MetadataBuilder() .withName("total_num_of_rounds") - .withDisplayName("Total Number of Rounds") .withDescription("Number of rounds that have been created") - .withType(MetricType.COUNTER) .build(); public static final Metadata currentPlayersCounter = new MetadataBuilder() .withName("current_num_of_players") - .withDisplayName("Current Number of Players") .withDescription("Number of players that are currently playing in a round") - .withType(MetricType.CONCURRENT_GAUGE) .build(); public static final Metadata totalPlayersCounter = new MetadataBuilder() .withName("total_num_of_players") - .withDisplayName("Total Number of Players That Have Played") .withDescription("Number of players that have played in a round, requeuing and replaying increases the count") - .withType(MetricType.COUNTER) .build(); public static final Metadata totalMobilePlayersCounter = new MetadataBuilder() .withName("total_num_of_mobile_players") - .withDisplayName("Total Number of Mobile Players That Have Played") .withDescription("Number of mobile players that have played in a round, requeuing and replaying increases the count") - .withType(MetricType.COUNTER) .build(); public static final Metadata gameRoundTimerMetadata = new MetadataBuilder() .withName("game_round_timer") - .withDisplayName("Game Round Timer") .withDescription("The Time Game Rounds Last") - .withType(MetricType.TIMER) .withUnit(MetricUnits.SECONDS) .build(); public static final Metadata currentPartiesCounterMetadata = new MetadataBuilder() .withName("current_number_of_parties") - .withDisplayName("Current Number of Parties") .withDescription("Number of parties currently running") - .withType(MetricType.CONCURRENT_GAUGE) .build(); public static final Metadata currentQueuedPlayersCounter = new MetadataBuilder() .withName("current_num_of_players_in_queue") - .withDisplayName("Current Number of Players Waiting In A Queue") .withDescription("Number of players that are currently waiting in a queue") - .withType(MetricType.CONCURRENT_GAUGE) .build(); public static final Metadata openWebsocketTimerMetadata = new MetadataBuilder() .withName("open_game_websocket_timer") - .withDisplayName("Open Game Round Websocket Timer") .withDescription("The Time Game Round Websockets Are Open") - .withType(MetricType.TIMER) .withUnit(MetricUnits.SECONDS) .build();