From c6347c50a4345f0005ea729da4f3f73fc51598ae Mon Sep 17 00:00:00 2001 From: lingniu Date: Wed, 1 Jul 2026 11:32:59 +0800 Subject: [PATCH] fix: keep telemetry fields out of default history api --- .../vehicle-ingest-tdengine-verification.md | 5 ++--- .../PortainerComposeResourceLimitsTest.java | 2 ++ .../VehicleHistoryAppCompositionTest.java | 22 +++++++++++++++++++ .../TelemetryFieldHistoryController.java | 7 +++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/operations/vehicle-ingest-tdengine-verification.md b/docs/operations/vehicle-ingest-tdengine-verification.md index 04b44a43..4df3f1b1 100644 --- a/docs/operations/vehicle-ingest-tdengine-verification.md +++ b/docs/operations/vehicle-ingest-tdengine-verification.md @@ -82,7 +82,6 @@ lsof -nP -iTCP:32960 -sTCP:LISTEN ```bash HTTP_PORT=20200 \ KAFKA_CONSUMER_ENABLED=true \ -EVENT_FILE_STORE_PATH=./target/tdengine-verification/event-store \ TDENGINE_TELEMETRY_FIELDS_ENABLED=false \ java -jar modules/apps/vehicle-history-app/target/vehicle-history-app.jar ``` @@ -92,10 +91,10 @@ java -jar modules/apps/vehicle-history-app/target/vehicle-history-app.jar ```bash curl -sS http://127.0.0.1:20200/actuator/health curl -sS http://127.0.0.1:20200/v3/api-docs \ - | grep -E '/api/event-history/jt808/locations|/api/event-history/gb32960/snapshots|/api/event-history/telemetry/fields' + | grep -E '/api/event-history/locations|/api/event-history/raw-frames' ``` -预期:健康检查为 `UP`,OpenAPI 中包含 JT808 TDengine 分页查询接口和 GB32960 snapshot 接口。`/api/event-history/telemetry/fields` 会存在,但只有在 `TDENGINE_TELEMETRY_FIELDS_ENABLED=true` 后才会持续写入新字段数据。 +预期:健康检查为 `UP`,OpenAPI 中包含通用位置分页查询和 RAW 帧查询接口。`/api/event-history/telemetry/fields` 只有在 `TDENGINE_TELEMETRY_FIELDS_ENABLED=true` 后才会暴露;默认高吞吐模式不暴露该接口,也不会持续写入逐字段宽表。 ## 本机 launchctl 部署 diff --git a/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/PortainerComposeResourceLimitsTest.java b/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/PortainerComposeResourceLimitsTest.java index 773835cd..d3ee5b30 100644 --- a/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/PortainerComposeResourceLimitsTest.java +++ b/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/PortainerComposeResourceLimitsTest.java @@ -118,6 +118,8 @@ class PortainerComposeResourceLimitsTest { .doesNotContain("再回读共享 archive") .doesNotContain("读取共享 archive 中的原始 `.bin`") .doesNotContain("EVENT_FILE_STORE_ENABLED") + .doesNotContain("EVENT_FILE_STORE_PATH") + .doesNotContain("/api/event-history/telemetry/fields' 会存在") .doesNotContain("/api/event-history/records"); assertThat(splitRunbook) .contains("TDengine `raw_frames`") diff --git a/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/VehicleHistoryAppCompositionTest.java b/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/VehicleHistoryAppCompositionTest.java index bba184b4..aa7b7aca 100644 --- a/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/VehicleHistoryAppCompositionTest.java +++ b/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/VehicleHistoryAppCompositionTest.java @@ -20,6 +20,7 @@ import com.lingniu.ingest.sink.kafka.KafkaEnvelopeConsumerRunner; import com.lingniu.ingest.sink.kafka.KafkaSinkProperties; import com.lingniu.ingest.sink.kafka.KafkaSinkAutoConfiguration; import com.lingniu.ingest.tdenginehistory.TdengineHistorySchema; +import com.lingniu.ingest.tdenginehistory.TdengineHistoryReader; import com.lingniu.ingest.tdenginehistory.TdengineHistoryWriter; import com.lingniu.ingest.tdenginehistory.config.TdengineHistoryAutoConfiguration; import org.apache.kafka.clients.producer.KafkaProducer; @@ -133,6 +134,27 @@ class VehicleHistoryAppCompositionTest { }); } + @Test + void applicationScanDoesNotExposeTelemetryFieldControllerByDefault() { + new ApplicationContextRunner() + .withUserConfiguration(VehicleHistoryApplication.class) + .withBean(TdengineHistoryReader.class, () -> mock(TdengineHistoryReader.class)) + .withPropertyValues( + "spring.cloud.nacos.config.enabled=false", + "spring.config.import=", + "lingniu.ingest.event-history.enabled=true", + "lingniu.ingest.tdengine-history.telemetry-fields-enabled=false", + "lingniu.ingest.tdengine-history.enabled=false", + "lingniu.ingest.sink.kafka.enabled=false", + "lingniu.ingest.sink.kafka.consumer.enabled=false", + "lingniu.ingest.gb32960.enabled=false") + .run(context -> { + assertThat(context).hasSingleBean(LocationHistoryController.class); + assertThat(context).hasSingleBean(RawFrameHistoryController.class); + assertThat(context).doesNotHaveBean(TelemetryFieldHistoryController.class); + }); + } + @Test void createsKafkaConsumerRunnerWhenTdengineHistoryRuntimeConsumesKafka() { new ApplicationContextRunner() diff --git a/modules/services/event-history-service/src/main/java/com/lingniu/ingest/eventhistory/TelemetryFieldHistoryController.java b/modules/services/event-history-service/src/main/java/com/lingniu/ingest/eventhistory/TelemetryFieldHistoryController.java index 4e6c1304..e8b60b4a 100644 --- a/modules/services/event-history-service/src/main/java/com/lingniu/ingest/eventhistory/TelemetryFieldHistoryController.java +++ b/modules/services/event-history-service/src/main/java/com/lingniu/ingest/eventhistory/TelemetryFieldHistoryController.java @@ -25,7 +25,12 @@ import java.util.Locale; import java.util.Map; @RestController -@ConditionalOnProperty(prefix = "lingniu.ingest.event-history", name = "enabled", havingValue = "true") +@ConditionalOnProperty( + name = { + "lingniu.ingest.event-history.enabled", + "lingniu.ingest.tdengine-history.telemetry-fields-enabled" + }, + havingValue = "true") @ConditionalOnBean(TdengineHistoryReader.class) @RequestMapping("/api/event-history/telemetry") @Tag(name = "telemetry-field-history-controller", description = "遥测字段历史分页查询接口。")