Skip to content

Commit

Permalink
feat: monitoring for target host and guest machine from tekton task
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Riobo Lorenzo <ariobolo@redhat.com>
  • Loading branch information
adrianriobo committed Feb 8, 2024
1 parent a9242cb commit cbb84ad
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 31 deletions.
7 changes: 6 additions & 1 deletion oci/lib/darwin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ backend_podman () {
fi
${PODMAN_BINARY} machine init ${PODMAN_OPTS}
${PODMAN_BINARY} machine start

if [[ ${MONITORING_ENABLE} == 'true' ]]
${PODMAN_BINARY} machine ssh 'podman run -d -p 9200:9100 -v "/:/host:ro,rslave" quay.io/prometheus/node-exporter:latest --path.rootfs=/host'
fi
fi
}

Expand Down Expand Up @@ -123,7 +127,8 @@ PODMAN_START="${PODMAN_START:-"false"}"
PODMAN_PROVIDER="${PODMAN_PROVIDER:-"qemu"}"
# Passing possible options for the podman machine init (i.e --rootful --user-mode-networking)
PODMAN_OPTS="${PODMAN_OPTS:-""}"

# If enable it will run node exporter insde the guest machine
MONITORING_ENABLE="${MONITORING_ENABLE:-"false"}"

# Prepare the backend
case "${BACKEND}" in
Expand Down
9 changes: 8 additions & 1 deletion oci/lib/windows/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ param(
[Parameter(HelpMessage='Set the podman machine provider (wsl or hyperv)), default wsl ')]
$podmanProvider="wsl",
[Parameter(HelpMessage='Check if wsl is installed if not it will install, default false.')]
$wslInstallFix="false"
$wslInstallFix="false",
[Parameter(HelpMessage=' If enable it will run node exporter insde the guest machine, default false.')]
$monitoringEnable="false"
)

function Backend-CRC-Podman {
Expand Down Expand Up @@ -80,6 +82,11 @@ function Backend-Podman {
set CONTAINERS_MACHINE_PROVIDER=$podmanProvider
podman machine init $podmanOpts
podman machine start

if ( $monitoringEnable -match 'true' )
{
podman machine ssh 'podman run -d -p 9200:9100 -v "/:/host:ro,rslave" quay.io/prometheus/node-exporter:latest --path.rootfs=/host'
}
}
}

Expand Down
74 changes: 45 additions & 29 deletions tkn/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ spec:
- name: cleanup-target
description: remove all assets moved into the target host
default: 'true'
- name: monitoring-enabled
description: If true will run node exporter on target host and guest machine and collect metrics during e2e execution
default: 'false'

results:
- name: duration
Expand Down Expand Up @@ -145,6 +148,7 @@ spec:
if [[ $(params.podman-opts) != "" ]]; then
cmd="$cmd -podmanOpts $(params.podman-opts) "
fi
cmd="$cmd -monitoringEnable $(params.monitoring-enabled) "
;;
darwin)
Expand All @@ -162,6 +166,7 @@ spec:
if [[ $(params.podman-opts) != "" ]]; then
cmd="$cmd PODMAN_OPTS=$(params.podman-opts) "
fi
cmd="$cmd MONITORING_ENABLE=$(params.monitoring-enabled) "
cmd="$cmd ${TARGET_FOLDER}/run.sh"
;;
Expand All @@ -174,16 +179,18 @@ spec:
# Exec
. entrypoint.sh "${cmd}"
# Create snapshot with performance metrics during e2e
curl -XPOST localhost:9090/api/v1/admin/tsdb/snapshot > snaphost-creation.json
# Use jq to get the snapshot compress and change name
# https://github.com/adrianriobo/deliverest/issues/26
apk add jq
snap_id=$(jq -r '.data.name' snaphost-creation.json)
# Check content
pushd $(workspaces.pipelines-data.path)/$(params.workspace-resources-path)/tmp-prom-$(params.podman-provider)/snapshots
tar -zcvf prom-$(params.podman-provider).tar.gz ${snap_id}
cp prom-$(params.podman-provider).tar.gz $(workspaces.pipelines-data.path)/$(params.workspace-resources-path)/$(params.worspace-qe-subpath)
if [[ $(params.monitoring-enabled) == "true" ]]; then
# Create snapshot with performance metrics during e2e
curl -XPOST localhost:9090/api/v1/admin/tsdb/snapshot > snaphost-creation.json
# Use jq to get the snapshot compress and change name
# https://github.com/adrianriobo/deliverest/issues/26
apk add jq
snap_id=$(jq -r '.data.name' snaphost-creation.json)
# Check content
pushd $(workspaces.pipelines-data.path)/$(params.workspace-resources-path)/tmp-prom-$(params.podman-provider)/snapshots
tar -zcvf prom-$(params.podman-provider).tar.gz ${snap_id}
cp prom-$(params.podman-provider).tar.gz $(workspaces.pipelines-data.path)/$(params.workspace-resources-path)/$(params.worspace-qe-subpath)
fi
# Results
echo -n "${SECONDS}" | tee $(results.duration.path)
Expand All @@ -204,30 +211,39 @@ spec:
set -exuo
if [[ $(params.monitoring-enabled) == "true" ]]; then
cat <<EOF > /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: $(params.podman-provider)
static_configs:
- targets: ['$(params.host):9100']
labels:
provider: $(params.podman-provider)
os: $(params.os)
osversion: $(params.os-version)
arch: $(params.arch)
global:
scrape_interval: 15s
scrape_configs:
- job_name: $(params.podman-provider)
static_configs:
- targets: ['$(params.host):9100']
labels:
provider: $(params.podman-provider)
os: $(params.os)
osversion: $(params.os-version)
arch: $(params.arch)
target: host
- targets: ['$(params.host):9200']
labels:
provider: $(params.podman-provider)
os: $(params.os)
osversion: $(params.os-version)
arch: $(params.arch)
target: machine
EOF
DATA_FOLDER="$(workspaces.pipelines-data.path)/$(params.workspace-resources-path)/tmp-prom-$(params.podman-provider)"
mkdir -p "${DATA_FOLDER}"
# Run prometheus to scrap the metrics while running tests
exec prometheus --config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path="${DATA_FOLDER}" \
--web.enable-admin-api
DATA_FOLDER="$(workspaces.pipelines-data.path)/$(params.workspace-resources-path)/tmp-prom-$(params.podman-provider)"
mkdir -p "${DATA_FOLDER}"
# Run prometheus to scrap the metrics while running tests
exec prometheus --config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path="${DATA_FOLDER}" \
--web.enable-admin-api
fi
volumeMounts:
- name: $(workspaces.pipelines-data.volume)
mountPath: $(workspaces.pipelines-data.path)
Expand Down

0 comments on commit cbb84ad

Please sign in to comment.