Skip to content

Commit

Permalink
ADD theia ide ping healthchecks #237
Browse files Browse the repository at this point in the history
  • Loading branch information
wabscale committed Sep 25, 2021
1 parent 88d40c2 commit 845e07d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion api/anubis/utils/k8s/theia.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
import traceback
from datetime import datetime
from datetime import datetime, timedelta
from typing import Tuple, Optional

from kubernetes import client
Expand Down Expand Up @@ -524,7 +524,11 @@ def fix_stale_theia_resources(theia_pods: client.V1PodList):

# Get active pods and db rows
active_db_sessions = TheiaSession.query.filter(
# Get sessions marked as active
TheiaSession.active == True,

# Filter for sessions that have had a proxy in the last 10 minutes
TheiaSession.last_proxy >= datetime.now() - timedelta(minutes=10),
).all()

# Build set of active pod session ids
Expand Down
3 changes: 3 additions & 0 deletions theia/ide/admin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ RUN set -ex; \
apt-get install -y --no-install-recommends libsecret-1-0; \
yarn --pure-lockfile; \
NODE_OPTIONS="--max_old_space_size=4096" yarn theia build; \
HEAD_LINE_NUMBER=$(grep -n '</head>' lib/index.html | cut -f1 -d:); \
SCRIPT_LINE='<script>function ping(){if (document.hasFocus()){fetch("/ide/ping")}};document.addEventListener("focus",ping);setInterval(ping,60000)</script>'; \
sed -i "${HEAD_LINE_NUMBER}i${SCRIPT_LINE}" lib/index.html; \
yarn theia download:plugins; \
yarn --production; \
yarn autoclean --init; \
Expand Down
3 changes: 3 additions & 0 deletions theia/ide/devops/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ RUN set -ex; \
apt-get install -y --no-install-recommends libsecret-1-0; \
yarn --pure-lockfile; \
NODE_OPTIONS="--max_old_space_size=4096" yarn theia build; \
HEAD_LINE_NUMBER=$(grep -n '</head>' lib/index.html | cut -f1 -d:); \
SCRIPT_LINE='<script>function ping(){if (document.hasFocus()){fetch("/ide/ping")}};document.addEventListener("focus",ping);setInterval(ping,60000)</script>'; \
sed -i "${HEAD_LINE_NUMBER}i${SCRIPT_LINE}" lib/index.html; \
yarn theia download:plugins; \
yarn --production; \
yarn autoclean --init; \
Expand Down
3 changes: 1 addition & 2 deletions theia/ide/devops/latest.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"vscode-builtin-xml": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/xml-1.39.1-prel.vsix",
"vscode-builtin-yaml": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/yaml-1.39.1-prel.vsix",
"vscode-editorconfig": "https://github.com/theia-ide/editorconfig-vscode/releases/download/v0.14.4/EditorConfig-0.14.4.vsix",
"vscode-python": "https://open-vsx.org/api/ms-python/python/2020.8.105369/file/ms-python.python-2020.8.105369.vsix",
"vscode-builtin-theme-defaults": "https://github.com/theia-ide/vscode-builtin-extensions/releases/download/v1.39.1-prel/theme-defaults-1.39.1-prel.vsix"
"vscode-python": "https://open-vsx.org/api/ms-python/python/2020.8.105369/file/ms-python.python-2020.8.105369.vsix"
}
}
3 changes: 3 additions & 0 deletions theia/ide/distributed-systems/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ RUN set -ex; \
libsecret-1-0; \
yarn --pure-lockfile; \
NODE_OPTIONS="--max_old_space_size=4096" yarn theia build; \
HEAD_LINE_NUMBER=$(grep -n '</head>' lib/index.html | cut -f1 -d:); \
SCRIPT_LINE='<script>function ping(){if (document.hasFocus()){fetch("/ide/ping")}};document.addEventListener("focus",ping);setInterval(ping,60000)</script>'; \
sed -i "${HEAD_LINE_NUMBER}i${SCRIPT_LINE}" lib/index.html; \
yarn theia download:plugins; \
yarn --production; \
yarn autoclean --init; \
Expand Down
3 changes: 3 additions & 0 deletions theia/ide/jepst/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ RUN set -ex; \
; \
yarn --pure-lockfile; \
NODE_OPTIONS="--max_old_space_size=4096" yarn theia build; \
HEAD_LINE_NUMBER=$(grep -n '</head>' lib/index.html | cut -f1 -d:); \
SCRIPT_LINE='<script>function ping(){if (document.hasFocus()){fetch("/ide/ping")}};document.addEventListener("focus",ping);setInterval(ping,60000)</script>'; \
sed -i "${HEAD_LINE_NUMBER}i${SCRIPT_LINE}" lib/index.html; \
yarn theia download:plugins; \
yarn --production; \
yarn autoclean --init; \
Expand Down
3 changes: 3 additions & 0 deletions theia/ide/xv6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ RUN set -ex; \
libsecret-1-0; \
yarn --pure-lockfile; \
NODE_OPTIONS="--max_old_space_size=4096" yarn theia build; \
HEAD_LINE_NUMBER=$(grep -n '</head>' lib/index.html | cut -f1 -d:); \
SCRIPT_LINE='<script>function ping(){if (document.hasFocus()){fetch("/ide/ping")}};document.addEventListener("focus",ping);setInterval(ping,60000)</script>'; \
sed -i "${HEAD_LINE_NUMBER}i${SCRIPT_LINE}" lib/index.html; \
yarn theia download:plugins; \
yarn --production; \
yarn autoclean --init; \
Expand Down
2 changes: 1 addition & 1 deletion theia/proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ var proxyServer = http.createServer(function (req, res) {
return;

case '/ping':
if (token !== null) updateProxyTime(token.session_id);
res.writeHead(200);
res.end('pong');
return;
Expand All @@ -166,7 +167,6 @@ var proxyServer = http.createServer(function (req, res) {
return;
}

// updateProxyTime(token.session_id);
get_session_ip(token.session_id).then((host) => {
proxy.web(req, res, {
target: {host, port}
Expand Down
1 change: 1 addition & 0 deletions theia/proxy/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setInterval(function() { fetch('/ide/ping'); }, 60*1000);

0 comments on commit 845e07d

Please sign in to comment.