
com.opentable.metrics.http.HealthController Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.opentable.metrics.http;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.SortedMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import javax.inject.Named;
import com.codahale.metrics.health.HealthCheck.Result;
import com.codahale.metrics.health.HealthCheckRegistry;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import com.opentable.metrics.health.HealthConfiguration;
import com.opentable.spring.PropertySourceUtil;
@Named
public class HealthController {
private static final Logger LOG = LoggerFactory.getLogger(HealthController.class);
private static final String CONFIG_PREFIX = "ot.metrics.health.group.";
private static final String WARN_PREFIX = "WARN: ";
private final Map failingChecks = new ConcurrentHashMap<>();
private final Map> groups = new HashMap<>();
private final HealthCheckRegistry registry;
private final ExecutorService executor;
public HealthController(HealthCheckRegistry registry, @Named(HealthConfiguration.HEALTH_CHECK_POOL_NAME) ExecutorService executor,
ConfigurableEnvironment env) {
this.registry = registry;
this.executor = executor;
final Properties groupBaseConf = PropertySourceUtil.getProperties(env, CONFIG_PREFIX);
groupBaseConf.stringPropertyNames().forEach(group -> {
final Set groupItems = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList(groupBaseConf.getProperty(group).split(","))));
groups.put(group, groupItems);
});
}
public Pair
© 2015 - 2025 Weber Informatics LLC | Privacy Policy