Skip to content

Commit

Permalink
optimized arklet healthService
Browse files Browse the repository at this point in the history
update README.md
  • Loading branch information
ColdClear committed Sep 9, 2023
1 parent 20b639a commit 8eac006
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 29 deletions.
245 changes: 244 additions & 1 deletion arklet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,247 @@ The http protocol is enabled and the default port is 1238
}
]
}
```
```

## Query Health
- URL: 127.0.0.1:1238/health

### Query All Health Info
- input sample:
```json
{}
```
- output sample:
```json
{
"code": "SUCCESS",
"data": {
"healthData": {
"jvm": {
"max non heap memory(M)": -9.5367431640625E-7,
"java version": "1.8.0_331",
"max memory(M)": 885.5,
"max heap memory(M)": 885.5,
"used heap memory(M)": 137.14127349853516,
"used non heap memory(M)": 62.54662322998047,
"loaded class count": 10063,
"init non heap memory(M)": 2.4375,
"total memory(M)": 174.5,
"free memory(M)": 37.358726501464844,
"unload class count": 0,
"total class count": 10063,
"committed heap memory(M)": 174.5,
"java home": "****\\jre",
"init heap memory(M)": 64.0,
"committed non heap memory(M)": 66.203125,
"run time(s)": 34.432
},
"cpu": {
"count": 4,
"total used (%)": 131749.0,
"type": "****",
"user used (%)": 9.926451054656962,
"free (%)": 81.46475495070172,
"system used (%)": 6.249762806548817
},
"masterBizInfo": {
"webContextPath": "/",
"bizName": "bookstore-manager",
"bizState": "ACTIVATED",
"bizVersion": "1.0.0"
},
"pluginListInfo": [
{
"artifactId": "web-ark-plugin",
"groupId": "com.alipay.sofa",
"pluginActivator": "com.alipay.sofa.ark.web.embed.WebPluginActivator",
"pluginName": "web-ark-plugin",
"pluginUrl": "file:/****/2.2.3-SNAPSHOT/web-ark-plugin-2.2.3-20230901.090402-2.jar!/",
"pluginVersion": "2.2.3-SNAPSHOT"
},
{
"artifactId": "runtime-sofa-boot-plugin",
"groupId": "com.alipay.sofa",
"pluginActivator": "com.alipay.sofa.runtime.ark.plugin.SofaRuntimeActivator",
"pluginName": "runtime-sofa-boot-plugin",
"pluginUrl": "file:/****/runtime-sofa-boot-plugin-3.11.0.jar!/",
"pluginVersion": "3.11.0"
}
],
"masterBizHealth": {
"readinessState": "ACCEPTING_TRAFFIC"
},
"bizListInfo": [
{
"bizName": "bookstore-manager",
"bizState": "ACTIVATED",
"bizVersion": "1.0.0",
"webContextPath": "/"
}
]
}
}
}
```

### Query System Health Info
- input sample:

```json
{
"type": "system",
// [OPTIONAL] if metrics is null -> query all system health info
"metrics": ["cpu", "jvm"]
}
```
- output sample:
```json
{
"code": "SUCCESS",
"data": {
"healthData": {
"jvm": {...},
"cpu": {...},
// "masterBizHealth": {...}
}
}
}
```

### Query Biz Health Info
- input sample:

```json
{
"type": "biz",
// [OPTIONAL] if moduleName is null and moduleVersion is null -> query all biz
"moduleName": "bookstore-manager",
// [OPTIONAL] if moduleVersion is null -> query all biz named moduleName
"moduleVersion": "1.0.0"
}
```
- output sample:
```json
{
"code": "SUCCESS",
"data": {
"healthData": {
"bizInfo": {
"bizName": "bookstore-manager",
"bizState": "ACTIVATED",
"bizVersion": "1.0.0",
"webContextPath": "/"
}
// "bizListInfo": [
// {
// "bizName": "bookstore-manager",
// "bizState": "ACTIVATED",
// "bizVersion": "1.0.0",
// "webContextPath": "/"
// }
// ]
}
}
}
```

### Query Plugin Health Info
- input sample:

```json
{
"type": "plugin",
// [OPTIONAL] if moduleName is null -> query all biz
"moduleName": "web-ark-plugin"
}
```
- output sample:
```json
{
"code": "SUCCESS",
"data": {
"healthData": {
"pluginListInfo": [
{
"artifactId": "web-ark-plugin",
"groupId": "com.alipay.sofa",
"pluginActivator": "com.alipay.sofa.ark.web.embed.WebPluginActivator",
"pluginName": "web-ark-plugin",
"pluginUrl": "file:/****/web-ark-plugin-2.2.3-20230901.090402-2.jar!/",
"pluginVersion": "2.2.3-SNAPSHOT"
}
]
}
}
}
```

### Query Health Using Endpoint

use endpoint for k8s module to get helath info

**default config**
* endpoints exposure include: `*`
* endpoints base path: `/`
* endpoints sever port: `8080`

**http code result**
* `HEALTHY(200)`: get health if all health indicator is healthy
* `UNHEALTHY(400)`: get health once a health indicator is unhealthy
* `ENDPOINT_NOT_FOUND(404)`: endpoint path or params not found
* `ENDPOINT_PROCESS_INTERNAL_ERROR(500)`: get health process throw an error

### query all health info
- url: 127.0.0.1:8080/arkletHealth
- method: GET
- output sample

```json
{
"healthy": true,
"code": 200,
"codeType": "HEALTHY",
"data": {
"jvm": {...},
"masterBizHealth": {...},
"cpu": {...},
"masterBizInfo": {...},
"bizListInfo": [...],
"pluginListInfo": [...]
}
}
```
### query all biz/plugin health info
- url: 127.0.0.1:8080/arkletHealth/{moduleType} (moduleType must in ['biz', 'plugin'])
- method: GET
- output sample
```json
{
"healthy": true,
"code": 200,
"codeType": "HEALTHY",
"data": {
"bizListInfo": [...],
// "pluginListInfo": [...]
}
}
```
### query single biz/plugin health info
- url: 127.0.0.1:8080/arkletHealth/{moduleType}/moduleName/moduleVersion (moduleType must in ['biz', 'plugin'])
- method: GET
- output sample

```json
{
"healthy": true,
"code": 200,
"codeType": "HEALTHY",
"data": {
"bizInfo": {...},
// "pluginInfo": {...}
}
}
```



Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ public void destroy() {

@Override
public Health getHealth() {
healthBuilder.init();
HealthBuilder builder = new HealthBuilder();
for (ArkletBaseIndicator indicator : this.indicators.values()) {
healthBuilder.putAllHealthData(indicator.getHealthModel(new HealthBuilder()));
builder.putAllHealthData(indicator.getHealthModel(healthBuilder));
}
return healthBuilder.build();
return builder.build();
}

@Override
public Health getHealth(String indicatorId) {
try {
healthBuilder.init();
AssertUtils.assertNotNull(indicators.get(indicatorId), "indicator not registered");
healthBuilder.putAllHealthData(indicators.get(indicatorId).getHealthModel(
new HealthBuilder()));
healthBuilder.putAllHealthData(indicators.get(indicatorId)
.getHealthModel(healthBuilder));
} catch (Throwable e) {
healthBuilder.putErrorData(Constants.HEALTH_ERROR, e.getMessage());
}
Expand All @@ -89,15 +89,15 @@ public Health getHealth(String indicatorId) {

@Override
public Health getHealth(String[] indicatorIds) {
healthBuilder.init();
HealthBuilder builder = new HealthBuilder();
if (ArrayUtil.isEmpty(indicatorIds)) {
healthBuilder.putAllHealthData(getHealth());
builder.putAllHealthData(getHealth());
} else {
for (String indicatorId : indicatorIds) {
healthBuilder.putAllHealthData(getHealth(indicatorId));
builder.putAllHealthData(getHealth(indicatorId));
}
}
return healthBuilder.build();
return builder.build();
}

@Override
Expand All @@ -110,26 +110,26 @@ public Health queryModuleInfo() {

@Override
public Health queryModuleInfo(String type, String name, String version) {
healthBuilder.init();
HealthBuilder builder = new HealthBuilder();
try {
AssertUtils.isTrue(StringUtils.isEmpty(type) || Constants.typeOfInfo(type),
"illegal type: %s", type);
if (StringUtils.isEmpty(type) || Constants.BIZ.equals(type)) {
BizModel bizModel = new BizModel();
bizModel.setBizName(name);
bizModel.setBizVersion(version);
healthBuilder.putAllHealthData(queryModuleInfo(bizModel));
builder.putAllHealthData(queryModuleInfo(bizModel));
}
if (StringUtils.isEmpty(type) || Constants.PLUGIN.equals(type)) {
PluginModel pluginModel = new PluginModel();
pluginModel.setPluginName(name);
pluginModel.setPluginVersion(version);
healthBuilder.putAllHealthData(queryModuleInfo(pluginModel));
builder.putAllHealthData(queryModuleInfo(pluginModel));
}
} catch (Throwable e) {
healthBuilder.putErrorData(Constants.HEALTH_ERROR, e.getMessage());
builder.putErrorData(Constants.HEALTH_ERROR, e.getMessage());
}
return healthBuilder.build();
return builder.build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alipay.sofa.serverless.arklet.core.health.model.Constants;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.util.GlobalConfig;
import oshi.util.Util;

import java.util.HashMap;
Expand Down Expand Up @@ -66,10 +67,10 @@ static class CpuIndicatorHandler {

public CpuIndicatorHandler() {
this.cpu = new SystemInfo().getHardware().getProcessor();
prevTicks = cpu.getSystemCpuLoadTicks();
}

public void collectTicks() {
prevTicks = cpu.getSystemCpuLoadTicks();
nextTicks = cpu.getSystemCpuLoadTicks();
}

Expand Down
Loading

0 comments on commit 8eac006

Please sign in to comment.