-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
534 additions
and
343 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...r-sentinel/src/main/java/com/alibaba/cloud/sentinel/endpoint/SentinelHealthIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.alibaba.cloud.sentinel.endpoint; | ||
|
||
import com.alibaba.cloud.sentinel.SentinelProperties; | ||
import com.alibaba.csp.sentinel.datasource.AbstractDataSource; | ||
import com.alibaba.csp.sentinel.heartbeat.HeartbeatSenderProvider; | ||
import com.alibaba.csp.sentinel.transport.HeartbeatSender; | ||
import com.alibaba.csp.sentinel.transport.config.TransportConfig; | ||
import com.alibaba.csp.sentinel.util.function.Tuple2; | ||
import org.springframework.beans.factory.support.DefaultListableBeanFactory; | ||
import org.springframework.boot.actuate.health.AbstractHealthIndicator; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.Status; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class SentinelHealthIndicator extends AbstractHealthIndicator { | ||
|
||
private DefaultListableBeanFactory beanFactory; | ||
|
||
private SentinelProperties sentinelProperties; | ||
|
||
public SentinelHealthIndicator(DefaultListableBeanFactory beanFactory, | ||
SentinelProperties sentinelProperties) { | ||
this.beanFactory = beanFactory; | ||
this.sentinelProperties = sentinelProperties; | ||
} | ||
|
||
@Override | ||
protected void doHealthCheck(Health.Builder builder) throws Exception { | ||
Map<String, Object> detailMap = new HashMap<>(); | ||
|
||
// If sentinel isn't enabled, set the status up and set the enabled to false in | ||
// detail | ||
if (!sentinelProperties.isEnabled()) { | ||
detailMap.put("enabled", false); | ||
builder.up().withDetails(detailMap); | ||
return; | ||
} | ||
|
||
detailMap.put("enabled", true); | ||
|
||
// Check health of Dashboard | ||
boolean dashboardUp = true; | ||
List<Tuple2<String, Integer>> consoleServer = TransportConfig.getConsoleServerList(); | ||
if (consoleServer == null) { | ||
// If Dashboard isn't configured, it's OK and mark the status of Dashboard | ||
// with UNKNOWN. | ||
detailMap.put("dashboard", | ||
new Status(Status.UNKNOWN.getCode(), "dashboard isn't configured")); | ||
} | ||
else { | ||
// If Dashboard is configured, send a heartbeat message to it and check the | ||
// result | ||
HeartbeatSender heartbeatSender = HeartbeatSenderProvider | ||
.getHeartbeatSender(); | ||
boolean result = heartbeatSender.sendHeartbeat(); | ||
if (result) { | ||
detailMap.put("dashboard", Status.UP); | ||
} | ||
else { | ||
// If failed to send heartbeat message, means that the Dashboard is DOWN | ||
dashboardUp = false; | ||
detailMap.put("dashboard", new Status(Status.DOWN.getCode(), | ||
consoleServer + " can't be connected")); | ||
} | ||
} | ||
|
||
// Check health of DataSource | ||
boolean dataSourceUp = true; | ||
Map<String, Object> dataSourceDetailMap = new HashMap<>(); | ||
detailMap.put("dataSource", dataSourceDetailMap); | ||
|
||
// Get all DataSources and each call loadConfig to check if it's OK | ||
// If no Exception thrown, it's OK | ||
// Note: | ||
// Even if the dynamic config center is down, the loadConfig() might return | ||
// successfully | ||
// e.g. for Nacos client, it might retrieve from the local cache) | ||
// But in most circumstances it's okay | ||
Map<String, AbstractDataSource> dataSourceMap = beanFactory | ||
.getBeansOfType(AbstractDataSource.class); | ||
for (Map.Entry<String, AbstractDataSource> dataSourceMapEntry : dataSourceMap | ||
.entrySet()) { | ||
String dataSourceBeanName = dataSourceMapEntry.getKey(); | ||
AbstractDataSource dataSource = dataSourceMapEntry.getValue(); | ||
try { | ||
dataSource.loadConfig(); | ||
dataSourceDetailMap.put(dataSourceBeanName, Status.UP); | ||
} | ||
catch (Exception e) { | ||
// If one DataSource failed to loadConfig, means that the DataSource is | ||
// DOWN | ||
dataSourceUp = false; | ||
dataSourceDetailMap.put(dataSourceBeanName, | ||
new Status(Status.DOWN.getCode(), e.getMessage())); | ||
} | ||
} | ||
|
||
// If Dashboard and DataSource are both OK, the health status is UP | ||
if (dashboardUp && dataSourceUp) { | ||
builder.up().withDetails(detailMap); | ||
} | ||
else { | ||
builder.down().withDetails(detailMap); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.