feat: add gb32960 session diagnostics
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.lingniu.ingest.gb32960app.actuator;
|
||||
|
||||
import com.lingniu.ingest.protocol.gb32960.inbound.Gb32960ConnectionDiagnostics;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Endpoint(id = "gb32960-sessions")
|
||||
public class Gb32960SessionsEndpoint {
|
||||
|
||||
private final Gb32960ConnectionDiagnostics diagnostics;
|
||||
|
||||
public Gb32960SessionsEndpoint(Gb32960ConnectionDiagnostics diagnostics) {
|
||||
this.diagnostics = diagnostics;
|
||||
}
|
||||
|
||||
@ReadOperation
|
||||
public Map<String, Object> sessions() {
|
||||
var sessions = diagnostics.activeSessions();
|
||||
return Map.of(
|
||||
"activeCount", sessions.size(),
|
||||
"sessions", sessions);
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,metrics,prometheus,env
|
||||
include: health,info,metrics,prometheus,env,gb32960-sessions
|
||||
health:
|
||||
redis:
|
||||
enabled: ${MANAGEMENT_HEALTH_REDIS_ENABLED:false}
|
||||
|
||||
@@ -30,7 +30,9 @@ class Gb32960IngestAppDefaultsTest {
|
||||
.containsEntry("lingniu.ingest.event-file-store.enabled", false)
|
||||
.containsEntry("lingniu.ingest.event-history.enabled", false)
|
||||
.containsEntry("lingniu.ingest.vehicle-state.enabled", false)
|
||||
.containsEntry("lingniu.ingest.vehicle-stat.enabled", false);
|
||||
.containsEntry("lingniu.ingest.vehicle-stat.enabled", false)
|
||||
.containsEntry("management.endpoints.web.exposure.include",
|
||||
"health,info,metrics,prometheus,env,gb32960-sessions");
|
||||
}
|
||||
|
||||
private static Properties applicationProperties() {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.lingniu.ingest.gb32960app.actuator;
|
||||
|
||||
import com.lingniu.ingest.protocol.gb32960.inbound.Gb32960ConnectionDiagnostics;
|
||||
import com.lingniu.ingest.protocol.gb32960.model.CommandType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class Gb32960SessionsEndpointTest {
|
||||
|
||||
@Test
|
||||
void returnsActiveGb32960Sessions() {
|
||||
Gb32960ConnectionDiagnostics diagnostics = new Gb32960ConnectionDiagnostics();
|
||||
diagnostics.opened("session-1", "127.0.0.1:65469");
|
||||
diagnostics.received("session-1", CommandType.PLATFORM_LOGIN, "");
|
||||
diagnostics.platformLoginAccepted("session-1", "Hyundai");
|
||||
|
||||
Gb32960SessionsEndpoint endpoint = new Gb32960SessionsEndpoint(diagnostics);
|
||||
|
||||
Map<String, Object> result = endpoint.sessions();
|
||||
|
||||
assertThat(result).containsEntry("activeCount", 1);
|
||||
assertThat(result.get("sessions")).isInstanceOf(List.class);
|
||||
assertThat((List<?>) result.get("sessions")).singleElement()
|
||||
.hasFieldOrPropertyWithValue("sessionId", "session-1")
|
||||
.hasFieldOrPropertyWithValue("peer", "127.0.0.1:65469")
|
||||
.hasFieldOrPropertyWithValue("lastCommand", "PLATFORM_LOGIN")
|
||||
.hasFieldOrPropertyWithValue("platformAccount", "Hyundai");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user