Skip to content

Commit 8139ffb

Browse files
authored
Clean up TopN rules in BanyanDB server that are not configured in the current config. (#13336)
1 parent d7d5812 commit 8139ffb

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

docs/en/setup/backend/configuration-vocabulary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ The global settings for the whole BanyanDB:
371371
| asyncProfilerTaskQueryMaxSize | Max size of AsyncProfilerTask to be fetched. | SW_STORAGE_BANYANDB_ASYNC_PROFILER_TASK_QUERY_MAX_SIZE | 200 |
372372
| profileDataQueryScrollBatchSize | The batch size of query profiling data. | SW_STORAGE_BANYAND_QUERY_PROFILE_DATA_BATCH_SIZE | 100 |
373373
| sslTrustCAPath | If the BanyanDB server is configured with TLS, config the TLS cert file path and open tls connection. | SW_STORAGE_BANYANDB_SSL_TRUST_CA_PATH | - |
374+
| cleanupUnusedTopNRules | Cleanup TopN rules in BanyanDB server that are not configured in the bydb-topn.yml config. | SW_STORAGE_BANYANDB_CLEANUP_UNUSED_TOPN_RULES | true |
374375

375376
### Group Configuration
376377
The settings for each group:

oap-server/server-starter/src/main/resources/bydb.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ global:
4545
asyncProfilerTaskQueryMaxSize: ${SW_STORAGE_BANYANDB_ASYNC_PROFILER_TASK_QUERY_MAX_SIZE:200}
4646
# If the BanyanDB server is configured with TLS, configure the TLS cert file path and enable TLS connection.
4747
sslTrustCAPath: ${SW_STORAGE_BANYANDB_SSL_TRUST_CA_PATH:""}
48+
# Cleanup TopN rules in BanyanDB server that are not configured in the bydb-topn.yml config.
49+
cleanupUnusedTopNRules: ${SW_STORAGE_BANYANDB_CLEANUP_UNUSED_TOPN_RULES:false}
4850

4951
groups:
5052
# The group settings of record.

oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBIndexInstaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ private void checkIndexRuleBinding(List<IndexRule> indexRules,
619619

620620
/**
621621
* Check if the TopN aggregation exists and update it if necessary.
622-
* todo:// can not delete TopN here now.
622+
* If the TopN rules are not used, will be checked and deleted after install, in the `BanyanDBStorageProvider.notifyAfterCompleted()`
623623
*/
624624
private void checkTopNAggregation(Model model, BanyanDBClient client) throws BanyanDBException {
625625
MetadataRegistry.Schema schema = MetadataRegistry.INSTANCE.findMetadata(model);

oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBStorageConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class BanyanDBStorageConfig extends ModuleConfig {
4646
private Metadata metadata = new Metadata();
4747
private Property property = new Property();
4848

49-
private Map<String/*metric name*/, Map<String, TopN>> topNConfigs = new HashMap<>();
49+
private Map<String/*metric name*/, Map<String, TopN>/*ruleName, topN*/> topNConfigs = new HashMap<>();
5050

5151
public String[] getTargetArray() {
5252
return Iterables.toArray(
@@ -98,6 +98,7 @@ public static class Global {
9898
private int metadataQueryMaxSize = 5000;
9999
private int segmentQueryMaxSize = 200;
100100
private int profileDataQueryBatchSize = 100;
101+
private boolean cleanupUnusedTopNRules = true;
101102
}
102103

103104
// The configuration of the groups.

oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/BanyanDBStorageProvider.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818

1919
package org.apache.skywalking.oap.server.storage.plugin.banyandb;
2020

21+
import java.util.HashSet;
22+
import java.util.List;
23+
import java.util.Set;
24+
import lombok.extern.slf4j.Slf4j;
25+
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
26+
import org.apache.skywalking.banyandb.database.v1.BanyandbDatabase;
27+
import org.apache.skywalking.banyandb.v1.client.grpc.exception.BanyanDBException;
2128
import org.apache.skywalking.oap.server.core.CoreModule;
2229
import org.apache.skywalking.oap.server.core.storage.IBatchDAO;
2330
import org.apache.skywalking.oap.server.core.storage.IHistoryDeleteDAO;
@@ -59,6 +66,7 @@
5966
import org.apache.skywalking.oap.server.library.module.ModuleProvider;
6067
import org.apache.skywalking.oap.server.library.module.ModuleStartException;
6168
import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException;
69+
import org.apache.skywalking.oap.server.library.util.CollectionUtils;
6270
import org.apache.skywalking.oap.server.storage.plugin.banyandb.measure.BanyanDBEBPFProfilingScheduleQueryDAO;
6371
import org.apache.skywalking.oap.server.storage.plugin.banyandb.stream.BanyanDBEventQueryDAO;
6472
import org.apache.skywalking.oap.server.storage.plugin.banyandb.measure.BanyanDBHierarchyQueryDAO;
@@ -89,6 +97,7 @@
8997
import org.apache.skywalking.oap.server.telemetry.api.MetricsCreator;
9098
import org.apache.skywalking.oap.server.telemetry.api.MetricsTag;
9199

100+
@Slf4j
92101
public class BanyanDBStorageProvider extends ModuleProvider {
93102
private BanyanDBStorageConfig config;
94103
private BanyanDBStorageClient client;
@@ -215,7 +224,45 @@ public void start() throws ServiceNotProvidedException, ModuleStartException {
215224

216225
@Override
217226
public void notifyAfterCompleted() throws ServiceNotProvidedException, ModuleStartException {
227+
// Cleanup TopN rules in BanyanDB server that are not configured in the current config.
228+
Set<String> topNNames = new HashSet<>();
229+
this.config.getTopNConfigs().values().forEach(topNConfig -> {
230+
topNNames.addAll(topNConfig.keySet());
231+
});
218232

233+
try {
234+
List<BanyandbCommon.Group> groups = this.client.client.findGroups();
235+
for (BanyandbCommon.Group group : groups) {
236+
if (BanyandbCommon.Catalog.CATALOG_MEASURE.equals(group.getCatalog())) {
237+
String groupName = group.getMetadata().getName();
238+
List<BanyandbDatabase.TopNAggregation> topNAggregations = this.client.client.findTopNAggregations(groupName);
239+
if (CollectionUtils.isNotEmpty(topNAggregations)) {
240+
for (BanyandbDatabase.TopNAggregation topNAggregation : topNAggregations) {
241+
String topNName = topNAggregation.getMetadata().getName();
242+
if (!topNNames.contains(topNName)) {
243+
if (this.config.getGlobal().isCleanupUnusedTopNRules()) {
244+
this.client.client.deleteTopNAggregation(groupName, topNName);
245+
log.info(
246+
"Deleted unused topN rule from BanyanDB server: {}, group: {}. Please check bydb-topn.yml. " +
247+
"If you don't want to cleanup unused rules from server, please set cleanupUnusedTopNRules=false in bydb.yml",
248+
topNName, groupName
249+
);
250+
} else {
251+
// Log the unused TopN aggregation.
252+
log.warn(
253+
"Unused topN rule in BanyanDB server: {}, group: {}. Please check bydb-topn.yml. " +
254+
"If you want to cleanup unused rules from server, please set cleanupUnusedTopNRules=true in bydb.yml",
255+
topNName, groupName
256+
);
257+
}
258+
}
259+
}
260+
}
261+
}
262+
}
263+
} catch (BanyanDBException e) {
264+
throw new ModuleStartException(e.getMessage(), e);
265+
}
219266
}
220267

221268
@Override

0 commit comments

Comments
 (0)