Skip to content

Commit

Permalink
Add a new admin HTTP API debug/method-calls to support debugging an…
Browse files Browse the repository at this point in the history
…y method quickly and conveniently
  • Loading branch information
JamesChenX committed Jun 10, 2024
1 parent 317f321 commit 897d638
Show file tree
Hide file tree
Showing 16 changed files with 760 additions and 2 deletions.
3 changes: 3 additions & 0 deletions turms-ai-serving/src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ turms:
console:
enabled: true
ai-serving:
admin-api:
debug:
enabled: true
mongo:
admin:
uri: mongodb://localhost:27017/turms-dev
14 changes: 14 additions & 0 deletions turms-ai-serving/src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
spring:
netty:
leak-detection: paranoid

############################### Turms ###############################

turms:
ai-serving:
admin-api:
debug:
enabled: true
logging:
console:
enabled: true
7 changes: 5 additions & 2 deletions turms-gateway/src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ turms:
mongo:
uri: mongodb://localhost:27017/turms-config-dev
gateway:
admin-api:
debug:
enabled: true
client-api:
logging:
heartbeat-sample-rate: 1
included-notification-categories:
- category: all
return-reason-for-server-error: true
fake:
enabled: true
mongo:
admin:
uri: mongodb://localhost:27017/turms-dev
user:
uri: mongodb://localhost:27017/turms-dev
fake:
enabled: true
logging:
console:
enabled: true
Expand Down
4 changes: 4 additions & 0 deletions turms-gateway/src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ spring:
############################### Turms ###############################

turms:
gateway:
admin-api:
debug:
enabled: true
logging:
console:
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public enum ResponseStatusCode {
IP_BLOCKLIST_IS_DISABLED(1400, "Blocking an IP is disabled", 403),
USER_ID_BLOCKLIST_IS_DISABLED(1401, "Blocking a user ID is disabled", 403),

// Admin - Debug
DEBUG_IS_DISABLED(1500, "Debug is disabled", 403),

// Admin - Cluster - Leader
NONEXISTENT_MEMBER_TO_BE_LEADER(1800, "Could not find the node", 404),
NO_QUALIFIED_MEMBER_TO_BE_LEADER(1801, "No qualified node to be a leader", 503),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2019 The Turms Project
* https://github.com/turms-im/turms
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package im.turms.server.common.domain.debug.access.admin.controller;

import reactor.core.publisher.Mono;

import im.turms.server.common.access.admin.dto.response.HttpHandlerResult;
import im.turms.server.common.access.admin.dto.response.ResponseDTO;
import im.turms.server.common.access.admin.web.annotation.PostMapping;
import im.turms.server.common.access.admin.web.annotation.RequestBody;
import im.turms.server.common.access.admin.web.annotation.RestController;
import im.turms.server.common.domain.debug.access.admin.dto.request.CreateMethodCallDTO;
import im.turms.server.common.domain.debug.access.admin.service.DebugService;

/**
* @author James Chen
*/
@RestController("debug")
public class DebugController {

private final DebugService debugService;

public DebugController(DebugService debugService) {
this.debugService = debugService;
}

@PostMapping("method-calls")
public Mono<HttpHandlerResult<ResponseDTO<Object>>> callMethod(
@RequestBody CreateMethodCallDTO request) {
Mono<Object> returnValue = debugService.callMethod(request.beanName(),
request.className(),
request.methodName(),
request.params());
return HttpHandlerResult.okIfTruthy(returnValue);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2019 The Turms Project
* https://github.com/turms-im/turms
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package im.turms.server.common.domain.debug.access.admin.dto.request;

import java.util.List;

import im.turms.server.common.domain.common.access.dto.ControllerDTO;

/**
* @author James Chen
*/
public record CreateMethodCallDTO(
String beanName,
String className,
String methodName,
List<ParamDTO> params
) implements ControllerDTO {

public record ParamDTO(
String name,
Object value
) {
}

}
Loading

0 comments on commit 897d638

Please sign in to comment.