Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalized hostname by concatenating scenarioName with index number #1209

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 10-task/dubbo-samples-benchmark/case-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:

bh-mysql:
image: mysql:5.7
hostname: bh-mysql
hostname: dubbo-samples-benchmark-mysql
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_DATABASE=skywalking
Expand All @@ -38,18 +38,18 @@ services:

skywalking:
image: apache/skywalking-oap-server:9.3.0
hostname: skywalking
hostname: dubbo-samples-benchmark-skywalking
ports:
- 11800:11800
volumes:
- /tmp/mysql-connector-java-8.0.23.jar:/skywalking/oap-libs/mysql-connector-java-8.0.23.jar
environment:
- SW_STORAGE=mysql
- SW_JDBC_URL=jdbc:mysql://bh-mysql:3306/skywalking?useSSL=false
- SW_JDBC_URL=jdbc:mysql://dubbo-samples-benchmark-mysql:3306/skywalking?useSSL=false
- SW_DATA_SOURCE_USER=root
- SW_DATA_SOURCE_PASSWORD=123456
waitPortsBeforeRun:
- bh-mysql:3306
- dubbo-samples-benchmark-mysql:3306
depends_on:
- bh-mysql

Expand All @@ -75,12 +75,12 @@ services:
systemProps:
- zookeeper.address=zookeeper
- skywalking.agent.service_name=dubbo-samples-benchmark-consumer
- skywalking.collector.backend_service=skywalking:11800
- skywalking.collector.backend_service=dubbo-samples-benchmark-skywalking:11800
volumes:
- /tmp:/tmp
waitPortsBeforeRun:
- zookeeper:2181
- provider:20880
- skywalking:11800
- dubbo-samples-benchmark-skywalking:11800
depends_on:
- provider
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ services:
- 8090
environment:
- APOLLO_SERVICE=1
- DB_ADDRESS=apollo-db:3306
- DB_ADDRESS=dubbo-samples-configcenter-apollo-db:3306
volumes:
- ${_basedir}/src/main/resources/docker/demo.sh:/apollo-quick-start/demo.sh
- ./logs:/apollo-quick-start/logs
Expand All @@ -81,6 +81,7 @@ services:

apollo-db:
image: mysql:5.7
hostname: dubbo-samples-configcenter-apollo-db
environment:
- TZ=Asia/Shanghai
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public ConfigurationImpl() throws IOException, ConfigureFileNotFoundException {
}
}

this.configuration = loadCaseConfiguration(configureFile);
this.configuration = loadCaseConfiguration(configureFile, scenarioName);

//set scenario timeout
if (this.configuration.getTimeout() > 0) {
Expand Down Expand Up @@ -163,7 +163,7 @@ private boolean isDebug() {
return debugPatterns != null && debugPatterns.size() > 0;
}

private CaseConfiguration loadCaseConfiguration(String configureFile) throws IOException {
private CaseConfiguration loadCaseConfiguration(String configureFile, String scenarioName) throws IOException {
// read 'props'
String configYaml = FileUtil.readFully(configureFile);
CaseConfiguration tmpConfiguration = parseConfiguration(configYaml);
Expand Down Expand Up @@ -210,7 +210,7 @@ private CaseConfiguration loadCaseConfiguration(String configureFile) throws IOE
caseConfiguration.setServices(newServices);
}

fillupServices(caseConfiguration);
fillupServices(caseConfiguration, scenarioName);
return caseConfiguration;
}

Expand Down Expand Up @@ -252,12 +252,26 @@ private CaseConfiguration parseConfiguration(String configYaml) {
return new Yaml().loadAs(configYaml, CaseConfiguration.class);
}

private void fillupServices(CaseConfiguration caseConfiguration) throws IOException {
private void fillupServices(CaseConfiguration caseConfiguration, String scenarioName) throws IOException {
List<String> caseSystemProps = caseConfiguration.getSystemProps();
int index = 0;
//normalize hostname by concatenating scenarioName with index number, hostname length should less than 64.
Map<String, String> hostnameMap = new HashMap<>();
for (String serviceName : caseConfiguration.getServices().keySet()) {
hostnameMap.put(serviceName, scenarioName + index++);
}
index = 0;
for (Map.Entry<String, ServiceComponent> entry : caseConfiguration.getServices().entrySet()) {
String serviceName = entry.getKey();
ServiceComponent service = entry.getValue();

String originalHostname = service.getHostname();
String normalizedHostname = hostnameMap.get(serviceName);
if (StringUtils.isBlank(originalHostname) || originalHostname.equals(serviceName)) {
//set normalized hostname if absent, or replace by normalized hostname if original equal serviceName.
service.setHostname(normalizedHostname);
}

String type = service.getType();
if (isAppOrTestService(type)) {
service.setImage(SAMPLE_TEST_IMAGE + ":" + testImageVersion);
Expand All @@ -280,7 +294,7 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept

//set wait ports
if (isNotEmpty(service.getWaitPortsBeforeRun())) {
String str = convertAddrPortsToString(service.getWaitPortsBeforeRun());
String str = convertAddrPortsToString(service.getWaitPortsBeforeRun(), hostnameMap);
setEnv(service, ENV_WAIT_PORTS_BEFORE_RUN, str);
}

Expand Down Expand Up @@ -351,7 +365,7 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
//set check ports
if (isNotEmpty(service.getCheckPorts())) {
addHealthcheck = true;
String str = convertAddrPortsToString(service.getCheckPorts());
String str = convertAddrPortsToString(service.getCheckPorts(), hostnameMap);
setEnv(service, ENV_CHECK_PORTS, str);
}

Expand Down Expand Up @@ -395,7 +409,7 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept

//set wait ports
if (isNotEmpty(service.getWaitPortsBeforeRun())) {
String str = convertAddrPortsToString(service.getWaitPortsBeforeRun());
String str = convertAddrPortsToString(service.getWaitPortsBeforeRun(), hostnameMap);
setEnv(service, ENV_WAIT_PORTS_BEFORE_RUN, str);
}

Expand Down Expand Up @@ -423,7 +437,7 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
//set check ports
if (isNotEmpty(service.getCheckPorts())) {
addHealthcheck = true;
String str = convertAddrPortsToString(service.getCheckPorts());
String str = convertAddrPortsToString(service.getCheckPorts(), hostnameMap);
setEnv(service, ENV_CHECK_PORTS, str);
}

Expand All @@ -434,17 +448,33 @@ private void fillupServices(CaseConfiguration caseConfiguration) throws IOExcept
}
}

// set hostname to serviceId if absent
if (StringUtils.isBlank(service.getHostname())) {
service.setHostname(serviceName);
}

//set jvmFlags
if (isNotEmpty(service.getJvmFlags())) {
String str = StringUtils.join(service.getJvmFlags(), ' ');
appendEnv(service, ENV_JAVA_OPTS, str);
}

//revise service hostname properties
List<String> serviceSystemProps = service.getSystemProps();
if (serviceSystemProps != null) {
List<String> revisedServiceSystemProps = new ArrayList<>();
serviceSystemProps.forEach(serviceProp -> {
String[] strs = serviceProp.split("=");
if (strs.length == 2) {
String hostname = hostnameMap.get(strs[1]);
if (null != hostname) {
//use normalized hostname instead.
revisedServiceSystemProps.add(strs[0] + "=" + hostname);
} else {
revisedServiceSystemProps.add(serviceProp);
}
} else {
revisedServiceSystemProps.add(serviceProp);
}
});
service.setSystemProps(revisedServiceSystemProps);
}

//set systemProps
List<String> systemProps = mergeSystemProps(caseSystemProps, service.getSystemProps());
if (isNotEmpty(systemProps)) {
Expand Down Expand Up @@ -526,13 +556,23 @@ private boolean isNotEmpty(List<String> list) {
return list != null && list.size() > 0;
}

private String convertAddrPortsToString(List<String> addrPorts) {
private String convertAddrPortsToString(List<String> addrPorts, Map<String, String> hostnameMap) {
StringBuilder sb = new StringBuilder();
for (String addrPort : addrPorts) {
if (!addrPort.contains(":")) {
int idx = addrPort.indexOf(":");
if (idx > 0) {
String hostname = hostnameMap.get(addrPort.substring(0, idx));
if (null != hostname) {
//use normalized hostname instead.
sb.append(hostname).append(addrPort.substring(idx));
} else {
sb.append(addrPort);
}
} else {
addrPort = "127.0.0.1" + ":" + addrPort;
sb.append(addrPort);
}
sb.append(addrPort).append(";");
sb.append(";");
}
return sb.toString();
}
Expand Down
Loading