Skip to content

Commit

Permalink
Introduce booster-ui and implement v9 template management protocol (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
wankai123 authored Mar 9, 2022
1 parent eb7529a commit f3743ee
Show file tree
Hide file tree
Showing 20 changed files with 213 additions and 180 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[submodule "oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol"]
path = oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol
url = https://github.com/apache/skywalking-query-protocol.git
[submodule "skywalking-ui"]
path = skywalking-ui
url = https://github.com/apache/skywalking-rocketbot-ui.git
[submodule "test/e2e-v2/java-test-service/e2e-protocol/src/main/proto"]
path = test/e2e-v2/java-test-service/e2e-protocol/src/main/proto
url = https://github.com/apache/skywalking-data-collect-protocol.git
[submodule "skywalking-ui"]
path = skywalking-ui
url = https://github.com/apache/skywalking-booster-ui.git
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ Release Notes.
* Support large service/instance/networkAddressAlias list query by using ElasticSearch scrolling API, add `metadataQueryBatchSize` to configure scrolling page size.
* Change default value of `metadataQueryMaxSize` from `5000` to `10000`
* Replace deprecated Armeria API `BasicToken.of` with `AuthToken.ofBasic`.
* Implement v9 UI template management protocol.

#### UI

* Remove unused jars (log4j-api.jar) in classpath.
* Bump up netty version to fix CVE.
* Add Database Connection pool metric.
* Introduce skywalking-booster-ui, remove skywalking-rocketbot-ui.

#### Documentation

Expand Down
2 changes: 1 addition & 1 deletion apm-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<version>${frontend-maven-plugin.version}</version>
<configuration>
<workingDirectory>${ui.path}</workingDirectory>
<nodeVersion>v8.17.0</nodeVersion>
<nodeVersion>v14.19.0</nodeVersion>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,54 +37,48 @@
@ScopeDeclaration(id = UI_TEMPLATE, name = "UITemplate")
@Stream(name = UITemplate.INDEX_NAME, scopeId = UI_TEMPLATE, builder = UITemplate.Builder.class, processor = ManagementStreamProcessor.class)
@EqualsAndHashCode(of = {
"name"
"templateId"
}, callSuper = false)
public class UITemplate extends ManagementData {
public static final String INDEX_NAME = "ui_template";
public static final String NAME = "name";
public static final String TYPE = "type";
public static final String TEMPLATE_ID = "template_id";
public static final String CONFIGURATION = "configuration";
public static final String ACTIVATED = "activated";
public static final String UPDATE_TIME = "update_time";
public static final String DISABLED = "disabled";

@Column(columnName = NAME)
private String name;
@Column(columnName = TYPE, storageOnly = true)
private String type;
@Column(columnName = TEMPLATE_ID)
private String templateId;
/**
* Configuration in JSON format.
*/
@Column(columnName = CONFIGURATION, storageOnly = true, length = 1_000_000)
private String configuration;
@Column(columnName = ACTIVATED, storageOnly = true)
private int activated;
@Column(columnName = UPDATE_TIME)
private long updateTime;
@Column(columnName = DISABLED)
private int disabled;

@Override
public String id() {
return name;
return templateId;
}

public static class Builder implements StorageHashMapBuilder<UITemplate> {
@Override
public UITemplate storage2Entity(final Map<String, Object> dbMap) {
UITemplate uiTemplate = new UITemplate();
uiTemplate.setName((String) dbMap.get(NAME));
uiTemplate.setType((String) dbMap.get(TYPE));
uiTemplate.setTemplateId((String) dbMap.get(TEMPLATE_ID));
uiTemplate.setConfiguration((String) dbMap.get(CONFIGURATION));
uiTemplate.setActivated(((Number) dbMap.get(ACTIVATED)).intValue());
uiTemplate.setDisabled(((Number) dbMap.get(DISABLED)).intValue());
return uiTemplate;
}

@Override
public Map<String, Object> entity2Storage(final UITemplate storageData) {
final HashMap<String, Object> map = new HashMap<>();
map.put(NAME, storageData.getName());
map.put(TYPE, storageData.getType());
map.put(TEMPLATE_ID, storageData.getTemplateId());
map.put(CONFIGURATION, storageData.getConfiguration());
map.put(ACTIVATED, storageData.getActivated());
map.put(UPDATE_TIME, storageData.getUpdateTime());
map.put(DISABLED, storageData.getDisabled());
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.oap.server.library.util.StringUtil;
import org.apache.skywalking.oap.server.core.query.enumeration.TemplateType;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.yaml.snakeyaml.Yaml;

/**
Expand All @@ -53,44 +49,7 @@ public UITemplateInitializer(InputStream inputStream) {

public List<UITemplate> read() {
List<UITemplate> uiTemplates = new ArrayList<>();
if (Objects.nonNull(yamlData)) {
List templates = (List) yamlData.get("templates");
if (templates != null) {
templates.forEach(templateObj -> {
final Map template = (Map) templateObj;
UITemplate newTemplate = new UITemplate();
final String name = (String) template.get("name");
if (StringUtil.isEmpty(name)) {
throw new IllegalArgumentException("template name shouldn't be null");
}
newTemplate.setName(name);
final String type = (String) template.getOrDefault("type", TemplateType.DASHBOARD.name());
TemplateType.forName(type); // for checking.
newTemplate.setType(type);
final String configuration = (String) template.get("configuration");
if (StringUtil.isEmpty(configuration)) {
throw new IllegalArgumentException("template configuration shouldn't be null");
}
newTemplate.setConfiguration(configuration);
newTemplate.setActivated(
BooleanUtils.booleanToValue(
// The template should be activated in default, it is just an option.
(Boolean) template.getOrDefault("activated", false)
)
);
newTemplate.setDisabled(
BooleanUtils.booleanToValue(
// The template should be available in default.
(Boolean) template.getOrDefault("disabled", false)
)
);
if (uiTemplates.contains(newTemplate)) {
throw new IllegalArgumentException("Template " + newTemplate.getName() + " name conflicts");
}
uiTemplates.add(newTemplate);
});
}
}
//Todo: implement later when new template file ready
return uiTemplates;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package org.apache.skywalking.oap.server.core.management.ui.template;

import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.skywalking.oap.server.core.query.input.DashboardSetting;
Expand All @@ -45,11 +43,17 @@ private UITemplateManagementDAO getUITemplateManagementDAO() {
return uiTemplateManagementDAO;
}

public DashboardConfiguration getTemplate(String id) throws IOException {
DashboardConfiguration configuration = getUITemplateManagementDAO().getTemplate(id);
if (configuration.isDisabled()) {
return null;
}
return configuration;
}

public List<DashboardConfiguration> getAllTemplates(Boolean includingDisabled) throws IOException {
final List<DashboardConfiguration> allTemplates =
getUITemplateManagementDAO().getAllTemplates(includingDisabled);
// Make sure the template in A-Za-z
Collections.sort(allTemplates, Comparator.comparing(DashboardConfiguration::getName));
return allTemplates;
}

Expand All @@ -61,7 +65,7 @@ public TemplateChangeStatus changeTemplate(DashboardSetting setting) throws IOEx
return getUITemplateManagementDAO().changeTemplate(setting);
}

public TemplateChangeStatus disableTemplate(String name) throws IOException {
return getUITemplateManagementDAO().disableTemplate(name);
public TemplateChangeStatus disableTemplate(String id) throws IOException {
return getUITemplateManagementDAO().disableTemplate(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,20 @@
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.management.ui.template.UITemplate;
import org.apache.skywalking.oap.server.core.query.enumeration.TemplateType;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;

@Setter
@Getter
public class DashboardSetting {
private String name;
private TemplateType type;
private String id;
private String configuration;
private boolean active;
private long updateTime;

public UITemplate toEntity() {
UITemplate uiTemplate = new UITemplate();
uiTemplate.setName(this.getName());
uiTemplate.setTemplateId(this.id);
uiTemplate.setConfiguration(this.getConfiguration());
uiTemplate.setType(this.getType().name());
uiTemplate.setActivated(BooleanUtils.booleanToValue(this.isActive()));
uiTemplate.setUpdateTime(this.updateTime);
uiTemplate.setDisabled(BooleanUtils.FALSE);
return uiTemplate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
*
*/

package org.apache.skywalking.oap.server.core.query.enumeration;
package org.apache.skywalking.oap.server.core.query.input;

public enum TemplateType {
DASHBOARD,
TOPOLOGY_SERVICE,
TOPOLOGY_INSTANCE,
TOPOLOGY_ENDPOINT,
TOPOLOGY_SERVICE_RELATION,
TOPOLOGY_SERVICE_INSTANCE_RELATION,
TOPOLOGY_ENDPOINT_RELATION,
;
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.management.ui.template.UITemplate;

public static TemplateType forName(String name) {
return Enum.valueOf(TemplateType.class, name.toUpperCase());
@Setter
@Getter
public class NewDashboardSetting {
private String configuration;

public UITemplate toEntity() {
UITemplate uiTemplate = new UITemplate();
uiTemplate.setConfiguration(this.getConfiguration());
return uiTemplate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,22 @@
import lombok.Getter;
import lombok.Setter;
import org.apache.skywalking.oap.server.core.management.ui.template.UITemplate;
import org.apache.skywalking.oap.server.core.query.enumeration.TemplateType;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;

@Setter
@Getter
public class DashboardConfiguration {
private String name;
private TemplateType type;
private String id;
/**
* Configuration in JSON format.
*/
private String configuration;
private boolean activated;
private boolean disabled;

public DashboardConfiguration fromEntity(UITemplate templateEntity) {
this.setName(templateEntity.getName());
this.setType(TemplateType.forName(templateEntity.getType()));
this.setId(templateEntity.getTemplateId());
this.setConfiguration(templateEntity.getConfiguration());
this.setActivated(BooleanUtils.valueToBoolean(templateEntity.getActivated()));
this.setDisabled(BooleanUtils.valueToBoolean(templateEntity.getDisabled()));

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@Getter
@Builder
public class TemplateChangeStatus {
private String id;
private boolean status;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
* UI Template management, including CRUD.
*/
public interface UITemplateManagementDAO extends DAO {
DashboardConfiguration getTemplate(String id) throws IOException;

List<DashboardConfiguration> getAllTemplates(Boolean includingDisabled) throws IOException;

TemplateChangeStatus addTemplate(DashboardSetting setting) throws IOException;

TemplateChangeStatus changeTemplate(DashboardSetting setting) throws IOException;

TemplateChangeStatus disableTemplate(String name) throws IOException;
TemplateChangeStatus disableTemplate(String id) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,12 @@

package org.apache.skywalking.oap.server.core.management.ui.template;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.apache.skywalking.oap.server.library.util.ResourceUtils;
import org.junit.Assert;
import org.junit.Test;

public class UITemplateInitializerTest {
@Test
public void testReadFile() throws FileNotFoundException {
final File[] templateFiles = ResourceUtils.getPathFiles("test-ui-templates");
final List<UITemplate> uiTemplates = new ArrayList<>();
for (final File templateFile : templateFiles) {
UITemplateInitializer initializer = new UITemplateInitializer(
new FileInputStream(templateFile));
uiTemplates.addAll(initializer.read());
}

Assert.assertEquals(2, uiTemplates.size());
UITemplate uiTemplate = uiTemplates.get(0);
Assert.assertEquals("APM (Agent based)", uiTemplate.getName());
Assert.assertTrue(uiTemplate.getConfiguration().length() > 0);
Assert.assertEquals(BooleanUtils.TRUE, uiTemplate.getActivated());
Assert.assertEquals(BooleanUtils.FALSE, uiTemplate.getDisabled());

uiTemplate = uiTemplates.get(1);
Assert.assertEquals("APM (Service Mesh)", uiTemplate.getName());
Assert.assertTrue(uiTemplate.getConfiguration().length() > 0);
Assert.assertEquals(BooleanUtils.FALSE, uiTemplate.getActivated());
Assert.assertEquals(BooleanUtils.TRUE, uiTemplate.getDisabled());
//Todo: implement later when new template file ready
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,23 @@

package org.apache.skywalking.oap.server.core.management.ui.template;

import org.apache.skywalking.oap.server.core.query.enumeration.TemplateType;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
import org.junit.Assert;
import org.junit.Test;

public class UITemplateTest {
@Test
public void testSerialization() {
UITemplate uiTemplate = new UITemplate();
uiTemplate.setName("name");
uiTemplate.setTemplateId("id");
uiTemplate.setConfiguration("configuration");
uiTemplate.setType(TemplateType.DASHBOARD.name());
uiTemplate.setActivated(BooleanUtils.TRUE);
uiTemplate.setDisabled(BooleanUtils.FALSE);

final UITemplate.Builder builder = new UITemplate.Builder();
final UITemplate uiTemplate2 = builder.storage2Entity(builder.entity2Storage(uiTemplate));

Assert.assertEquals(uiTemplate, uiTemplate2);

uiTemplate2.setConfiguration("configuration2");
uiTemplate.setType(TemplateType.TOPOLOGY_ENDPOINT.name());
uiTemplate.setActivated(BooleanUtils.FALSE);
uiTemplate.setDisabled(BooleanUtils.TRUE);
// Equals method is only for `name` field.
// Equals method is only for `templateId` field.
Assert.assertEquals(uiTemplate, uiTemplate2);
}
}
Loading

0 comments on commit f3743ee

Please sign in to comment.