|
50 | 50 | import org.mandas.docker.client.messages.ContainerInfo; |
51 | 51 | import org.mandas.docker.client.messages.ContainerState; |
52 | 52 | import org.mandas.docker.client.messages.HostConfig; |
| 53 | +import org.mandas.docker.client.messages.LogConfig; |
53 | 54 | import org.mandas.docker.client.messages.PortBinding; |
54 | 55 | import org.mandas.docker.client.messages.RegistryAuth; |
55 | 56 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
@@ -77,17 +78,20 @@ public class DockerEngineBackend extends AbstractDockerBackend { |
77 | 78 |
|
78 | 79 | private static final String PROPERTY_IMG_PULL_POLICY = "image-pull-policy"; |
79 | 80 | private static final String PROPERTY_CONTAINER_NETWORK = "default-container-network"; |
| 81 | + private static final String PROPERTY_LOKI_URL = "loki-url"; |
80 | 82 |
|
81 | 83 | private ImagePullPolicy imagePullPolicy; |
82 | 84 | private String nonInternalNetworkTargetProtocol; |
83 | 85 | private URL hostURL; |
84 | 86 | private String containerNetwork; |
| 87 | + private String lokiUrl; |
85 | 88 |
|
86 | 89 | @PostConstruct |
87 | 90 | public void initialize() { |
88 | 91 | super.initialize(); |
89 | 92 | imagePullPolicy = environment.getProperty(getPropertyPrefix() + PROPERTY_IMG_PULL_POLICY, ImagePullPolicy.class, ImagePullPolicy.IfNotPresent); |
90 | 93 | containerNetwork = environment.getProperty(getPropertyPrefix() + PROPERTY_CONTAINER_NETWORK); |
| 94 | + lokiUrl = environment.getProperty(getPropertyPrefix() + PROPERTY_LOKI_URL); |
91 | 95 |
|
92 | 96 | try { |
93 | 97 | hostURL = new URL(getProperty(PROPERTY_URL, DEFAULT_TARGET_URL)); |
@@ -171,6 +175,17 @@ public Proxy startContainer(Authentication user, Container initialContainer, Con |
171 | 175 | } |
172 | 176 | }); |
173 | 177 |
|
| 178 | + if (lokiUrl != null) { |
| 179 | + hostConfigBuilder.logConfig(LogConfig.builder() |
| 180 | + .logType("loki") |
| 181 | + .logOptions(Map.of( |
| 182 | + "loki-url", lokiUrl, |
| 183 | + "mode", "non-blocking", |
| 184 | + "loki-external-labels", String.format("sp_realm_id=%s,namespace=default,sp_proxy_id=%s", identifierService.realmId, proxy.getId()) |
| 185 | + )) |
| 186 | + .build()); |
| 187 | + } |
| 188 | + |
174 | 189 | ContainerConfig containerConfig = ContainerConfig.builder() |
175 | 190 | .hostConfig(hostConfigBuilder.build()) |
176 | 191 | .image(spec.getImage().getValue()) |
|
0 commit comments