Skip to content

Commit 7c7e596

Browse files
author
Oleksandr Garagatyi
authored
Add possibility to disable DockerInstanceStopDetector (eclipse-che#6415)
It is needed for OpenShift infra where getting events is not supported due to security limits. To disable containers stop detector variable CHE_DOCKER_ENABLE__CONTAINER__STOP__DETECTOR=false should be defined. Signed-off-by: Oleksandr Garagatyi <ogaragat@redhat.com>
1 parent 7ce87d9 commit 7c7e596

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ che.docker.cleanup_period_min=60
255255
# Version number of the Docker API used within the Che implementation
256256
che.docker.api=1.20
257257

258+
# Whether to enable component that detects failures of a machine caused by unexpected container stop
259+
che.docker.enable_container_stop_detector=true
260+
258261
che.docker.network_driver=NULL
259262

260263
che.docker.tcp_connection_timeout_ms=600000

plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/DockerInstanceStopDetector.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.concurrent.TimeUnit;
2222
import javax.annotation.PostConstruct;
2323
import javax.inject.Inject;
24+
import javax.inject.Named;
2425
import javax.inject.Singleton;
2526
import org.eclipse.che.api.core.notification.EventService;
2627
import org.eclipse.che.api.machine.server.event.InstanceStateEvent;
@@ -44,10 +45,11 @@
4445
public class DockerInstanceStopDetector {
4546
private static final Logger LOG = LoggerFactory.getLogger(DockerInstanceStopDetector.class);
4647

47-
private final EventService eventService;
48-
private final DockerConnector dockerConnector;
49-
private final ExecutorService executorService;
50-
private final Map<String, Pair<String, String>> instances;
48+
private final boolean isEnabled;
49+
private EventService eventService;
50+
private DockerConnector dockerConnector;
51+
private ExecutorService executorService;
52+
private Map<String, Pair<String, String>> instances;
5153
/*
5254
Helps differentiate container main process OOM from other processes OOM
5355
Algorithm:
@@ -60,13 +62,19 @@ public class DockerInstanceStopDetector {
6062
That's why cache expires in X seconds.
6163
X was set as 10 empirically.
6264
*/
63-
private final Cache<String, String> containersOomTimestamps;
65+
private Cache<String, String> containersOomTimestamps;
6466

6567
private long lastProcessedEventDate = 0;
6668

6769
@Inject
6870
public DockerInstanceStopDetector(
69-
EventService eventService, DockerConnectorProvider dockerConnectorProvider) {
71+
EventService eventService,
72+
DockerConnectorProvider dockerConnectorProvider,
73+
@Named("che.docker.enable_container_stop_detector") boolean isEnabled) {
74+
this.isEnabled = isEnabled;
75+
if (!isEnabled) {
76+
return;
77+
}
7078
this.eventService = eventService;
7179
this.dockerConnector = dockerConnectorProvider.get();
7280
this.instances = new ConcurrentHashMap<>();
@@ -89,7 +97,9 @@ public DockerInstanceStopDetector(
8997
* @param workspaceId id of a workspace that owns machine
9098
*/
9199
public void startDetection(String containerId, String machineId, String workspaceId) {
92-
instances.put(containerId, Pair.of(machineId, workspaceId));
100+
if (isEnabled) {
101+
instances.put(containerId, Pair.of(machineId, workspaceId));
102+
}
93103
}
94104

95105
/**
@@ -98,11 +108,16 @@ public void startDetection(String containerId, String machineId, String workspac
98108
* @param containerId id of a container to start detection for
99109
*/
100110
public void stopDetection(String containerId) {
101-
instances.remove(containerId);
111+
if (isEnabled) {
112+
instances.remove(containerId);
113+
}
102114
}
103115

104116
@PostConstruct
105117
private void detectContainersEvents() {
118+
if (!isEnabled) {
119+
return;
120+
}
106121
executorService.execute(
107122
() -> {
108123
//noinspection InfiniteLoopStatement

0 commit comments

Comments
 (0)