use of com.netflix.spectator.stackdriver.StackdriverWriter 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;
}
Aggregations