Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
Coax actuator sample into a native image
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyer committed Aug 13, 2020
1 parent 30d80a7 commit e036962
Show file tree
Hide file tree
Showing 10 changed files with 1,825 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public interface TypeCondition {

boolean matches(TypeService types, Environment environment);

// TODO: need a BeanFactory or something too
default boolean matches(String resultType, TypeService types, Environment environment) {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public boolean matches(Class<?> type, ConfigurationPhase phase) {
}
ConditionService fallback = getFallback();
boolean matches = fallback == null ? false : fallback.matches(type, phase);
match(type, matches);
return matches;
}

Expand All @@ -83,6 +82,9 @@ public boolean matches(Class<?> type) {

@Override
public boolean matches(Class<?> factory, Class<?> type) {
if (typeMatches.containsKey(factory.getName())) {
return typeMatches.get(factory.getName()).matches(type.getName(), types, environment);
}
ConditionService fallback = getFallback();
boolean matches = fallback == null ? false : fallback.matches(factory, type);
return matches;
Expand All @@ -98,13 +100,4 @@ public boolean includes(Class<?> type) {
return fallback == null ? true : fallback.includes(type);
}

public TypeConditionService match(Class<?> type, boolean matches) {
typeMatches.put(type.getName(), (types, environment) -> matches);
return this;
}

public Map<String, TypeCondition> getTypeMatches() {
return typeMatches;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public class ProbesCondition implements TypeCondition {

private static final String DEPRECATED_ENABLED_PROPERTY = "management.health.probes.enabled";

@Override
public boolean matches(TypeService types, Environment environment) {
return getMatchOutcome(environment).isMatch();
}

// TODO: Add method matchers

private ConditionOutcome getMatchOutcome(Environment environment) {
ConditionMessage.Builder message = ConditionMessage.forCondition("Probes availability");
ConditionOutcome outcome = onProperty(environment, message, ENABLED_PROPERTY);
Expand All @@ -55,9 +62,4 @@ private ConditionOutcome onProperty(Environment environment, ConditionMessage.Bu
return null;
}

@Override
public boolean matches(TypeService types, Environment environment) {
return getMatchOutcome(environment).isMatch();
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Args=--initialize-at-build-time\=org.springframework.boot.autoconfigure.web.reactive.RouterFunctionAutoConfigurationInitializer,\
org.springframework.boot.autoconfigure.web.servlet.RouterFunctionAutoConfigurationInitializer
org.springframework.boot.autoconfigure.web.servlet.RouterFunctionAutoConfigurationInitializer,\
org.springframework.boot.actuate.autoconfigure.web.servlet.FunctionalServletActuatorEndpointAutoConfigurationInitializer,\
org.springframework.boot.actuate.autoconfigure.web.reactive.FunctionalReactiveActuatorEndpointAutoConfigurationInitializer
13 changes: 13 additions & 0 deletions samples/actuator/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM springci/spring-graalvm-native:master-java8

ARG USER
ARG USER_ID
ARG USER_GID

RUN (groupadd --gid "${USER_GID}" "${USER}" || echo "No groupadd needed") && \
useradd \
--uid ${USER_ID} \
--gid ${USER_GID} \
--create-home \
--shell /bin/bash \
${USER}
40 changes: 40 additions & 0 deletions samples/actuator/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "Java",
"dockerFile": "Dockerfile",
"build": {
"args": {
"USER": "${env:USER}",
"USER_ID": 1000, // VSCode adjusts the IDs when it builds
"USER_GID": 1000
}
},
"runArgs": [
"--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined",

"--mount", "type=bind,source=${env:HOME}/.ssh,target=${env:HOME}/.ssh",
"--mount", "type=bind,source=${env:HOME}/.m2,target=${env:HOME}/.m2"
],
"remoteUser": "${env:USER}",

// Use 'settings' to set *default* container specific settings.json values on container create.
// You can edit these settings after create using File > Preferences > Settings > Remote.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"remote.extensionKind": {
"ms-azuretools.vscode-docker": "workspace"
}
},

// Uncomment the next line if you want to publish any ports. Or use the Remote Explorer to open
// up ports in a running container.
// "appPort": [8080],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "java -version",

// Add the IDs of extensions you want installed when the container is created in the array below.
"extensions": [
"vscjava.vscode-java-pack",
"ms-vscode.cpptools"
]
}
3 changes: 3 additions & 0 deletions samples/actuator/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.reactive.FunctionalReactiveActuatorEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration;
Expand Down Expand Up @@ -66,7 +64,6 @@ public static void main(String[] args) {
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Endpoint.class)
@Import({ EndpointAutoConfiguration.class, ApplicationAvailabilityAutoConfiguration.class,
AvailabilityProbesAutoConfiguration.class, HealthContributorAutoConfiguration.class,
HealthEndpointAutoConfiguration.class, InfoEndpointAutoConfiguration.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"name":"com.fasterxml.jackson.core.JsonGenerator"
},
{
"name":"com.fasterxml.jackson.databind.ObjectMapper"
},
{
"name":"com.fasterxml.jackson.databind.deser.Deserializers[]"
},
{
"name":"com.fasterxml.jackson.databind.deser.KeyDeserializers[]"
},
{
"name":"com.fasterxml.jackson.databind.deser.ValueInstantiators[]"
},
{
"name":"com.fasterxml.jackson.databind.ser.Serializers[]"
},
{
"name":"org.springframework.boot.actuate.endpoint.web.Link",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"org.springframework.boot.actuate.health.CompositeHealth",
"allDeclaredFields":true,
"allDeclaredMethods":true
},
{
"name":"org.springframework.boot.actuate.health.Health",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"org.springframework.boot.actuate.health.HealthComponent",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"org.springframework.boot.actuate.health.Status",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"org.springframework.boot.actuate.health.SystemHealth",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
}
]
Loading

0 comments on commit e036962

Please sign in to comment.