Skip to content

Commit

Permalink
feat: 방 총 갯수 metrix 생성 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
waterricecake committed May 21, 2024
1 parent 6ca7ee3 commit e0a6db3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ dependencies {
testImplementation 'io.rest-assured:rest-assured:5.4.0'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
}

tasks.named('test') {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/mafia/mafiatogether/domain/RoomManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public Room findByCode(final String code) {
public boolean validateCode(final String code) {
return !rooms.containsKey(code);
}

public Integer getTotalRoomCount() {
return rooms.size();
}
}
6 changes: 5 additions & 1 deletion src/main/java/mafia/mafiatogether/service/RoomService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mafia.mafiatogether.service;

import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import java.time.Clock;
import lombok.RequiredArgsConstructor;
import mafia.mafiatogether.config.exception.ExceptionCode;
Expand All @@ -22,9 +24,11 @@
public class RoomService {

private final RoomManager roomManager;
private final MeterRegistry meterRegistry;

public RoomCodeResponse create(final RoomCreateRequest request) {
final String code = roomManager.create(request.toDomain());
Gauge.builder("room", roomManager, RoomManager::getTotalRoomCount).tag("info", "size").register(meterRegistry);
return new RoomCodeResponse(code);
}

Expand Down Expand Up @@ -57,7 +61,7 @@ public RoomValidateResponse validateCode(final String code) {

public RoomResultResponse findResult(final String code) {
final Room room = roomManager.findByCode(code);
if(!room.isEnd()){
if (!room.isEnd()) {
throw new RoomException(ExceptionCode.GAME_IS_NOT_FINISHED);
}
return RoomResultResponse.of((EndStatus) room.getStatus());
Expand Down

0 comments on commit e0a6db3

Please sign in to comment.