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

feat: address zone #849

Merged
merged 1 commit into from
May 9, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public class EnvironmentProperties {
private String userCenter;
private String location;
private String gptUrl;
private String zone;
}
5 changes: 5 additions & 0 deletions server/extension/extension-storage-ceresdbx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,10 @@
<artifactId>common-dao</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.holoinsight.server</groupId>
<artifactId>common-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.ceresdb.rpc.RpcOptions;
import io.ceresdb.rpc.RpcOptions.LimitKind;
import io.holoinsight.server.common.J;
import io.holoinsight.server.common.config.EnvironmentProperties;
import io.holoinsight.server.common.dao.entity.TenantOps;
import io.holoinsight.server.common.dao.mapper.TenantOpsMapper;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -38,10 +39,14 @@ public class CeresdbxClientManager {

private TenantOpsMapper tenantOpsMapper;

private EnvironmentProperties environmentProperties;

private Map<String, CeresDBxClientInstance> instances = new ConcurrentHashMap<>();

public CeresdbxClientManager(TenantOpsMapper tenantOpsMapper) {
public CeresdbxClientManager(TenantOpsMapper tenantOpsMapper,
EnvironmentProperties environmentProperties) {
this.tenantOpsMapper = tenantOpsMapper;
this.environmentProperties = environmentProperties;
}

@PostConstruct
Expand All @@ -65,7 +70,7 @@ public void refresh() {
String database = (String) ceresdbConfig.get("database");
Object portObj = ceresdbConfig.get("port");
int port = Double.valueOf(String.valueOf(portObj)).intValue();
String newConfigKey = configKey(address, port, accessUser, accessKey);
String newConfigKey = configKey(fixAddress(address), port, accessUser, accessKey);
CeresDBxClientInstance clientInstance = instances.get(tenant);
if (clientInstance == null
|| !StringUtils.equals(clientInstance.getConfigKey(), newConfigKey)) {
Expand All @@ -89,6 +94,15 @@ public void refresh() {
}
}

private String fixAddress(String address) {
if (StringUtils.indexOfIgnoreCase(address, "${zone}") != -1) {
String zoneAddress =
StringUtils.replaceIgnoreCase(address, "${zone}", this.environmentProperties.getZone());
return zoneAddress;
}
return address;
}

public CeresDBClient getClient(String tenant) {
if (StringUtils.isBlank(tenant)) {
tenant = "dev";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package io.holoinsight.server.extension.ceresdbx;

import io.holoinsight.server.common.config.EnvironmentProperties;
import io.holoinsight.server.common.dao.mapper.TenantOpsMapper;
import io.holoinsight.server.extension.MetricMeterService;
import io.holoinsight.server.extension.MetricStorage;
Expand All @@ -24,8 +25,9 @@
public class HoloinsightCeresdbxConfiguration {

@Bean
public CeresdbxClientManager ceresdbxClientManager(TenantOpsMapper tenantOpsMapper) {
return new CeresdbxClientManager(tenantOpsMapper);
public CeresdbxClientManager ceresdbxClientManager(TenantOpsMapper tenantOpsMapper,
EnvironmentProperties environmentProperties) {
return new CeresdbxClientManager(tenantOpsMapper, environmentProperties);
}

@Bean
Expand Down
Loading