Do first revision (review and refactoring) of Apache Geode's Actuator support and HealthIndicators in order to adapt to Spring Boot's new HealthContributor API.

This commit is contained in:
John Blum
2020-01-22 17:07:21 -08:00
parent 4e492ad089
commit 901fce5f7e
16 changed files with 51 additions and 45 deletions

View File

@@ -18,10 +18,8 @@ package org.springframework.geode.boot.actuate.autoconfigure;
import org.apache.geode.cache.GemFireCache;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -41,8 +39,10 @@ import org.springframework.geode.boot.autoconfigure.ClientCacheAutoConfiguration
* @see org.apache.geode.cache.GemFireCache
* @see org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator
* @see org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration
* @see org.springframework.boot.autoconfigure.EnableAutoConfiguration
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.context.annotation.Import
* @see org.springframework.data.gemfire.CacheFactoryBean
* @see org.springframework.geode.boot.actuate.autoconfigure.config.BaseGeodeHealthIndicatorConfiguration
* @see org.springframework.geode.boot.actuate.autoconfigure.config.ClientCacheHealthIndicatorConfiguration
* @see org.springframework.geode.boot.actuate.autoconfigure.config.PeerCacheHealthIndicatorConfiguration
@@ -51,7 +51,6 @@ import org.springframework.geode.boot.autoconfigure.ClientCacheAutoConfiguration
*/
@Configuration
@AutoConfigureAfter(ClientCacheAutoConfiguration.class)
@AutoConfigureBefore(HealthContributorAutoConfiguration.class)
@ConditionalOnBean(GemFireCache.class)
@ConditionalOnClass(CacheFactoryBean.class)
@ConditionalOnEnabledHealthIndicator("geode")

View File

@@ -13,12 +13,12 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.boot.actuate.autoconfigure.config;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

View File

@@ -13,12 +13,12 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.boot.actuate.autoconfigure.config;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.annotation.Bean;

View File

@@ -22,6 +22,7 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.cache.server.ServerLoadProbe;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.actuate.health.HealthIndicator;

View File

@@ -13,7 +13,6 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.boot.actuate;
import java.util.Collections;
@@ -23,6 +22,7 @@ import java.util.Set;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.gemfire.util.CacheUtils;
@@ -65,7 +65,7 @@ public class GeodeAsyncEventQueuesHealthIndicator extends AbstractGeodeHealthInd
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
if (getGemFireCache().filter(CacheUtils::isPeer).isPresent()) {

View File

@@ -23,6 +23,7 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.control.ResourceManager;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.DistributedSystem;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
@@ -90,7 +91,7 @@ public class GeodeCacheHealthIndicator extends AbstractGeodeHealthIndicator {
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
if (getGemFireCache().isPresent()) {

View File

@@ -25,6 +25,7 @@ import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.cache.server.ServerLoad;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.gemfire.util.CacheUtils;
@@ -69,7 +70,7 @@ public class GeodeCacheServersHealthIndicator extends AbstractGeodeHealthIndicat
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
if (getGemFireCache().filter(CacheUtils::isPeer).isPresent()) {

View File

@@ -27,6 +27,7 @@ import org.apache.geode.cache.query.CqStatistics;
import org.apache.geode.cache.query.Query;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.cache.query.QueryStatistics;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer;
@@ -102,14 +103,14 @@ public class GeodeContinuousQueriesHealthIndicator extends AbstractGeodeHealthIn
queryService
.map(QueryService::getCqStatistics)
.ifPresent(cqServiceStatistics -> {
.ifPresent(cqServiceStatistics ->
builder.withDetail("geode.continuous-query.number-of-active", cqServiceStatistics.numCqsActive())
.withDetail("geode.continuous-query.number-of-closed", cqServiceStatistics.numCqsClosed())
.withDetail("geode.continuous-query.number-of-created", cqServiceStatistics.numCqsCreated())
.withDetail("geode.continuous-query.number-of-stopped", cqServiceStatistics.numCqsStopped())
.withDetail("geode.continuous-query.number-on-client", cqServiceStatistics.numCqsOnClient());
});
.withDetail("geode.continuous-query.number-on-client", cqServiceStatistics.numCqsOnClient())
);
continuousQueries.stream()
.filter(Objects::nonNull)

View File

@@ -13,7 +13,6 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.boot.actuate;
import java.io.File;
@@ -22,7 +21,6 @@ import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.geode.cache.DiskStore;
@@ -88,7 +86,7 @@ public class GeodeDiskStoresHealthIndicator extends AbstractGeodeHealthIndicator
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
if (getApplicationContext().isPresent()) {
@@ -137,7 +135,7 @@ public class GeodeDiskStoresHealthIndicator extends AbstractGeodeHealthIndicator
return Arrays.toString(Arrays.stream(ArrayUtils.nullSafeArray(files, File.class))
.filter(Objects::nonNull)
.map(File::getAbsolutePath)
.collect(Collectors.toSet())
.distinct()
.toArray());
}
}

View File

@@ -13,7 +13,6 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.boot.actuate;
import java.util.Collections;
@@ -24,6 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.wan.GatewayReceiver;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.gemfire.util.CacheUtils;
@@ -66,7 +66,7 @@ public class GeodeGatewayReceiversHealthIndicator extends AbstractGeodeHealthInd
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
if (getGemFireCache().filter(CacheUtils::isPeer).isPresent()) {

View File

@@ -22,6 +22,7 @@ import java.util.Set;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.wan.GatewaySender;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.gemfire.util.CacheUtils;
@@ -65,7 +66,7 @@ public class GeodeGatewaySendersHealthIndicator extends AbstractGeodeHealthIndic
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
if (getGemFireCache().filter(CacheUtils::isPeer).isPresent()) {

View File

@@ -87,7 +87,7 @@ public class GeodeIndexesHealthIndicator extends AbstractGeodeHealthIndicator {
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
if (getApplicationContext().isPresent()) {
@@ -144,6 +144,7 @@ public class GeodeIndexesHealthIndicator extends AbstractGeodeHealthIndicator {
return String.format("geode.index.%1$s.statistics.%2$s", indexName, suffix);
}
@SuppressWarnings("rawtypes")
private String toRegionPath(Region region) {
String regionPath = region != null ? region.getFullPath() : null;

View File

@@ -13,7 +13,6 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.boot.actuate;
import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeList;
@@ -29,6 +28,7 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.gemfire.util.CacheUtils;
@@ -72,7 +72,7 @@ public class GeodePoolsHealthIndicator extends AbstractGeodeHealthIndicator {
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
protected void doHealthCheck(Health.Builder builder) {
if (getGemFireCache().filter(CacheUtils::isClient).isPresent()) {
@@ -106,8 +106,8 @@ public class GeodePoolsHealthIndicator extends AbstractGeodeHealthIndicator {
.withDetail(poolKey(poolName, "subscription-ack-interval"), pool.getSubscriptionAckInterval())
.withDetail(poolKey(poolName, "subscription-enabled"), toYesNoString(pool.getSubscriptionEnabled()))
.withDetail(poolKey(poolName, "subscription-message-tracking-timeout"), pool.getSubscriptionMessageTrackingTimeout())
.withDetail(poolKey(poolName, "subscription-redundancy"), pool.getSubscriptionRedundancy())
.withDetail(poolKey(poolName, "thread-local-connections"), toYesNoString(pool.getThreadLocalConnections()));
.withDetail(poolKey(poolName, "subscription-redundancy"), pool.getSubscriptionRedundancy());
//.withDetail(poolKey(poolName, "thread-local-connections"), toYesNoString(pool.getThreadLocalConnections()));
getGemFireCache()
.map(ClientCache.class::cast)

View File

@@ -30,6 +30,7 @@ import org.apache.geode.cache.PartitionAttributes;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.internal.cache.LocalDataSet;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.geode.boot.actuate.health.AbstractGeodeHealthIndicator;
@@ -160,7 +161,7 @@ public class GeodeRegionsHealthIndicator extends AbstractGeodeHealthIndicator {
builder.withDetail(cachePartitionRegionKey(regionName, "collocated-with"), emptyIfUnset(partitionAttributes.getColocatedWith()))
.withDetail(cachePartitionRegionKey(regionName, "local-max-memory"), partitionAttributes.getLocalMaxMemory())
.withDetail(cachePartitionRegionKey(regionName, "redundant-copies"), partitionAttributes.getRedundantCopies())
.withDetail(cachePartitionRegionKey(regionName, "total-max-memory"), partitionAttributes.getTotalMaxMemory())
//.withDetail(cachePartitionRegionKey(regionName, "total-max-memory"), partitionAttributes.getTotalMaxMemory())
.withDetail(cachePartitionRegionKey(regionName, "total-number-of-buckets"), partitionAttributes.getTotalNumBuckets());
}
}

View File

@@ -13,7 +13,6 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.boot.actuate;
import static org.assertj.core.api.Assertions.assertThat;
@@ -30,16 +29,18 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.distributed.DistributedSystem;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.distributed.DistributedSystem;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.data.gemfire.tests.mock.PoolMockObjects;
@@ -97,7 +98,7 @@ public class GeodePoolsHealthIndicatorUnitTests {
}
@Test
public void healthCheckCapturesDetails() throws Exception {
public void healthCheckCapturesDetails() {
List<InetSocketAddress> mockLocators =
Arrays.asList(testSocketAddress("mailbox", 1234),
@@ -149,12 +150,12 @@ public class GeodePoolsHealthIndicatorUnitTests {
assertThat(healthDetails).containsEntry("geode.pool.MockPool.subscription-enabled", "Yes");
assertThat(healthDetails).containsEntry("geode.pool.MockPool.subscription-message-tracking-timeout", 5000);
assertThat(healthDetails).containsEntry("geode.pool.MockPool.subscription-redundancy", 2);
assertThat(healthDetails).containsEntry("geode.pool.MockPool.thread-local-connections", "No");
//assertThat(healthDetails).containsEntry("geode.pool.MockPool.thread-local-connections", "No");
verify(this.poolsHealthIndicator, times(1)).findAllPools();
}
public void testHealthCheckFailsWhenGemFireCacheIsInvalid(GemFireCache gemfireCache) throws Exception {
public void testHealthCheckFailsWhenGemFireCacheIsInvalid(GemFireCache gemfireCache) {
GeodePoolsHealthIndicator healthIndicator = gemfireCache != null
? new GeodePoolsHealthIndicator(gemfireCache)

View File

@@ -13,7 +13,6 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.boot.actuate;
import static org.assertj.core.api.Assertions.assertThat;
@@ -28,6 +27,12 @@ import java.util.Currency;
import java.util.Map;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.apache.geode.cache.CacheStatistics;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.EvictionAction;
@@ -39,11 +44,7 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.PartitionAttributes;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.Scope;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.data.gemfire.tests.mock.CacheMockObjects;
@@ -79,8 +80,8 @@ public class GeodeRegionsHealthIndicatorUnitTests {
}
@Test
@SuppressWarnings("unchecked")
public void healthCheckCapturesDetails() throws Exception {
@SuppressWarnings({ "rawtypes", "unchecked" })
public void healthCheckCapturesDetails() {
Region<?, ?> mockRegionOne = CacheMockObjects.mockRegion("MockRegionOne", DataPolicy.PARTITION);
@@ -99,7 +100,7 @@ public class GeodeRegionsHealthIndicatorUnitTests {
when(mockPartitionAttributes.getColocatedWith()).thenReturn("CollocatedRegion");
when(mockPartitionAttributes.getLocalMaxMemory()).thenReturn(10240);
when(mockPartitionAttributes.getRedundantCopies()).thenReturn(2);
when(mockPartitionAttributes.getTotalMaxMemory()).thenReturn(4096000L);
//when(mockPartitionAttributes.getTotalMaxMemory()).thenReturn(4096000L);
when(mockPartitionAttributes.getTotalNumBuckets()).thenReturn(226);
when(mockRegionOne.getAttributes().getPartitionAttributes()).thenReturn(mockPartitionAttributes);
@@ -176,7 +177,7 @@ public class GeodeRegionsHealthIndicatorUnitTests {
assertThat(healthDetails).containsEntry("geode.cache.regions.MockRegionOne.partition.collocated-with", "CollocatedRegion");
assertThat(healthDetails).containsEntry("geode.cache.regions.MockRegionOne.partition.local-max-memory", 10240);
assertThat(healthDetails).containsEntry("geode.cache.regions.MockRegionOne.partition.redundant-copies", 2);
assertThat(healthDetails).containsEntry("geode.cache.regions.MockRegionOne.partition.total-max-memory", 4096000L);
//assertThat(healthDetails).containsEntry("geode.cache.regions.MockRegionOne.partition.total-max-memory", 4096000L);
assertThat(healthDetails).containsEntry("geode.cache.regions.MockRegionOne.partition.total-number-of-buckets", 226);
assertThat(healthDetails).containsEntry("geode.cache.regions.MockRegionOne.pool-name", "");
assertThat(healthDetails).containsEntry("geode.cache.regions.MockRegionOne.scope", Scope.DISTRIBUTED_ACK.toString());
@@ -206,7 +207,7 @@ public class GeodeRegionsHealthIndicatorUnitTests {
}
@Test
public void healthCheckFailsWhenGemFireCacheIsNotPresent() throws Exception {
public void healthCheckFailsWhenGemFireCacheIsNotPresent() {
GeodeRegionsHealthIndicator healthIndicator = new GeodeRegionsHealthIndicator();