Skip to content

Instantly share code, notes, and snippets.

Avatar

Joris Kuipers jkuipers

  • Trifork
  • The Netherlands, near Amsterdam
View GitHub Profile
@jkuipers
jkuipers / TomcatAutoConfiguration.java
Created Jan 14, 2022
Spring Boot (auto-)configuration class that defines an additional Tomcat Connector for health checks
View TomcatAutoConfiguration.java
import org.apache.catalina.connector.Connector;
import org.apache.coyote.AbstractProtocol;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@jkuipers
jkuipers / OpenJ9MemoryMetrics.java
Created Jan 14, 2022
Micrometer.io heap statistics for OpenJ9 VMs
View OpenJ9MemoryMetrics.java
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.BaseUnits;
import io.micrometer.core.instrument.binder.MeterBinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
@jkuipers
jkuipers / MDCPropagatingTaskDecorator.java
Created Jan 5, 2022
Spring TaskDecorator that propagates an SLF4J MDC to the runner's thread. Accounts for the possibility that the runner's thread is actually the same as the caller's thread by restoring the old MDC context, if existing.
View MDCPropagatingTaskDecorator.java
import org.slf4j.MDC;
import org.springframework.core.task.TaskDecorator;
import java.util.Map;
public class MDCPropagatingTaskDecorator implements TaskDecorator {
@Override
public Runnable decorate(Runnable runnable) {
Map<String, String> callerContext = MDC.getCopyOfContextMap();
@jkuipers
jkuipers / spring-boot-snippet.gradle
Created Jun 23, 2020
Sample of how to configure Spring Boot's layered jar support for multi-module build that includes your own libs
View spring-boot-snippet.gradle
subprojects { subproject ->
// ...
plugins.withId('org.springframework.boot') {
springBoot {
bootJar {
layered {
// application follows Boot's defaults
application {
intoLayer("spring-boot-loader") {
@jkuipers
jkuipers / HttpConnectionPoolHealthIndicator.java
Last active Jun 16, 2020
Ensures unhealthy status in case a PoolingHttpClientConnectionManager is shut down, e.g. as result of OOM
View HttpConnectionPoolHealthIndicator.java
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
View keybase.md

Keybase proof

I hereby claim:

  • I am jkuipers on github.
  • I am jkuipers (https://keybase.io/jkuipers) on keybase.
  • I have a public key ASCj78lyxPW8_W1t735luDbfcfDboljNT1nxLwkDZvK7rQo

To claim this, I am signing this object:

View MdcPropagatingHystrixConcurrencyStrategy.java
import com.netflix.hystrix.HystrixThreadPoolKey;
import com.netflix.hystrix.HystrixThreadPoolProperties;
import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariable;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableLifecycle;
import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier;
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
View ApiKeyHeaderFilter.java
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PROXY_KEY;
/**
* Adds an API key in the form of a request header to proxied requests.
@jkuipers
jkuipers / InstrumentedQueueMessagingTemplate.java
Last active May 2, 2019
Spring Cloud AWS QueueMessagingTemplate subtype which adds Brave and Micrometer.io integration for sending messages
View InstrumentedQueueMessagingTemplate.java
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.Propagation;
import brave.propagation.TraceContext;
import com.amazonaws.services.sqs.AmazonSQSAsync;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import org.springframework.cloud.aws.messaging.core.QueueMessageChannel;
import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
View DnsServerList.java
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.Security;
import java.util.ArrayList;
import java.util.List;