|
18 | 18 |
|
19 | 19 | package org.apache.skywalking.oap.server.storage.plugin.banyandb; |
20 | 20 |
|
| 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; |
21 | 28 | import org.apache.skywalking.oap.server.core.CoreModule; |
22 | 29 | import org.apache.skywalking.oap.server.core.storage.IBatchDAO; |
23 | 30 | import org.apache.skywalking.oap.server.core.storage.IHistoryDeleteDAO; |
|
59 | 66 | import org.apache.skywalking.oap.server.library.module.ModuleProvider; |
60 | 67 | import org.apache.skywalking.oap.server.library.module.ModuleStartException; |
61 | 68 | import org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException; |
| 69 | +import org.apache.skywalking.oap.server.library.util.CollectionUtils; |
62 | 70 | import org.apache.skywalking.oap.server.storage.plugin.banyandb.measure.BanyanDBEBPFProfilingScheduleQueryDAO; |
63 | 71 | import org.apache.skywalking.oap.server.storage.plugin.banyandb.stream.BanyanDBEventQueryDAO; |
64 | 72 | import org.apache.skywalking.oap.server.storage.plugin.banyandb.measure.BanyanDBHierarchyQueryDAO; |
|
89 | 97 | import org.apache.skywalking.oap.server.telemetry.api.MetricsCreator; |
90 | 98 | import org.apache.skywalking.oap.server.telemetry.api.MetricsTag; |
91 | 99 |
|
| 100 | +@Slf4j |
92 | 101 | public class BanyanDBStorageProvider extends ModuleProvider { |
93 | 102 | private BanyanDBStorageConfig config; |
94 | 103 | private BanyanDBStorageClient client; |
@@ -215,7 +224,45 @@ public void start() throws ServiceNotProvidedException, ModuleStartException { |
215 | 224 |
|
216 | 225 | @Override |
217 | 226 | 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 | + }); |
218 | 232 |
|
| 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 | + } |
219 | 266 | } |
220 | 267 |
|
221 | 268 | @Override |
|
0 commit comments