refactor: store jt808 mileage metrics directly

This commit is contained in:
lingniu
2026-07-01 03:31:10 +08:00
parent a3367f1886
commit 140b3f3995
19 changed files with 236 additions and 729 deletions

View File

@@ -81,8 +81,6 @@ lingniu:
zone-id: ${VEHICLE_STAT_ZONE_ID:Asia/Shanghai}
jt808:
enabled: ${VEHICLE_STAT_JT808_MILEAGE_ENABLED:true}
redis-key-prefix: ${VEHICLE_STAT_JT808_REDIS_KEY_PREFIX:vehicle:mileage:jt808:daily:}
state-ttl-days: ${VEHICLE_STAT_JT808_STATE_TTL_DAYS:3}
management:
endpoints:

View File

@@ -0,0 +1,71 @@
package com.lingniu.ingest.historyapp;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.assertj.core.api.Assertions.assertThat;
class PortainerComposeResourceLimitsTest {
@Test
void productionServicesHaveOverridableMemoryLimits() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
assertServiceMemoryLimit(compose, "gb32960-ingest-app", "GB32960_MEM_LIMIT", "768m");
assertServiceMemoryLimit(compose, "jt808-ingest-app", "JT808_MEM_LIMIT", "768m");
assertServiceMemoryLimit(compose, "yutong-mqtt-app", "YUTONG_MQTT_MEM_LIMIT", "512m");
assertServiceMemoryLimit(compose, "vehicle-history-app", "VEHICLE_HISTORY_MEM_LIMIT", "1536m");
assertServiceMemoryLimit(compose, "vehicle-analytics-app", "VEHICLE_ANALYTICS_MEM_LIMIT", "1024m");
}
@Test
void vehicleHistoryUsesApplicationConsumerGroupEnvironmentNames() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
assertThat(compose)
.contains("KAFKA_GROUP_HISTORY_GB32960_EVENT: ${KAFKA_GROUP_HISTORY_GB32960_EVENT:-${KAFKA_GROUP_HISTORY:-vehicle-history}-gb32960-event}")
.contains("KAFKA_GROUP_HISTORY_JT808_EVENT: ${KAFKA_GROUP_HISTORY_JT808_EVENT:-${KAFKA_GROUP_HISTORY:-vehicle-history}-jt808-event}")
.contains("KAFKA_GROUP_HISTORY_YUTONG_MQTT_EVENT: ${KAFKA_GROUP_HISTORY_YUTONG_MQTT_EVENT:-${KAFKA_GROUP_HISTORY:-vehicle-history}-yutong-mqtt-event}")
.contains("KAFKA_GROUP_HISTORY_GB32960_RAW: ${KAFKA_GROUP_HISTORY_GB32960_RAW:-${KAFKA_GROUP_HISTORY:-vehicle-history}-gb32960-raw}")
.contains("KAFKA_GROUP_HISTORY_JT808_RAW: ${KAFKA_GROUP_HISTORY_JT808_RAW:-${KAFKA_GROUP_HISTORY:-vehicle-history}-jt808-raw}")
.contains("KAFKA_GROUP_HISTORY_YUTONG_MQTT_RAW: ${KAFKA_GROUP_HISTORY_YUTONG_MQTT_RAW:-${KAFKA_GROUP_HISTORY:-vehicle-history}-yutong-mqtt-raw}")
.doesNotContain("\n KAFKA_GROUP_HISTORY_GB32960:")
.doesNotContain("\n KAFKA_GROUP_HISTORY_JT808:")
.doesNotContain("\n KAFKA_GROUP_HISTORY_MQTT_YUTONG:");
}
@Test
void vehicleHistoryUsesTdengineHistoryEnvironmentNames() throws IOException {
String compose = Files.readString(repositoryRoot().resolve("deploy/portainer/docker-compose.yml"));
assertThat(compose)
.contains("TDENGINE_HISTORY_ENABLED: ${TDENGINE_HISTORY_ENABLED:-true}")
.contains("TDENGINE_HISTORY_DATABASE: ${TDENGINE_HISTORY_DATABASE:-vehicle_ts}")
.doesNotContain("\n TDENGINE_ENABLED:")
.doesNotContain("\n TDENGINE_DATABASE:");
}
private static void assertServiceMemoryLimit(String compose,
String serviceName,
String envName,
String defaultLimit) {
assertThat(compose)
.contains(serviceName + ":\n")
.contains("\n " + serviceName + ":\n")
.contains(" mem_limit: ${" + envName + ":-" + defaultLimit + "}");
}
private static Path repositoryRoot() {
Path current = Path.of(System.getProperty("user.dir")).toAbsolutePath();
while (current != null) {
if (Files.exists(current.resolve("deploy/portainer/docker-compose.yml"))) {
return current;
}
current = current.getParent();
}
throw new IllegalStateException("repository root not found");
}
}