Skip to content

Commit

Permalink
feat(chart): se:recordVideo should be used to determine if record vi…
Browse files Browse the repository at this point in the history
…deo (#2104)

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Jan 23, 2024
1 parent 7485f7f commit 6f5f75b
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 93 deletions.
1 change: 1 addition & 0 deletions .github/workflows/helm-chart-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ jobs:
uses: helm/[email protected]
with:
mark_as_latest: false
skip_existing: true
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
18 changes: 18 additions & 0 deletions charts/selenium-grid/configs/recorder/graphQLRecordVideo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# Define parameters
SESSION_ID=$1
GRAPHQL_ENDPOINT=${2:-$SE_NODE_GRID_GRAPHQL_URL}

# Send GraphQL query
curl --retry 3 -k -X POST \
-H "Content-Type: application/json" \
--data '{"query":"{ session (id: \"'${SESSION_ID}'\") { id, capabilities, startTime, uri, nodeId, nodeUri, sessionDurationMillis, slot { id, stereotype, lastStarted } } } "}' \
-s "${GRAPHQL_ENDPOINT}" > /tmp/graphQL_$SESSION_ID.json

RECORD_VIDEO=$(jq -r '.data.session.capabilities | fromjson | ."se:recordVideo"' /tmp/graphQL_$SESSION_ID.json)

if [ "${RECORD_VIDEO}" = "false" ]; then
echo "${RECORD_VIDEO}"
else
echo true
fi
21 changes: 14 additions & 7 deletions charts/selenium-grid/configs/recorder/video.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash

UPLOAD_ENABLED=${UPLOAD_ENABLED:-"false"}
VIDEO_UPLOAD_ENABLED=${VIDEO_UPLOAD_ENABLED:-"false"}
VIDEO_CONFIG_DIRECTORY=${VIDEO_CONFIG_DIRECTORY:-"/opt/bin"}

function create_pipe() {
if [[ "${UPLOAD_ENABLED}" != "false" ]] && [[ ! -z "${UPLOAD_DESTINATION_PREFIX}" ]];
if [[ "${VIDEO_UPLOAD_ENABLED}" != "false" ]] && [[ ! -z "${UPLOAD_DESTINATION_PREFIX}" ]];
then
echo "Create pipe if not exists for video upload stream"
if [ ! -p ${SE_VIDEO_FOLDER}/uploadpipe ];
Expand All @@ -15,7 +16,7 @@ function create_pipe() {
create_pipe

function wait_util_force_exit_consume() {
if [[ "${UPLOAD_ENABLED}" != "false" ]] && [[ ! -z "${UPLOAD_DESTINATION_PREFIX}" ]];
if [[ "${VIDEO_UPLOAD_ENABLED}" != "false" ]] && [[ ! -z "${UPLOAD_DESTINATION_PREFIX}" ]];
then
while [[ -f ${SE_VIDEO_FOLDER}/force_exit ]]
do
Expand All @@ -27,7 +28,7 @@ function wait_util_force_exit_consume() {
}

function add_exit_signal() {
if [[ "${UPLOAD_ENABLED}" != "false" ]] && [[ ! -z "${UPLOAD_DESTINATION_PREFIX}" ]];
if [[ "${VIDEO_UPLOAD_ENABLED}" != "false" ]] && [[ ! -z "${UPLOAD_DESTINATION_PREFIX}" ]];
then
echo "exit" >> ${SE_VIDEO_FOLDER}/uploadpipe &
echo "exit" > ${SE_VIDEO_FOLDER}/force_exit
Expand Down Expand Up @@ -93,8 +94,14 @@ fi
while curl -sk --request GET ${SE_SERVER_PROTOCOL}://${DISPLAY_CONTAINER_NAME}:${SE_NODE_PORT}/status > /tmp/status.json
do
session_id=$(jq -r '.[]?.node?.slots | .[0]?.session?.sessionId' /tmp/status.json)
echo $session_id
echo "Session: $session_id is created"
if [[ "$session_id" != "null" && "$session_id" != "" && "$recording_started" = "false" ]]
then
caps_se_video_record=$(bash ${VIDEO_CONFIG_DIRECTORY}/graphQLRecordVideo.sh "$session_id")
cat "/tmp/graphQL_$session_id.json"; echo
echo "se:recordVideo value is: $caps_se_video_record"
fi
if [[ "$session_id" != "null" && "$session_id" != "" && "$recording_started" = "false" && "$caps_se_video_record" = "true" ]]
then
video_file_name="$session_id.mp4"
video_file="${SE_VIDEO_FOLDER}/$video_file_name"
Expand All @@ -108,12 +115,12 @@ do
pkill -INT ffmpeg
recorded_count=$((recorded_count+1))
recording_started="false"
if [[ "${UPLOAD_ENABLED}" != "false" ]] && [[ ! -z "${UPLOAD_DESTINATION_PREFIX}" ]];
if [[ "${VIDEO_UPLOAD_ENABLED}" != "false" ]] && [[ ! -z "${UPLOAD_DESTINATION_PREFIX}" ]];
then
upload_destination=${UPLOAD_DESTINATION_PREFIX}/${video_file_name}
echo "Uploading video to $upload_destination"
echo $video_file ${UPLOAD_DESTINATION_PREFIX} >> ${SE_VIDEO_FOLDER}/uploadpipe &
elif [[ "${UPLOAD_ENABLED}" != "false" ]] && [[ -z "${UPLOAD_DESTINATION_PREFIX}" ]];
elif [[ "${VIDEO_UPLOAD_ENABLED}" != "false" ]] && [[ -z "${UPLOAD_DESTINATION_PREFIX}" ]];
then
echo Upload destination not known since UPLOAD_DESTINATION_PREFIX is not set. Continue without uploading.
fi
Expand Down
107 changes: 51 additions & 56 deletions charts/selenium-grid/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,15 @@ template:
{{- end }}
envFrom:
- configMapRef:
name: {{ .Values.busConfigMap.name }}
name: {{ tpl (toYaml .Values.busConfigMap.name) $ }}
- configMapRef:
name: {{ .Values.nodeConfigMap.name }}
name: {{ tpl (toYaml .Values.nodeConfigMap.name) $ }}
- configMapRef:
name: {{ .Values.loggingConfigMap.name }}
name: {{ tpl (toYaml .Values.loggingConfigMap.name) $ }}
- configMapRef:
name: {{ .Values.serverConfigMap.name }}
name: {{ tpl (toYaml .Values.serverConfigMap.name) $ }}
- secretRef:
name: {{ include "seleniumGrid.common.secrets" $ | quote }}
name: {{ include "seleniumGrid.common.secrets" $ }}
{{- with .node.extraEnvFrom }}
{{- tpl (toYaml .) $ | nindent 10 }}
{{- end }}
Expand All @@ -364,9 +364,11 @@ template:
volumeMounts:
- name: dshm
mountPath: /dev/shm
- name: {{ .Values.nodeConfigMap.scriptVolumeMountName }}
mountPath: /opt/selenium/{{ .Values.nodeConfigMap.preStopScript }}
subPath: {{ .Values.nodeConfigMap.preStopScript }}
{{- range $fileName, $value := .Values.nodeConfigMap.extraScripts }}
- name: {{ $.Values.nodeConfigMap.scriptVolumeMountName }}
mountPath: {{ $.Values.nodeConfigMap.extraScriptsDirectory }}/{{ $fileName }}
subPath: {{ $fileName }}
{{- end }}
{{- if .Values.tls.enabled }}
- name: {{ include "seleniumGrid.tls.fullname" $ | quote }}
mountPath: {{ .Values.serverConfigMap.certVolumeMountPath }}
Expand Down Expand Up @@ -451,11 +453,13 @@ template:
{{- end }}
envFrom:
- configMapRef:
name: {{ .Values.busConfigMap.name }}
name: {{ tpl (toYaml .Values.busConfigMap.name) $ }}
- configMapRef:
name: {{ tpl (toYaml .Values.nodeConfigMap.name) $ }}
- configMapRef:
name: {{ .Values.nodeConfigMap.name }}
name: {{ tpl (toYaml .Values.recorderConfigMap.name) $ }}
- configMapRef:
name: {{ .Values.serverConfigMap.name }}
name: {{ tpl (toYaml .Values.serverConfigMap.name) $ }}
{{- with .Values.videoRecorder.extraEnvFrom }}
{{- tpl (toYaml .) $ | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -499,14 +503,16 @@ template:
{{- if .uploader.args }}
args: {{- tpl (toYaml .uploader.args) $ | nindent 8 }}
{{- else }}
args: ["-c", "{{ $.Values.videoRecorder.uploader.scriptMountPath }}/{{ $.Values.videoRecorder.uploader.entryPointFileName }}"]
args: ["-c", "{{ $.Values.recorderConfigMap.extraScriptsDirectory }}/{{ $.Values.videoRecorder.uploader.entryPointFileName }}"]
{{- end }}
{{- with .uploader.extraEnvironmentVariables }}
env: {{- tpl (toYaml .) $ | nindent 8 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ tpl (toYaml .Values.uploaderConfigMap.name) $ }}
- secretRef:
name: {{ include "seleniumGrid.common.secrets" $ | quote }}
name: {{ tpl (toYaml .Values.uploaderConfigMap.secretVolumeMountName) $ }}
{{- with .uploader.extraEnvFrom }}
{{- tpl (toYaml .) $ | nindent 10 }}
{{- end }}
Expand Down Expand Up @@ -655,7 +661,7 @@ Define preStop hook for the node pod. Node preStop script is stored in a ConfigM
{{- define "seleniumGrid.node.deregisterLifecycle" -}}
preStop:
exec:
command: ["bash", "-c", "/opt/selenium/{{ .Values.nodeConfigMap.preStopScript }}"]
command: ["bash", "-c", "{{ $.Values.nodeConfigMap.extraScriptsDirectory }}/nodePreStop.sh"]
{{- end -}}

{{/*
Expand Down Expand Up @@ -699,56 +705,45 @@ Define terminationGracePeriodSeconds of the node pod.
{{- $period -}}
{{- end -}}

{{/*
Default specs of VolumeMounts and Volumes for video recorder
*/}}
{{- define "seleniumGrid.video.volume.name.folder" -}}
{{- $name := default "video" (((.Values.videoRecorder).volume).name).folder -}}
{{- $name -}}
{{- end -}}

{{- define "seleniumGrid.video.volume.name.scripts" -}}
{{- $name := default "video-scripts" (((.Values.videoRecorder).volume).name).scripts -}}
{{- $name -}}
{{- end -}}

{{- define "seleniumGrid.video.volumeMounts.default" -}}
{{- $root := . -}}
{{- range $path, $bytes := .Files.Glob "configs/recorder/*.sh" }}
- name: {{ include "seleniumGrid.video.volume.name.scripts" $ }}
mountPath: /opt/bin/{{ base $path }}
subPath: {{ base $path }}
{{- range $fileName, $value := .Values.recorderConfigMap.extraScripts }}
- name: {{ tpl (toYaml $.Values.recorderConfigMap.scriptVolumeMountName) $ }}
mountPath: {{ $.Values.recorderConfigMap.extraScriptsDirectory }}/{{ $fileName }}
subPath: {{ $fileName }}
{{- end }}
- name: {{ include "seleniumGrid.video.volume.name.folder" . }}
mountPath: /videos
- name: {{ tpl (toYaml $.Values.recorderConfigMap.videoVolumeMountName) $ }}
mountPath: {{ $.Values.videoRecorder.targetFolder }}
{{- end -}}

{{- define "seleniumGrid.video.volumes.default" -}}
- name: {{ include "seleniumGrid.video.volume.name.scripts" . }}
- name: {{ tpl (toYaml $.Values.recorderConfigMap.videoVolumeMountName) $ }}
emptyDir: {}
- name: {{ tpl (toYaml $.Values.recorderConfigMap.scriptVolumeMountName) $ }}
configMap:
name: {{ tpl (toYaml $.Values.recorderConfigMap.name) $ }}
defaultMode: {{ $.Values.recorderConfigMap.defaultMode }}
- name: {{ tpl (toYaml $.Values.uploaderConfigMap.scriptVolumeMountName) $ }}
configMap:
name: {{ template "seleniumGrid.video.fullname" . }}
defaultMode: 0500
- name: {{ template "seleniumGrid.common.secrets" . }}
name: {{ tpl (toYaml $.Values.uploaderConfigMap.name) $ }}
defaultMode: {{ $.Values.uploaderConfigMap.defaultMode }}
- name: {{ tpl (toYaml $.Values.uploaderConfigMap.secretVolumeMountName) $ }}
secret:
secretName: {{ template "seleniumGrid.common.secrets" . }}
- name: {{ include "seleniumGrid.video.volume.name.folder" . }}
emptyDir: {}
secretName: {{ tpl (toYaml $.Values.uploaderConfigMap.secretVolumeMountName) $ }}
{{- end -}}

{{- define "seleniumGrid.video.uploader.volumeMounts.default" -}}
{{- $root := . -}}
{{- range $path, $bytes := .Files.Glob (printf "configs/uploader/%s/*.sh" $.Values.videoRecorder.uploader.name) }}
- name: {{ include "seleniumGrid.video.volume.name.scripts" $ }}
mountPath: {{ $.Values.videoRecorder.uploader.scriptMountPath }}/{{ base $path }}
subPath: {{ base $path }}
{{- range $fileName, $value := .Values.uploaderConfigMap.extraScripts }}
- name: {{ tpl (toYaml $.Values.uploaderConfigMap.scriptVolumeMountName) $ }}
mountPath: {{ $.Values.uploaderConfigMap.extraScriptsDirectory }}/{{ $fileName }}
subPath: {{ $fileName }}
{{- end }}
{{- range $path, $bytes := .Files.Glob (printf "configs/uploader/%s/*.conf" $.Values.videoRecorder.uploader.name) }}
- name: {{ include "seleniumGrid.common.secrets" $ }}
mountPath: {{ $.Values.videoRecorder.uploader.scriptMountPath }}/{{ base $path }}
subPath: {{ base $path }}
{{- range $fileName, $value := .Values.uploaderConfigMap.secretFiles }}
- name: {{ tpl (toYaml $.Values.uploaderConfigMap.secretVolumeMountName) $ }}
mountPath: {{ $.Values.uploaderConfigMap.extraScriptsDirectory }}/{{ $fileName }}
subPath: {{ $fileName }}
{{- end }}
- name: {{ include "seleniumGrid.video.volume.name.folder" . }}
mountPath: /videos
- name: {{ tpl (toYaml $.Values.recorderConfigMap.videoVolumeMountName) $ }}
mountPath: {{ $.Values.videoRecorder.targetFolder }}
{{- end -}}

{{/* Combine videoRecorder.extraVolumeMounts with the default ones for container video recorder */}}
Expand All @@ -759,9 +754,9 @@ Default specs of VolumeMounts and Volumes for video recorder
{{- $videoVolumeMounts = append $videoVolumeMounts . -}}
{{- end -}}
{{- end -}}
{{- $defaultVolumeMounts := (include "seleniumGrid.video.volumeMounts.default" . | toString | fromYamlArray ) -}}
{{- $defaultVolumeMounts := (include "seleniumGrid.video.volumeMounts.default" $ | toString | fromYamlArray ) -}}
{{- $videoVolumeMounts = include "utils.appendDefaultIfNotExist" (dict "currentArray" $videoVolumeMounts "defaultArray" $defaultVolumeMounts "uniqueKey" "mountPath") -}}
{{- not $videoVolumeMounts | ternary $videoVolumeMounts "" -}}
{{- not (empty $videoVolumeMounts) | ternary $videoVolumeMounts "" -}}
{{- end -}}

{{/* Combine videoRecorder.uploader.extraVolumeMounts with the default ones for container video uploader */}}
Expand All @@ -774,7 +769,7 @@ Default specs of VolumeMounts and Volumes for video recorder
{{- end }}
{{- $defaultVolumeMounts := (include "seleniumGrid.video.uploader.volumeMounts.default" . | toString | fromYamlArray ) -}}
{{- $videoUploaderVolumeMounts = include "utils.appendDefaultIfNotExist" (dict "currentArray" $videoUploaderVolumeMounts "defaultArray" $defaultVolumeMounts "uniqueKey" "mountPath") -}}
{{- not $videoUploaderVolumeMounts | ternary $videoUploaderVolumeMounts "" -}}
{{- not (empty $videoUploaderVolumeMounts) | ternary $videoUploaderVolumeMounts "" -}}
{{- end -}}

{{/* Combine videoRecorder.extraVolumes with the default ones for the node pod */}}
Expand All @@ -787,7 +782,7 @@ Default specs of VolumeMounts and Volumes for video recorder
{{- end -}}
{{- $defaultVolumes := (include "seleniumGrid.video.volumes.default" . | toString | fromYamlArray ) -}}
{{- $videoVolumes = include "utils.appendDefaultIfNotExist" (dict "currentArray" $videoVolumes "defaultArray" $defaultVolumes "uniqueKey" "name") -}}
{{- not $videoVolumes | ternary $videoVolumes "" -}}
{{- not (empty $videoVolumes) | ternary $videoVolumes "" -}}
{{- end -}}

{{/*
Expand Down
14 changes: 9 additions & 5 deletions charts/selenium-grid/templates/node-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ metadata:
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" .}}'
UPLOAD_ENABLED: '{{ .Values.videoRecorder.uploader.enabled }}'
UPLOAD_DESTINATION_PREFIX: '{{ .Values.videoRecorder.uploader.destinationPrefix }}'
UPLOAD_CONFIG_FILE_NAME: '{{ .Values.videoRecorder.uploader.configFileName }}'
UPLOAD_CONFIG_DIRECTORY: '{{ .Values.videoRecorder.uploader.scriptMountPath }}'
{{ (.Files.Glob "configs/node/*").AsConfig | indent 2 }}
SE_NODE_GRID_GRAPHQL_URL: '{{ include "seleniumGrid.graphqlURL" .}}'
{{- range $fileName, $value := .Values.nodeConfigMap.extraScripts }}
{{- if not (empty $value) }}
{{ $fileName | indent 2 -}}: |
{{ $value | indent 4 }}
{{- else }}
{{ ($.Files.Glob (printf "configs/node/%s" $fileName)).AsConfig | indent 2 }}
{{- end }}
{{- end }}
27 changes: 27 additions & 0 deletions charts/selenium-grid/templates/recorder-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{- if .Values.videoRecorder.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.recorderConfigMap.name }}
namespace: {{ .Release.Namespace }}
{{- with .Values.recorderConfigMap.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "seleniumGrid.commonLabels" . | nindent 4 }}
{{- with .Values.customLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
data:
VIDEO_UPLOAD_ENABLED: '{{ .Values.videoRecorder.uploader.enabled }}'
VIDEO_CONFIG_DIRECTORY: '{{ .Values.recorderConfigMap.extraScriptsDirectory }}'
UPLOAD_DESTINATION_PREFIX: '{{ .Values.videoRecorder.uploader.destinationPrefix }}'
{{- range $fileName, $value := .Values.recorderConfigMap.extraScripts }}
{{- if not (empty $value) }}
{{ $fileName | indent 2 -}}: |
{{ $value | indent 4 }}
{{- else }}
{{ ($.Files.Glob (printf "configs/recorder/%s" $fileName)).AsConfig | indent 2 }}
{{- end }}
{{- end }}
{{- end }}
1 change: 0 additions & 1 deletion charts/selenium-grid/templates/router-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ spec:
{{- if .Values.components.router.livenessProbe.enabled }}
livenessProbe:
{{- with .Values.components.router.livenessProbe }}
livenessProbe:
{{- if (ne (include "seleniumGrid.probe.fromUserDefine" .) "{}") }}
{{- include "seleniumGrid.probe.fromUserDefine" . | nindent 10 }}
{{- else }}
Expand Down
12 changes: 8 additions & 4 deletions charts/selenium-grid/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ data:
{{- end }}
{{- end }}
{{- end }}
{{- if and .Values.videoRecorder.uploader.enabled .Values.videoRecorder.uploader.config }}
{{ .Values.videoRecorder.uploader.configFileName }}: {{ .Values.videoRecorder.uploader.config | b64enc }}
{{- else if and .Values.videoRecorder.uploader.enabled (not .Values.videoRecorder.uploader.config) }}
{{ (.Files.Glob (printf "configs/uploader/%s/*.conf" $.Values.videoRecorder.uploader.name)).AsSecrets | indent 2 }}
{{- if and .Values.videoRecorder.uploader.enabled }}
{{- range $fileName, $value := .Values.uploaderConfigMap.secretFiles }}
{{- if not (empty $value) }}
{{ $fileName }}: {{ $value | b64enc }}
{{- else }}
{{ ($.Files.Glob (printf "configs/uploader/%s/%s" $.Values.videoRecorder.uploader.name $fileName)).AsSecrets | indent 2 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
26 changes: 26 additions & 0 deletions charts/selenium-grid/templates/uploader-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- if .Values.videoRecorder.uploader.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.uploaderConfigMap.name }}
namespace: {{ .Release.Namespace }}
{{- with .Values.uploaderConfigMap.annotations }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "seleniumGrid.commonLabels" . | nindent 4 }}
{{- with .Values.customLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
data:
UPLOAD_CONFIG_DIRECTORY: '{{ .Values.uploaderConfigMap.extraScriptsDirectory }}'
UPLOAD_CONFIG_FILE_NAME: '{{ .Values.videoRecorder.uploader.configFileName }}'
{{- range $fileName, $value := .Values.uploaderConfigMap.extraScripts }}
{{- if not (empty $value) }}
{{ $fileName | indent 2 -}}: |
{{ $value | indent 4 }}
{{- else }}
{{ ($.Files.Glob (printf "configs/uploader/%s/%s" $.Values.videoRecorder.uploader.name $fileName)).AsConfig | indent 2 }}
{{- end }}
{{- end }}
{{- end }}
14 changes: 0 additions & 14 deletions charts/selenium-grid/templates/video-cm.yaml

This file was deleted.

Loading

0 comments on commit 6f5f75b

Please sign in to comment.