-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect-metrics-job.yaml
125 lines (104 loc) · 3.3 KB
/
collect-metrics-job.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-collector
namespace: default
---
apiVersion: v1
kind: ConfigMap
metadata:
name: run-script
namespace: default
data:
setup_and_run.sh: |
#!/bin/bash
set -e
# Log script start
echo "Starting setup_and_run.sh script..."
# Record start time
START_TIME=$(date +%s)
# Install dependencies
echo "Updating package list and installing required packages..."
apt-get update
apt-get install -y git curl apt-transport-https ca-certificates
# Install kubectl
echo "Downloading and installing kubectl..."
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
# Verify kubectl installation
echo "Verifying kubectl installation..."
kubectl version --client || { echo "kubectl installation failed"; exit 1; }
# Install Python dependencies
echo "Installing Python dependencies..."
pip install --no-cache-dir requests pandas matplotlib plotly numpy
# Clean and decode the Git token
echo "Decoding GIT_TOKEN..."
DECODED_TOKEN=$(echo -n "${GIT_TOKEN}" | tr -d '\n' | base64 -d | tr -d '\n')
# Clone the repository
echo "Cloning repository..."
git clone "https://${DECODED_TOKEN}@github.com/armosec/perfornamce.git" /workspace
cd /workspace
# Configure Git for committing results
echo "Configuring Git..."
git config --global user.email "[email protected]"
git config --global user.name "bvolovat"
# Wait for 5 minutes (simulated delay)
echo "Waiting for 5 minutes before running tests..."
sleep 5m
# Calculate exact duration
END_TIME=$(date +%s)
EXACT_DURATION=$(( ($END_TIME - $START_TIME) / 60 ))
echo "Exact test duration: ${EXACT_DURATION} minutes"
export EXACT_DURATION
# Create output directory
echo "Creating output directory..."
mkdir -p output
# Run the tests
echo "Running tests with exact duration of ${EXACT_DURATION} minutes..."
EXACT_DURATION=${EXACT_DURATION} python get_data_from_prometheus.py
EXACT_DURATION=${EXACT_DURATION} python get_data_from_pyroscope.py
python parse_pyroscope_data.py
# Push the results
echo "Pushing results to repository..."
git add output/
git commit -m "Add test results from cluster run - Duration: ${EXACT_DURATION}m"
git push origin main
echo "Test execution complete. Results have been pushed to the repository."
---
apiVersion: batch/v1
kind: Job
metadata:
name: metrics-test
namespace: default
spec:
backoffLimit: 3
template:
spec:
serviceAccountName: metrics-collector
containers:
- name: metrics-collector
image: python:3.9-slim
command: ["/bin/bash", "/scripts/setup_and_run.sh"]
env:
- name: GIT_TOKEN
valueFrom:
secretKeyRef:
name: git-auth
key: token
volumeMounts:
- name: run-script
mountPath: /scripts
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "1"
volumes:
- name: run-script
configMap:
name: run-script
defaultMode: 0777
restartPolicy: Never