From 64da1193beb28d71de912f791cb75e1a1037037c Mon Sep 17 00:00:00 2001 From: sw1136562366 Date: Wed, 24 Jan 2024 13:28:37 +0800 Subject: [PATCH] feat: apm ttl (#781) --- .../common/model/storage/annotation/ModelAnnotation.java | 7 ++++++- .../engine/elasticsearch/HoloinsightEsConfiguration.java | 1 + .../server/apm/engine/elasticsearch/ttl/EsDataCleaner.java | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/apm/apm-common/src/main/java/io/holoinsight/server/apm/common/model/storage/annotation/ModelAnnotation.java b/server/apm/apm-common/src/main/java/io/holoinsight/server/apm/common/model/storage/annotation/ModelAnnotation.java index 145de0d99..21f093eef 100644 --- a/server/apm/apm-common/src/main/java/io/holoinsight/server/apm/common/model/storage/annotation/ModelAnnotation.java +++ b/server/apm/apm-common/src/main/java/io/holoinsight/server/apm/common/model/storage/annotation/ModelAnnotation.java @@ -17,5 +17,10 @@ public @interface ModelAnnotation { String name(); - long ttl() default 60000L * 60 * 24 * 3; + /** + * unit: day + * + * @return + */ + long ttl() default 0; } diff --git a/server/apm/apm-server/apm-engine/src/main/java/io/holoinsight/server/apm/engine/elasticsearch/HoloinsightEsConfiguration.java b/server/apm/apm-server/apm-engine/src/main/java/io/holoinsight/server/apm/engine/elasticsearch/HoloinsightEsConfiguration.java index 13a5afa83..4726f802b 100644 --- a/server/apm/apm-server/apm-engine/src/main/java/io/holoinsight/server/apm/engine/elasticsearch/HoloinsightEsConfiguration.java +++ b/server/apm/apm-server/apm-engine/src/main/java/io/holoinsight/server/apm/engine/elasticsearch/HoloinsightEsConfiguration.java @@ -60,6 +60,7 @@ public class HoloinsightEsConfiguration { private String password; private int shards = 5; private int replicas = 1; + private int ttl = 7; // unit: day @Bean("elasticsearchClient") @Primary diff --git a/server/apm/apm-server/apm-engine/src/main/java/io/holoinsight/server/apm/engine/elasticsearch/ttl/EsDataCleaner.java b/server/apm/apm-server/apm-engine/src/main/java/io/holoinsight/server/apm/engine/elasticsearch/ttl/EsDataCleaner.java index 3f80bccf9..7115300fb 100644 --- a/server/apm/apm-server/apm-engine/src/main/java/io/holoinsight/server/apm/engine/elasticsearch/ttl/EsDataCleaner.java +++ b/server/apm/apm-server/apm-engine/src/main/java/io/holoinsight/server/apm/engine/elasticsearch/ttl/EsDataCleaner.java @@ -6,6 +6,7 @@ import io.holoinsight.server.apm.common.constants.Const; import io.holoinsight.server.apm.common.model.storage.Model; import io.holoinsight.server.apm.core.ttl.DataCleaner; +import io.holoinsight.server.apm.engine.elasticsearch.HoloinsightEsConfiguration; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -30,13 +31,15 @@ public class EsDataCleaner implements DataCleaner { @Autowired private RestHighLevelClient esClient; + @Autowired + private HoloinsightEsConfiguration esConfiguration; protected RestHighLevelClient client() { return esClient; } protected long ttl(Model model) { - return model.getTtl(); + return model.getTtl() != 0 ? model.getTtl() : esConfiguration.getTtl() * 60000L * 60 * 24; } @Override