refactor: store runtime identity and mileage in mysql metrics
This commit is contained in:
@@ -5,7 +5,6 @@ import com.lingniu.ingest.api.consumer.EnvelopeDeadLetterSink;
|
||||
import com.lingniu.ingest.vehiclestat.DailyMileageCalculator;
|
||||
import com.lingniu.ingest.vehiclestat.DailyMileageStrategy;
|
||||
import com.lingniu.ingest.vehiclestat.DailyVehicleStatService;
|
||||
import com.lingniu.ingest.vehiclestat.FileVehicleStatRepository;
|
||||
import com.lingniu.ingest.vehiclestat.JdbcVehicleStatMetricRepository;
|
||||
import com.lingniu.ingest.vehiclestat.VehicleStatController;
|
||||
import com.lingniu.ingest.vehiclestat.VehicleStatEnvelopeIngestor;
|
||||
@@ -33,7 +32,6 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
|
||||
@@ -48,20 +46,11 @@ public class VehicleStatAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(JdbcTemplate.class)
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.vehicle-stat", name = "repository-type",
|
||||
havingValue = "jdbc", matchIfMissing = true)
|
||||
@ConditionalOnMissingBean
|
||||
public VehicleStatRepository jdbcVehicleStatMetricRepository(JdbcTemplate jdbcTemplate) {
|
||||
return new JdbcVehicleStatMetricRepository(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public VehicleStatRepository vehicleStatRepository(VehicleStatProperties props) {
|
||||
// 无 JDBC 指标库时才回落本地文件,主要用于开发和单元验证。
|
||||
return new FileVehicleStatRepository(Path.of(props.getFilePath()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public VehicleStatRuleRepository vehicleStatRuleRepository() {
|
||||
|
||||
@@ -5,33 +5,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@ConfigurationProperties(prefix = "lingniu.ingest.vehicle-stat")
|
||||
public class VehicleStatProperties {
|
||||
|
||||
/** 派生统计本地文件根目录;不是 32960 RAW archive 或 DuckDB 历史库目录。 */
|
||||
private String filePath = "./target/vehicle-stat/";
|
||||
|
||||
/** 指标仓储类型:有 JDBC 数据源时生产使用 jdbc;本地无数据库时回落 file。 */
|
||||
private String repositoryType = "jdbc";
|
||||
|
||||
/** 统计自然日口径,默认按国内业务使用东八区。 */
|
||||
private String zoneId = "Asia/Shanghai";
|
||||
|
||||
private Jt808 jt808 = new Jt808();
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getRepositoryType() {
|
||||
return repositoryType;
|
||||
}
|
||||
|
||||
public void setRepositoryType(String repositoryType) {
|
||||
this.repositoryType = repositoryType;
|
||||
}
|
||||
|
||||
public String getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.lingniu.ingest.api.consumer.EnvelopeDeadLetterSink;
|
||||
import com.lingniu.ingest.vehiclestat.DailyMileageCalculator;
|
||||
import com.lingniu.ingest.vehiclestat.DailyMileageStrategy;
|
||||
import com.lingniu.ingest.vehiclestat.DailyVehicleStatService;
|
||||
import com.lingniu.ingest.vehiclestat.FileVehicleStatRepository;
|
||||
import com.lingniu.ingest.vehiclestat.JdbcVehicleStatMetricRepository;
|
||||
import com.lingniu.ingest.vehiclestat.MileagePoint;
|
||||
import com.lingniu.ingest.vehiclestat.VehicleStatController;
|
||||
@@ -71,17 +70,14 @@ class VehicleStatAutoConfigurationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsFileRepositoryWhenNoRepositoryBeanExists() {
|
||||
void doesNotCreateRepositoryWithoutJdbcMetricStore() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(VehicleStatAutoConfiguration.class))
|
||||
.withPropertyValues("lingniu.ingest.vehicle-stat.enabled=true")
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(VehicleStatRepository.class);
|
||||
assertThat(context).hasSingleBean(FileVehicleStatRepository.class);
|
||||
assertThat(context).hasSingleBean(VehicleStatRuleRepository.class);
|
||||
assertThat(context).hasSingleBean(DailyMileageCalculator.class);
|
||||
assertThat(context).hasSingleBean(DailyVehicleStatService.class);
|
||||
assertThat(context).hasSingleBean(VehicleStatEventProcessor.class);
|
||||
assertThat(context).doesNotHaveBean(VehicleStatRepository.class);
|
||||
assertThat(context).doesNotHaveBean(DailyVehicleStatService.class);
|
||||
assertThat(context).doesNotHaveBean(VehicleStatEventProcessor.class);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -142,7 +138,7 @@ class VehicleStatAutoConfigurationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void canForceFileRepositoryEvenWhenJdbcTemplateExists() {
|
||||
void ignoresFileRepositoryTypeAndKeepsJdbcMetricRepository() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
JdbcTemplateAutoConfiguration.class,
|
||||
@@ -156,8 +152,7 @@ class VehicleStatAutoConfigurationTest {
|
||||
"lingniu.ingest.vehicle-stat.repository-type=file")
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(VehicleStatRepository.class);
|
||||
assertThat(context).hasSingleBean(FileVehicleStatRepository.class);
|
||||
assertThat(context).doesNotHaveBean(JdbcVehicleStatMetricRepository.class);
|
||||
assertThat(context).hasSingleBean(JdbcVehicleStatMetricRepository.class);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user