Skip to content

Commit

Permalink
add DashboardConfig for fix dashboard-ui 404
Browse files Browse the repository at this point in the history
add ServiceRegistry.setMetadata api
add ServiceRegistry.removeService api
add ServiceStatistic.getInstanceCount api
add Config/Service/Namespace Management (Dashboard-UI)
  • Loading branch information
Ahoo-Wang committed May 14, 2021
1 parent 0ba8ece commit 01d670b
Show file tree
Hide file tree
Showing 29 changed files with 275 additions and 43 deletions.
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ process cache refresh, with unparalleled QPS performance and real-time consisten
> Kotlin DSL
``` kotlin
val governVersion = "0.9.2";
val governVersion = "0.9.3";
implementation("me.ahoo.govern:spring-cloud-starter-config:${governVersion}")
implementation("me.ahoo.govern:spring-cloud-starter-discovery:${governVersion}")
```
Expand All @@ -32,7 +32,7 @@ process cache refresh, with unparalleled QPS performance and real-time consisten
<modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<govern.version>0.9.2</govern.version>
<govern.version>0.9.3</govern.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -67,29 +67,38 @@ spring:
url: redis://localhost:6379
```
## Dashboard (beta)
## REST-API Server (``Optional``)
```shell
bin/rest-api
```

> http://localhost:8080/
### Dashboard

### Namespace
![dashboard-dashboard](./docs/dashboard-dashboard.png)

#### Namespace

![dashboard-namespace](./docs/dashboard-namespace.png)

### Config
#### Config

![dashboard-config](./docs/dashboard-config.png)
![dashboard-config-edit](./docs/dashboard-config-edit.png)
![dashboard-config-rollback](./docs/dashboard-config-rollback.png)

### Service
#### Service

![dashboard-service](./docs/dashboard-service.png)
![dashboard-service-edit](./docs/dashboard-service-edit.png)

## REST-API Server (``Optional``)
```shell
bin/rest-api
```
### REST-API

> http://localhost:8080/swagger-ui/index.html#/
### Namespace
##### Namespace

![rest-api-namespace](./docs/rest-api-namespace.png)

Expand All @@ -103,7 +112,7 @@ bin/rest-api
- /v1/namespaces/current/{namespace}
- PUT

### Config
##### Config

![rest-api-config](./docs/rest-api-config.png)

Expand All @@ -120,7 +129,7 @@ bin/rest-api
- /v1/namespaces/{namespace}/configs/{configId}/to/{targetVersion}
- PUT

### Service
#### Service

![rest-api-service](./docs/rest-api-service.png)

Expand All @@ -133,7 +142,7 @@ bin/rest-api
- DELETE
- /v1/namespaces/{namespace}/services/{serviceId}/instances/{instanceId}/metadata
- PUT
- /v1/namespaces/{namespace}/services/lb/{serviceId}
- /v1/namespaces/{namespace}/services/{serviceId}/lb
- GET

## JMH Benchmark
Expand Down Expand Up @@ -192,6 +201,5 @@ RedisServiceRegistryBenchmark.renew thrpt 67116.1

## TODO

1. Dashboard
2. Import/Export API
3. Grayscale Publishing
1. Import/Export API
2. Grayscale Publishing
53 changes: 39 additions & 14 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Govern Service* 提供了超高TPS&QPS。*Govern Service* 结合本地进程缓
> Kotlin DSL
``` kotlin
val governVersion = "0.9.2";
val governVersion = "0.9.3";
implementation("me.ahoo.govern:spring-cloud-starter-config:${governVersion}")
implementation("me.ahoo.govern:spring-cloud-starter-discovery:${governVersion}")
```
Expand All @@ -27,7 +27,7 @@ Govern Service* 提供了超高TPS&QPS。*Govern Service* 结合本地进程缓
<modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<govern.version>0.9.2</govern.version>
<govern.version>0.9.3</govern.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -62,29 +62,38 @@ spring:
url: redis://localhost:6379
```
## 管理平台 (beta)
## REST-API Server (``Optional``)
```shell
bin/rest-api
```

> http://localhost:8080/
### Dashboard

### 命名空间管理
![dashboard-dashboard](./docs/dashboard-dashboard.png)

#### 命名空间管理

![dashboard-namespace](./docs/dashboard-namespace.png)

### 配置管理
#### 配置管理

![dashboard-config](./docs/dashboard-config.png)
![dashboard-config-edit](./docs/dashboard-config-edit.png)
![dashboard-config-rollback](./docs/dashboard-config-rollback.png)

### 服务管理
#### 服务管理

![dashboard-service](./docs/dashboard-service.png)
![dashboard-service-edit](./docs/dashboard-service-edit.png)

## REST-API Server (``Optional``)
```shell
bin/rest-api
```
### REST-API

> http://localhost:8080/swagger-ui/index.html#/
### Namespace
##### Namespace

![rest-api-namespace](./docs/rest-api-namespace.png)

Expand All @@ -98,7 +107,7 @@ bin/rest-api
- /v1/namespaces/current/{namespace}
- PUT

### Config
##### Config

![rest-api-config](./docs/rest-api-config.png)

Expand All @@ -115,6 +124,22 @@ bin/rest-api
- /v1/namespaces/{namespace}/configs/{configId}/to/{targetVersion}
- PUT

#### Service

![rest-api-service](./docs/rest-api-service.png)

- /v1/namespaces/{namespace}/services/
- GET
- /v1/namespaces/{namespace}/services/{serviceId}/instances
- GET
- PUT
- /v1/namespaces/{namespace}/services/{serviceId}/instances/{instanceId}
- DELETE
- /v1/namespaces/{namespace}/services/{serviceId}/instances/{instanceId}/metadata
- PUT
- /v1/namespaces/{namespace}/services/{serviceId}/lb
- GET

### Service

![rest-api-service](./docs/rest-api-service.png)
Expand Down Expand Up @@ -187,5 +212,5 @@ RedisServiceRegistryBenchmark.renew thrpt 67116.1

## TODO

1. Dashboard
1. Import/Export API
2. Grayscale Publishing
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static URI getUri(Instance instance) {
return URI.create(uri);
}

public URI getUri() {
public URI parseUri() {
return getUri(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static Map<String, String> encode(ServiceInstance serviceInstance) {

public static String[] encodeMetadata(String[] preArgs, Map<String, String> instanceMetadata) {
if (instanceMetadata.isEmpty()) {
return EMPTY_STRING_ARRAY;
return preArgs;
}
String[] values = new String[preArgs.length + instanceMetadata.size() * 2];
System.arraycopy(preArgs, 0, values, 0, preArgs.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*/
public interface ServiceRegistry {


CompletableFuture<Boolean> setService(String namespace, String serviceId);

CompletableFuture<Boolean> removeService(String namespace, String serviceId);

/**
* 注册实例
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface ServiceStatistic {
CompletableFuture<Void> statService(String namespace, @Nullable String serviceId);

CompletableFuture<List<ServiceStat>> getServiceStats(String namespace);

CompletableFuture<Long> getInstanceCount(String namespace);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public final class DiscoveryRedisScripts {
public static final String REGISTRY_DEREGISTER = "registry_deregister.lua";
public static final String REGISTRY_RENEW = "registry_renew.lua";
public static final String REGISTRY_SET_METADATA = "registry_set_metadata.lua";
public static final String REGISTRY_SET_SERVICE = "registry_set_service.lua";
public static final String REGISTRY_REMOVE_SERVICE = "registry_remove_service.lua";
public static final String DISCOVERY_GET_INSTANCES = "discovery_get_instances.lua";
public static final String DISCOVERY_GET_INSTANCE = "discovery_get_instance.lua";
public static final String DISCOVERY_GET_INSTANCE_TTL = "discovery_get_instance_ttl.lua";
public static final String INSTANCE_COUNT_STAT = "instance_count_stat.lua";
public static final String SERVICE_STAT = "service_stat.lua";

public static CompletableFuture<String> loadRegistryRegister(RedisScriptingAsyncCommands<String, String> scriptingCommands) {
Expand All @@ -34,6 +37,14 @@ public static CompletableFuture<String> loadRegistrySetMetadata(RedisScriptingAs
return RedisScripts.loadScript(REGISTRY_SET_METADATA, scriptingCommands);
}

public static CompletableFuture<String> loadRegistrySetService(RedisScriptingAsyncCommands<String, String> scriptingCommands) {
return RedisScripts.loadScript(REGISTRY_SET_SERVICE, scriptingCommands);
}

public static CompletableFuture<String> loadRegistryRemoveService(RedisScriptingAsyncCommands<String, String> scriptingCommands) {
return RedisScripts.loadScript(REGISTRY_REMOVE_SERVICE, scriptingCommands);
}

public static CompletableFuture<String> loadDiscoveryGetInstances(RedisScriptingAsyncCommands<String, String> scriptingCommands) {
return RedisScripts.loadScript(DISCOVERY_GET_INSTANCES, scriptingCommands);
}
Expand All @@ -49,4 +60,8 @@ public static CompletableFuture<String> loadDiscoveryGetInstanceTtl(RedisScripti
public static CompletableFuture<String> loadServiceStat(RedisScriptingAsyncCommands<String, String> scriptingCommands) {
return RedisScripts.loadScript(SERVICE_STAT, scriptingCommands);
}

public static CompletableFuture<String> loadInstanceCountStat(RedisScriptingAsyncCommands<String, String> scriptingCommands) {
return RedisScripts.loadScript(INSTANCE_COUNT_STAT, scriptingCommands);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ private CompletableFuture<Boolean> register0(String namespace, String scriptSha,
return redisFuture.toCompletableFuture();
}

@Override
public CompletableFuture<Boolean> setService(String namespace, String serviceId) {
if (log.isInfoEnabled()) {
log.info("setService - serviceId:[{}] @ namespace:[{}].", serviceId, namespace);
}

return DiscoveryRedisScripts.loadRegistrySetService(redisCommands)
.thenCompose(sha -> redisCommands.evalsha(sha, ScriptOutputType.BOOLEAN, new String[]{namespace}, serviceId));

}

@Override
public CompletableFuture<Boolean> removeService(String namespace, String serviceId) {
if (log.isInfoEnabled()) {
log.info("removeService - serviceId:[{}] @ namespace:[{}].", serviceId, namespace);
}

return DiscoveryRedisScripts.loadRegistryRemoveService(redisCommands)
.thenCompose(sha -> redisCommands.evalsha(sha, ScriptOutputType.BOOLEAN, new String[]{namespace}, serviceId));
}

/**
* @param serviceInstance 服务实例
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public CompletableFuture<List<ServiceStat>> getServiceStats(String namespace) {
}).collect(Collectors.toList())).toCompletableFuture();
}

@Override
public CompletableFuture<Long> getInstanceCount(String namespace) {
return DiscoveryRedisScripts.loadInstanceCountStat(redisCommands).
thenCompose(sha -> redisCommands.evalsha(sha, ScriptOutputType.INTEGER, namespace));
}

private class InstanceListener implements MessageListener {

@Override
Expand Down
22 changes: 22 additions & 0 deletions discovery/src/main/resources/instance_count_stat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local namespace = KEYS[1];
local serviceIdxKey = namespace .. ":svc_idx";

local instanceCount = 0;

local function getInstanceIdxKey(serviceId)
return namespace .. ":svc_itc_idx:" .. serviceId;
end

local function statInstance(serviceId)
local instanceIdxKey = getInstanceIdxKey(serviceId);
local servicedInstanceCount = redis.call("scard", instanceIdxKey);
instanceCount = instanceCount + servicedInstanceCount;
end

local serviceIds = redis.call("smembers", serviceIdxKey);

for index, serviceId in ipairs(serviceIds) do
statInstance(serviceId)
end

return instanceCount;
19 changes: 19 additions & 0 deletions discovery/src/main/resources/registry_remove_service.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local namespace = KEYS[1];
local serviceId = ARGV[1];

local serviceIdxKey = namespace .. ":svc_idx";
local serviceIdxStatKey = namespace .. ":svc_stat";
local instanceIdxKey = namespace .. ":svc_itc_idx:" .. serviceId;

local instanceCount = redis.call("scard", instanceIdxKey);
if instanceCount > 0 then
return 0;
end

local affected = redis.call("srem", serviceIdxKey, serviceId);

if affected > 0 then
redis.call("hdel", serviceIdxStatKey, serviceId);
end

return affected;
13 changes: 13 additions & 0 deletions discovery/src/main/resources/registry_set_service.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local namespace = KEYS[1];
local serviceId = ARGV[1];

local serviceIdxKey = namespace .. ":svc_idx";
local serviceIdxStatKey = namespace .. ":svc_stat";

local affected = redis.call("sadd", serviceIdxKey, serviceId);

if affected > 0 then
redis.call("hset", serviceIdxStatKey, serviceId, 0);
end

return affected;
2 changes: 1 addition & 1 deletion docker/rest-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# docker build --build-arg JDK_VERSION=armv7l-centos-jdk-11.0.8_10-slim --build-arg GOVERN_VERSION=0.7.2 -t ahoowang/govern-service:0.7.2 .
ARG JDK_VERSION=alpine
ARG GOVERN_VERSION=0.9.2
ARG GOVERN_VERSION=0.9.3
ARG GOVERN_SERVICE_HOME=/govern-service
FROM adoptopenjdk/openjdk11:${JDK_VERSION} AS base

Expand Down
Binary file added docs/dashboard-config-edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/dashboard-config-rollback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dashboard-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/dashboard-dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dashboard-namespace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/dashboard-service-edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dashboard-service.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/rest-api-service.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=me.ahoo.govern
version=0.9.2
version=0.9.3

description=Govern Service On Redis
website=https://github.com/Ahoo-Wang/govern-service
Expand Down
Loading

0 comments on commit 01d670b

Please sign in to comment.