Search in sources :

Example 1 with ConfigParams

use of com.netflix.spectator.stackdriver.ConfigParams in project kork by spinnaker.

the class StackdriverConfig method defaultStackdriverWriter.

/**
 * Schedule a thread to flush our registry into stackdriver periodically.
 *
 * This configures our StackdriverWriter as well.
 */
@Bean
public StackdriverWriter defaultStackdriverWriter(Environment environment, Registry registry, SpectatorStackdriverConfigurationProperties spectatorStackdriverConfigurationProperties) throws IOException {
    Logger log = LoggerFactory.getLogger("StackdriverConfig");
    log.info("Creating StackdriverWriter.");
    Predicate<Measurement> filterNotSpring = new Predicate<Measurement>() {

        public boolean test(Measurement measurement) {
            // These are from spring; those of interest were replicated in spectator.
            if (measurement.id().tags().iterator().hasNext()) {
                return true;
            }
            return false;
        }
    };
    Predicate<Measurement> measurementFilter;
    final String prototypeFilterPath = spectatorStackdriverConfigurationProperties.getWebEndpoint().getPrototypeFilter().getPath();
    if (!prototypeFilterPath.isEmpty()) {
        log.error("Ignoring prototypeFilterPath because it is not yet supported.");
        measurementFilter = null;
        log.info("Configuring stackdriver filter from {}", prototypeFilterPath);
        measurementFilter = PrototypeMeasurementFilter.loadFromPath(prototypeFilterPath).and(filterNotSpring);
    } else {
        measurementFilter = filterNotSpring;
    }
    InetAddress hostaddr = serverProperties.getAddress();
    if (hostaddr.equals(InetAddress.getLoopbackAddress())) {
        hostaddr = InetAddress.getLocalHost();
    }
    String host = hostaddr.getCanonicalHostName();
    String hostPort = host + ":" + serverProperties.getPort();
    ConfigParams params = new ConfigParams.Builder().setCounterStartTime(new Date().getTime()).setCustomTypeNamespace("spinnaker").setProjectName(spectatorStackdriverConfigurationProperties.getStackdriver().getProjectName()).setApplicationName(spectatorStackdriverConfigurationProperties.getApplicationName(environment.getProperty("spring.application.name"))).setCredentialsPath(spectatorStackdriverConfigurationProperties.getStackdriver().getCredentialsPath()).setMeasurementFilter(measurementFilter).setInstanceId(hostPort).build();
    stackdriver = new StackdriverWriter(params);
    Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(1));
    Observable.timer(spectatorStackdriverConfigurationProperties.getStackdriver().getPeriod(), TimeUnit.SECONDS).repeat().subscribe(interval -> {
        stackdriver.writeRegistry(registry);
    });
    return stackdriver;
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Scheduler(rx.Scheduler) StackdriverWriter(com.netflix.spectator.stackdriver.StackdriverWriter) Logger(org.slf4j.Logger) InetAddress(java.net.InetAddress) Date(java.util.Date) Predicate(java.util.function.Predicate) ConfigParams(com.netflix.spectator.stackdriver.ConfigParams) Bean(org.springframework.context.annotation.Bean)

Aggregations

Measurement (com.netflix.spectator.api.Measurement)1 ConfigParams (com.netflix.spectator.stackdriver.ConfigParams)1 StackdriverWriter (com.netflix.spectator.stackdriver.StackdriverWriter)1 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 Predicate (java.util.function.Predicate)1 Logger (org.slf4j.Logger)1 Bean (org.springframework.context.annotation.Bean)1 Scheduler (rx.Scheduler)1