Skip to content

Commit f7da99d

Browse files
authored
Add more model installation log info for OAP storage initialization. (#13094)
1 parent 3048c6a commit f7da99d

File tree

5 files changed

+194
-31
lines changed
  • docs/en/changes
  • oap-server
    • server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/model
    • server-storage-plugin
      • storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb
      • storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base
      • storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common

5 files changed

+194
-31
lines changed

Diff for: docs/en/changes/changes.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
* Optimize metrics cache loading when trace latency greater than cache timeout.
7878
* Allow calling `lang.groovy.GString` in DSL.
7979
* BanyanDB: fix alarm query result without sort.
80-
* Add a component ID for Virtual thread executor
80+
* Add a component ID for Virtual thread executor.
81+
* Add more model installation log info for OAP storage initialization.
8182

8283
#### UI
8384

Diff for: oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/model/ModelInstaller.java

+48-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
package org.apache.skywalking.oap.server.core.storage.model;
2020

21+
import lombok.Getter;
2122
import lombok.RequiredArgsConstructor;
23+
import lombok.Setter;
2224
import lombok.extern.slf4j.Slf4j;
2325
import org.apache.skywalking.oap.server.core.CoreModule;
2426
import org.apache.skywalking.oap.server.core.RunningMode;
@@ -38,20 +40,29 @@ public abstract class ModelInstaller implements ModelCreator.CreatingListener {
3840
@Override
3941
public void whenCreating(Model model) throws StorageException {
4042
if (RunningMode.isNoInitMode()) {
41-
while (!isExists(model)) {
42-
try {
43-
log.info(
44-
"table: {} does not exist. OAP is running in 'no-init' mode, waiting... retry 3s later.",
45-
model.getName()
46-
);
47-
Thread.sleep(3000L);
48-
} catch (InterruptedException e) {
49-
log.error(e.getMessage());
43+
while (true) {
44+
InstallInfo info = isExists(model);
45+
if (!info.isAllExist()) {
46+
try {
47+
log.info(
48+
"install info: {}.table for model: [{}] not all required resources exist. OAP is running in 'no-init' mode, waiting create or update... retry 3s later.",
49+
info.buildInstallInfoMsg(), model.getName()
50+
);
51+
Thread.sleep(3000L);
52+
} catch (InterruptedException e) {
53+
log.error(e.getMessage());
54+
}
55+
} else {
56+
break;
5057
}
5158
}
5259
} else {
53-
if (!isExists(model)) {
54-
log.info("table: {} does not exist", model.getName());
60+
InstallInfo info = isExists(model);
61+
if (!info.isAllExist()) {
62+
log.info(
63+
"install info: {}. table for model: [{}] not all required resources exist, creating or updating...",
64+
info.buildInstallInfoMsg(), model.getName()
65+
);
5566
createTable(model);
5667
}
5768
}
@@ -74,10 +85,35 @@ protected final void overrideColumnName(String columnName, String newName) {
7485
/**
7586
* Check whether the storage entity exists. Need to implement based on the real storage.
7687
*/
77-
public abstract boolean isExists(Model model) throws StorageException;
88+
public abstract InstallInfo isExists(Model model) throws StorageException;
7889

7990
/**
8091
* Create the storage entity. All creations should be after the {@link #isExists(Model)} check.
8192
*/
8293
public abstract void createTable(Model model) throws StorageException;
94+
95+
@Getter
96+
@Setter
97+
public abstract static class InstallInfo {
98+
private final String modelName;
99+
private final boolean timeSeries;
100+
private final boolean superDataset;
101+
private final String modelType;
102+
private boolean allExist;
103+
104+
protected InstallInfo(Model model) {
105+
this.modelName = model.getName();
106+
this.timeSeries = model.isTimeSeries();
107+
this.superDataset = model.isSuperDataset();
108+
if (model.isMetric()) {
109+
this.modelType = "metric";
110+
} else if (model.isRecord()) {
111+
this.modelType = "record";
112+
} else {
113+
this.modelType = "unknown";
114+
}
115+
}
116+
117+
public abstract String buildInstallInfoMsg();
118+
}
83119
}

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

+54-8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.Map;
2626
import java.util.Set;
2727
import java.util.stream.Collectors;
28+
import lombok.Getter;
29+
import lombok.Setter;
2830
import lombok.extern.slf4j.Slf4j;
2931
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon;
3032
import org.apache.skywalking.banyandb.common.v1.BanyandbCommon.Group;
@@ -41,6 +43,7 @@
4143
import org.apache.skywalking.banyandb.v1.client.metadata.ResourceExist;
4244
import org.apache.skywalking.oap.server.core.CoreModule;
4345
import org.apache.skywalking.oap.server.core.RunningMode;
46+
import org.apache.skywalking.oap.server.core.analysis.DownSampling;
4447
import org.apache.skywalking.oap.server.core.config.DownSamplingConfigService;
4548
import org.apache.skywalking.oap.server.core.storage.StorageException;
4649
import org.apache.skywalking.oap.server.core.storage.model.Model;
@@ -62,21 +65,31 @@ public BanyanDBIndexInstaller(Client client, ModuleManager moduleManager, Banyan
6265
}
6366

6467
@Override
65-
public boolean isExists(Model model) throws StorageException {
68+
public InstallInfo isExists(Model model) throws StorageException {
69+
InstallInfoBanyanDB installInfo = new InstallInfoBanyanDB(model);
70+
installInfo.setDownSampling(model.getDownsampling());
6671
if (!model.isTimeSeries()) {
67-
return true;
72+
installInfo.setTableName(model.getName());
73+
installInfo.setAllExist(true);
74+
return installInfo;
6875
}
6976
final DownSamplingConfigService downSamplingConfigService = moduleManager.find(CoreModule.NAME)
7077
.provider()
7178
.getService(DownSamplingConfigService.class);
7279
final MetadataRegistry.SchemaMetadata metadata = MetadataRegistry.INSTANCE.parseMetadata(
7380
model, config, downSamplingConfigService);
81+
installInfo.setTableName(metadata.name());
82+
installInfo.setKind(metadata.getKind());
83+
installInfo.setGroup(metadata.getGroup());
7484
try {
7585
final BanyanDBClient c = ((BanyanDBStorageClient) this.client).client;
7686
// first check resource existence and create group if necessary
77-
final boolean resourceExist = checkResourceExistence(metadata, c);
78-
if (!resourceExist) {
79-
return false;
87+
final ResourceExist resourceExist = checkResourceExistence(metadata, c);
88+
installInfo.setGroupExist(resourceExist.hasGroup());
89+
installInfo.setTableExist(resourceExist.hasResource());
90+
if (!resourceExist.hasResource()) {
91+
installInfo.setAllExist(false);
92+
return installInfo;
8093
} else {
8194
// register models only locally(Schema cache) but not remotely
8295
if (model.isRecord()) { // stream
@@ -108,7 +121,8 @@ public boolean isExists(Model model) throws StorageException {
108121
if (remoteMeta == null) {
109122
throw new IllegalStateException("inconsistent state: metadata:" + metadata + ", remoteMeta: null");
110123
}
111-
return true;
124+
installInfo.setAllExist(true);
125+
return installInfo;
112126
}
113127
} catch (BanyanDBException ex) {
114128
throw new StorageException("fail to check existence", ex);
@@ -206,7 +220,7 @@ private boolean checkGroup(MetadataRegistry.SchemaMetadata metadata, BanyanDBCli
206220
|| g.getResourceOpts().getTtl().getNum() != metadata.getTtlDays();
207221
}
208222

209-
private boolean checkResourceExistence(MetadataRegistry.SchemaMetadata metadata,
223+
private ResourceExist checkResourceExistence(MetadataRegistry.SchemaMetadata metadata,
210224
BanyanDBClient client) throws BanyanDBException {
211225
ResourceExist resourceExist;
212226
Group.Builder gBuilder
@@ -265,7 +279,7 @@ private boolean checkResourceExistence(MetadataRegistry.SchemaMetadata metadata,
265279
groupAligned.add(metadata.getGroup());
266280
}
267281
}
268-
return resourceExist.hasResource();
282+
return resourceExist;
269283
}
270284

271285
/**
@@ -559,4 +573,36 @@ private void checkTopNAggregation(Model model, BanyanDBClient client) throws Ban
559573
}
560574
}
561575
}
576+
577+
@Getter
578+
@Setter
579+
private static class InstallInfoBanyanDB extends InstallInfo {
580+
private DownSampling downSampling;
581+
private String tableName;
582+
private MetadataRegistry.Kind kind;
583+
private String group;
584+
private boolean tableExist;
585+
private boolean groupExist;
586+
587+
protected InstallInfoBanyanDB(Model model) {
588+
super(model);
589+
}
590+
591+
@Override
592+
public String buildInstallInfoMsg() {
593+
return "InstallInfoBanyanDB{" +
594+
"modelName=" + getModelName() +
595+
", modelType=" + getModelType() +
596+
", timeSeries=" + isTimeSeries() +
597+
", superDataset=" + isSuperDataset() +
598+
", downSampling=" + downSampling.name() +
599+
", tableName=" + tableName +
600+
", kind=" + kind.name() +
601+
", group=" + group +
602+
", allResourcesExist=" + isAllExist() +
603+
" [groupExist=" + groupExist +
604+
", tableExist=" + tableExist +
605+
"]}";
606+
}
607+
}
562608
}

Diff for: oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java

+54-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.fasterxml.jackson.core.type.TypeReference;
2222
import com.google.common.base.Strings;
2323
import com.google.gson.Gson;
24+
import lombok.Getter;
2425
import lombok.Setter;
2526
import lombok.extern.slf4j.Slf4j;
2627
import org.apache.skywalking.library.elasticsearch.response.Index;
@@ -81,12 +82,15 @@ protected IndexStructures getStructures() {
8182
}
8283

8384
@Override
84-
public boolean isExists(Model model) throws StorageException {
85+
public InstallInfo isExists(Model model) throws StorageException {
86+
InstallInfoES installInfo = new InstallInfoES(model, config);
8587
ElasticSearchClient esClient = (ElasticSearchClient) client;
8688
String tableName = IndexController.INSTANCE.getTableName(model);
8789
IndexController.LogicIndicesRegister.registerRelation(model, tableName);
90+
installInfo.setTableName(esClient.formatIndexName(tableName));
8891
if (!model.isTimeSeries()) {
8992
boolean exist = esClient.isExistsIndex(tableName);
93+
installInfo.setTableExist(exist);
9094
if (exist) {
9195
Optional<Index> index = esClient.getIndex(tableName);
9296
Mappings historyMapping = index.map(Index::getMappings).orElseGet(Mappings::new);
@@ -97,15 +101,21 @@ public boolean isExists(Model model) throws StorageException {
97101
// or updating field types, it just cares about whether the data can be ingested without
98102
// reporting errors.
99103
exist = structures.containsFieldNames(tableName, createMapping(model));
104+
installInfo.setAllFieldsExist(exist);
100105
} else {
101106
boolean containsMapping = structures.containsMapping(tableName, createMapping(model));
102-
exist = containsMapping && structures.compareIndexSetting(tableName, createSetting(model));
107+
installInfo.setAllFieldsExist(containsMapping);
108+
boolean containsSetting = structures.compareIndexSetting(tableName, createSetting(model));
109+
installInfo.setAllIndexSettingsExist(containsSetting);
110+
exist = containsMapping && containsSetting;
103111
}
104112
}
105-
return exist;
113+
installInfo.setAllExist(exist);
114+
return installInfo;
106115
}
107116

108117
boolean templateExists = esClient.isExistsTemplate(tableName);
118+
installInfo.setTableExist(templateExists);
109119
final Optional<IndexTemplate> template = esClient.getTemplate(tableName);
110120

111121
if ((templateExists && template.isEmpty()) || (!templateExists && template.isPresent())) {
@@ -123,12 +133,17 @@ public boolean isExists(Model model) throws StorageException {
123133
// because the no-init mode OAP server doesn't take responsibility for index settings.
124134
if (RunningMode.isNoInitMode()) {
125135
exist = structures.containsFieldNames(tableName, createMapping(model));
136+
installInfo.setAllFieldsExist(exist);
126137
} else {
127138
boolean containsMapping = structures.containsMapping(tableName, createMapping(model));
128-
exist = containsMapping && structures.compareIndexSetting(tableName, createSetting(model));
139+
installInfo.setAllFieldsExist(containsMapping);
140+
boolean containsSetting = structures.compareIndexSetting(tableName, createSetting(model));
141+
installInfo.setAllIndexSettingsExist(containsSetting);
142+
exist = containsMapping && containsSetting;
129143
}
130144
}
131-
return exist;
145+
installInfo.setAllExist(exist);
146+
return installInfo;
132147
}
133148

134149
@Override
@@ -373,4 +388,38 @@ protected Mappings createMapping(Model model) {
373388

374389
return mappings;
375390
}
391+
392+
@Getter
393+
@Setter
394+
public static class InstallInfoES extends InstallInfo {
395+
private String tableName;
396+
private boolean tableExist;
397+
private boolean allFieldsExist;
398+
private boolean allIndexSettingsExist;
399+
private StorageModuleElasticsearchConfig config;
400+
401+
protected InstallInfoES(Model model, StorageModuleElasticsearchConfig config) {
402+
super(model);
403+
this.config = config;
404+
}
405+
406+
@Override
407+
public String buildInstallInfoMsg() {
408+
String tableNameMsg = isTimeSeries() ? "indexTemplateName=" + tableName : "indexName=" + tableName;
409+
String tableExistMsg = isTimeSeries() ? "indexTemplateExists=" + tableExist : "indexExists=" + tableExist;
410+
return "InstallInfoES:{" +
411+
"modelName=" + getModelName() +
412+
", modelType=" + getModelType() +
413+
", timeSeries=" + isTimeSeries() +
414+
", superDataset=" + isSuperDataset() +
415+
", logicSharding=" + config.isLogicSharding() +
416+
", indexNamespace=" + config.getNamespace() +
417+
", " + tableNameMsg +
418+
", allResourcesExist=" + isAllExist() +
419+
" [" + tableExistMsg +
420+
", allFieldsExist=" + allFieldsExist +
421+
", allIndexSettingsExist=" + allIndexSettingsExist +
422+
"]}";
423+
}
424+
}
376425
}

Diff for: oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/JDBCTableInstaller.java

+36-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package org.apache.skywalking.oap.server.storage.plugin.jdbc.common;
2020

2121
import com.google.gson.JsonObject;
22+
import lombok.Getter;
23+
import lombok.Setter;
2224
import lombok.SneakyThrows;
2325
import lombok.extern.slf4j.Slf4j;
2426
import org.apache.skywalking.oap.server.core.analysis.DownSampling;
@@ -64,14 +66,16 @@ public JDBCTableInstaller(Client client, ModuleManager moduleManager) {
6466

6567
@Override
6668
@SneakyThrows
67-
public boolean isExists(Model model) {
69+
public InstallInfo isExists(Model model) {
70+
InstallInfoJDBC installInfo = new InstallInfoJDBC(model);
6871
TableMetaInfo.addModel(model);
6972

7073
final var table = TableHelper.getLatestTableForWrite(model);
71-
74+
installInfo.setTableName(table);
7275
final var jdbcClient = (JDBCClient) client;
7376
if (!jdbcClient.tableExists(table)) {
74-
return false;
77+
installInfo.setAllExist(false);
78+
return installInfo;
7579
}
7680

7781
final var databaseColumns = getDatabaseColumns(table);
@@ -81,8 +85,9 @@ public boolean isExists(Model model) {
8185
.map(ModelColumn::getColumnName)
8286
.map(ColumnName::getStorageName)
8387
.anyMatch(not(databaseColumns::contains));
84-
85-
return !isAnyColumnNotCreated;
88+
installInfo.setAllColumnsExist(isAnyColumnNotCreated);
89+
installInfo.setAllExist(!isAnyColumnNotCreated);
90+
return installInfo;
8691
}
8792

8893
@Override
@@ -277,4 +282,30 @@ private void createTable(String table, List<ModelColumn> columns, boolean isAddi
277282

278283
executeSQL(sql);
279284
}
285+
286+
@Getter
287+
@Setter
288+
private static class InstallInfoJDBC extends InstallInfo {
289+
private String tableName;
290+
private boolean tableExist;
291+
private boolean allColumnsExist;
292+
293+
protected InstallInfoJDBC(Model model) {
294+
super(model);
295+
}
296+
297+
@Override
298+
public String buildInstallInfoMsg() {
299+
return "InstallInfoJDBC{" +
300+
"modelName=" + getModelName() +
301+
", modelType=" + getModelType() +
302+
", timeSeries=" + isTimeSeries() +
303+
", superDataset=" + isSuperDataset() +
304+
", tableName=" + tableName +
305+
", allResourcesExist=" + isAllExist() +
306+
" [tableExist=" + tableExist +
307+
", allColumnsExist=" + allColumnsExist +
308+
"]}";
309+
}
310+
}
280311
}

0 commit comments

Comments
 (0)