Skip to content

Commit

Permalink
feat(chart): enable automatic browser leftovers cleanup in chart
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Mar 27, 2024
1 parent ed2b538 commit fed2e1c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -952,15 +952,15 @@ of jobs that have already finished but failed to fully stop the browser, or temp
file system (notably on Chrome-based browsers). To avoid these filling up resources like process IDs and file system
usage in the container, there is an automatic cleanup script running every hour in the node containers. This will
clean up old processes and old temporary files. By default, this is disabled. When enabled, this will clean up browsers
running for longer than 20 minutes, and files older than 1 day. These can be enabled and tweaked with the following
running for longer than 2 hours, and files older than 1 day. These can be enabled and tweaked with the following
environment variables:

* `SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP`: default value `false`, set to `true` to enable the cleanup.
* `SE_BROWSER_LEFTOVERS_INTERVAL_SECS`: default value `3600` (1 hour), cleanup interval in seconds.
* `SE_BROWSER_LEFTOVERS_PROCESSES_SECS`: default value `7200` (2 hours), browsers running for longer than this time will be killed.
* `SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS`: default value `1` (1 day), files generated by Chrome-based browsers in `/tmp` will be removed after these number of days (ignored when using Firefox).

If you use Selenium for long-running sessions and expect browsers to be running for longer than 20 minutes, either do
If you use Selenium for long-running sessions and expect browsers to be running for longer than 2 hours, either do
not set `SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP` to `true` (leave the default value of `false`), or tweak
`SE_BROWSER_LEFTOVERS_PROCESSES_SECS` to set a value higher than your expected long-running browser processes.

Expand Down
12 changes: 12 additions & 0 deletions charts/selenium-grid/templates/node-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ data:
SE_DRAIN_AFTER_SESSION_COUNT: '{{- and (eq (include "seleniumGrid.useKEDA" .) "true") (eq .Values.autoscaling.scalingType "job") | ternary "1" "0" -}}'
SE_NODE_GRID_URL: '{{ include "seleniumGrid.url" .}}'
SE_NODE_GRID_GRAPHQL_URL: '{{ include "seleniumGrid.graphqlURL" . }}'
{{- if $.Values.nodeConfigMap.leftoversCleanup.enabled }}
SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP: 'true'
{{- with $.Values.nodeConfigMap.leftoversCleanup.jobIntervalInSecs }}
SE_BROWSER_LEFTOVERS_INTERVAL_SECS: '{{ . }}'
{{- end }}
{{- with $.Values.nodeConfigMap.leftoversCleanup.browserElapsedTimeInSecs }}
SE_BROWSER_LEFTOVERS_PROCESSES_SECS: '{{ . }}'
{{- end }}
{{- with $.Values.nodeConfigMap.leftoversCleanup.tmpFilesAfterDays }}
SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS: '{{ . }}'
{{- end }}
{{- end }}
{{- $fileProceeded := list -}}
{{- range $path, $_ := .Files.Glob $.Values.nodeConfigMap.extraScriptsImportFrom }}
{{- $fileName := base $path -}}
Expand Down
8 changes: 7 additions & 1 deletion charts/selenium-grid/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ global:
# liveness probe method `exec.command` is using a script is mounted from `nodeConfigMap.extraScripts.nodeProbe.sh`
defaultNodeLivenessProbe: exec
# probe logs output can be retrieved using `kubectl logs`
stdoutProbeLog: true
stdoutProbeLog: false

tls:
enabled: false
Expand Down Expand Up @@ -117,6 +117,12 @@ nodeConfigMap:
nodeProbe.sh:
# Name of volume mount is used to mount scripts in the ConfigMap
scriptVolumeMountName:
# Automatic browser leftovers cleanup stuck browser processes, tmp files
leftoversCleanup:
enabled: false
jobIntervalInSecs: 3600
browserElapsedTimeInSecs: 7200
tmpFilesAfterDays: 1
# Custom annotations for configmap
annotations: {}

Expand Down
2 changes: 2 additions & 0 deletions tests/charts/templates/render/dummy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ videoRecorder:
RCLONE_CONFIG_S3_NO_CHECK_BUCKET: "true"

nodeConfigMap:
leftoversCleanup:
enabled: true
extraScripts:
nodeCustomTask.sh: |
#!/bin/bash
Expand Down
2 changes: 2 additions & 0 deletions tests/charts/templates/render/dummy_solution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ selenium-grid:
RCLONE_CONFIG_S3_NO_CHECK_BUCKET: "true"

nodeConfigMap:
leftoversCleanup:
enabled: true
extraScripts:
nodeCustomTask.sh: |
#!/bin/bash
Expand Down
13 changes: 13 additions & 0 deletions tests/charts/templates/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ def test_terminationGracePeriodSeconds_in_deployment_autoscaling(self):
count += 1
self.assertEqual(count, len(resources_name), "node.terminationGracePeriodSeconds doesn't inherit the global value autoscaling.terminationGracePeriodSeconds")

def test_enable_leftovers_cleanup(self):
resources_name = ['{0}selenium-node-config'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'ConfigMap':
logger.info(f"Assert ENV vars for function leftovers cleanup is set to Node ConfigMap")
self.assertEqual(doc['data']['SE_ENABLE_BROWSER_LEFTOVERS_CLEANUP'], 'true')
self.assertEqual(doc['data']['SE_BROWSER_LEFTOVERS_INTERVAL_SECS'], '3600')
self.assertEqual(doc['data']['SE_BROWSER_LEFTOVERS_PROCESSES_SECS'], '7200')
self.assertEqual(doc['data']['SE_BROWSER_LEFTOVERS_TEMPFILES_DAYS'], '1')
count += 1
self.assertEqual(count, len(resources_name), "No node config resources found")

if __name__ == '__main__':
failed = False
try:
Expand Down

0 comments on commit fed2e1c

Please sign in to comment.