|
| 1 | +name: CI - Test prometheus-cvmfs-exporter |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test-debian-ubuntu: |
| 11 | + name: Test DEB Package on Ubuntu |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Setup CernVM-FS |
| 19 | + uses: cvmfs-contrib/github-action-cvmfs@v4 |
| 20 | + with: |
| 21 | + cvmfs_repositories: 'sft.cern.ch,sw.hsf.org' |
| 22 | + cvmfs_http_proxy: 'DIRECT' |
| 23 | + |
| 24 | + - name: Verify CVMFS is working |
| 25 | + run: | |
| 26 | + echo "Testing CVMFS access..." |
| 27 | + ls -la /cvmfs/ |
| 28 | + timeout 30 ls /cvmfs/sft.cern.ch/ || echo "CVMFS access test completed" |
| 29 | + |
| 30 | + - name: Install build dependencies |
| 31 | + run: | |
| 32 | + sudo apt-get update |
| 33 | + sudo apt-get install -y \ |
| 34 | + build-essential \ |
| 35 | + debhelper \ |
| 36 | + devscripts \ |
| 37 | + dpkg-dev \ |
| 38 | + systemd \ |
| 39 | + curl \ |
| 40 | + attr \ |
| 41 | + bc |
| 42 | + |
| 43 | + - name: Build DEB package |
| 44 | + run: | |
| 45 | + echo "Building DEB package..." |
| 46 | + make clean |
| 47 | + make deb |
| 48 | + |
| 49 | + - name: Verify DEB package contents |
| 50 | + run: | |
| 51 | + echo "Checking DEB package contents..." |
| 52 | + dpkg -c build/prometheus-cvmfs-exporter_*.deb |
| 53 | + dpkg -I build/prometheus-cvmfs-exporter_*.deb |
| 54 | + |
| 55 | + - name: Install DEB package |
| 56 | + run: | |
| 57 | + echo "Installing DEB package..." |
| 58 | + sudo dpkg -i build/prometheus-cvmfs-exporter_*.deb || true |
| 59 | + sudo apt-get install -f -y |
| 60 | + |
| 61 | + - name: Verify installation |
| 62 | + run: | |
| 63 | + echo "Verifying installation..." |
| 64 | + ls -la /usr/libexec/cvmfs/cvmfs-prometheus.sh |
| 65 | + ls -la /usr/lib/systemd/system/cvmfs-client-prometheus* |
| 66 | + |
| 67 | + - name: Test script functionality |
| 68 | + run: | |
| 69 | + echo "Testing script functionality..." |
| 70 | + # Test script help |
| 71 | + /usr/libexec/cvmfs/cvmfs-prometheus.sh --help || true |
| 72 | + |
| 73 | + # Test script execution (may fail without proper CVMFS setup, but should not crash) |
| 74 | + timeout 10 /usr/libexec/cvmfs/cvmfs-prometheus.sh || echo "Script execution test completed" |
| 75 | + |
| 76 | + - name: Start systemd services |
| 77 | + run: | |
| 78 | + echo "Starting systemd services..." |
| 79 | + sudo systemctl daemon-reload |
| 80 | + sudo systemctl enable cvmfs-client-prometheus.socket |
| 81 | + sudo systemctl start cvmfs-client-prometheus.socket |
| 82 | + sudo systemctl status cvmfs-client-prometheus.socket --no-pager |
| 83 | + |
| 84 | + - name: Test metrics endpoint |
| 85 | + run: | |
| 86 | + echo "Testing metrics endpoint..." |
| 87 | + # Wait for socket to be ready |
| 88 | + sleep 5 |
| 89 | + |
| 90 | + # Test the metrics endpoint with timeout and timing |
| 91 | + echo "Attempting to connect to localhost:9868..." |
| 92 | + start_time=$(date +%s.%N) |
| 93 | + |
| 94 | + # Use curl with timeout and proper error handling |
| 95 | + if timeout 30 curl -f -s http://localhost:9868 > metrics_output.txt; then |
| 96 | + end_time=$(date +%s.%N) |
| 97 | + response_time=$(echo "$end_time - $start_time" | bc) |
| 98 | + echo "✅ Metrics endpoint responded successfully in ${response_time} seconds" |
| 99 | + |
| 100 | + # Verify Prometheus metrics format |
| 101 | + if grep -q "^# HELP" metrics_output.txt && grep -q "^# TYPE" metrics_output.txt; then |
| 102 | + echo "✅ Response contains valid Prometheus metrics format" |
| 103 | + echo "Sample metrics:" |
| 104 | + head -20 metrics_output.txt |
| 105 | + else |
| 106 | + echo "❌ Response does not contain valid Prometheus metrics" |
| 107 | + echo "Response content:" |
| 108 | + cat metrics_output.txt |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | + else |
| 112 | + echo "❌ Failed to connect to metrics endpoint" |
| 113 | + echo "Checking service status..." |
| 114 | + sudo systemctl status cvmfs-client-prometheus.socket --no-pager || true |
| 115 | + sudo journalctl -u cvmfs-client-prometheus.socket --no-pager -n 20 || true |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | + |
| 119 | + - name: Upload DEB package artifact |
| 120 | + uses: actions/upload-artifact@v4 |
| 121 | + if: always() |
| 122 | + with: |
| 123 | + name: deb-package |
| 124 | + path: build/prometheus-cvmfs-exporter_*.deb |
| 125 | + retention-days: 7 |
| 126 | + |
| 127 | + test-rpm-almalinux: |
| 128 | + name: Test RPM Package on AlmaLinux |
| 129 | + runs-on: ubuntu-latest |
| 130 | + |
| 131 | + services: |
| 132 | + almalinux: |
| 133 | + image: almalinux:9 |
| 134 | + options: >- |
| 135 | + --privileged |
| 136 | + --cgroupns=host |
| 137 | + volumes: |
| 138 | + - /sys/fs/cgroup:/sys/fs/cgroup:rw |
| 139 | + |
| 140 | + steps: |
| 141 | + - name: Checkout repository |
| 142 | + uses: actions/checkout@v4 |
| 143 | + |
| 144 | + - name: Setup AlmaLinux container with systemd |
| 145 | + run: | |
| 146 | + # Create a container with systemd support |
| 147 | + docker run -d \ |
| 148 | + --name almalinux-test \ |
| 149 | + --privileged \ |
| 150 | + --cgroupns=host \ |
| 151 | + -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ |
| 152 | + -v $PWD:/workspace \ |
| 153 | + -w /workspace \ |
| 154 | + almalinux:9 \ |
| 155 | + /usr/sbin/init |
| 156 | +
|
| 157 | + # Wait for container to be ready |
| 158 | + sleep 5 |
| 159 | +
|
| 160 | + # Verify container is running |
| 161 | + docker ps |
| 162 | +
|
| 163 | + - name: Install dependencies in container |
| 164 | + run: | |
| 165 | + docker exec almalinux-test bash -c " |
| 166 | + # Install EPEL and basic tools |
| 167 | + dnf install -y epel-release |
| 168 | + dnf update -y |
| 169 | +
|
| 170 | + # Install CVMFS |
| 171 | + dnf install -y https://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest.noarch.rpm |
| 172 | + dnf install -y cvmfs cvmfs-config-default |
| 173 | +
|
| 174 | + # Install build tools and dependencies |
| 175 | + dnf install -y --allowerasing \ |
| 176 | + rpm-build \ |
| 177 | + make \ |
| 178 | + systemd \ |
| 179 | + curl \ |
| 180 | + attr \ |
| 181 | + bc \ |
| 182 | + findutils \ |
| 183 | + grep \ |
| 184 | + coreutils \ |
| 185 | + util-linux |
| 186 | + " |
| 187 | +
|
| 188 | + - name: Setup CVMFS in container |
| 189 | + run: | |
| 190 | + docker exec almalinux-test bash -c " |
| 191 | + # Configure CVMFS |
| 192 | + echo 'CVMFS_REPOSITORIES=sft.cern.ch,sw.hsf.org' > /etc/cvmfs/default.local |
| 193 | + echo 'CVMFS_HTTP_PROXY=DIRECT' >> /etc/cvmfs/default.local |
| 194 | + echo 'CVMFS_CLIENT_PROFILE=single' >> /etc/cvmfs/default.local |
| 195 | + echo 'CVMFS_USE_CDN=yes' >> /etc/cvmfs/default.local |
| 196 | +
|
| 197 | + # Setup CVMFS |
| 198 | + cvmfs_config setup |
| 199 | +
|
| 200 | + # Test CVMFS access |
| 201 | + timeout 30 ls /cvmfs/sft.cern.ch/ || echo 'CVMFS access test completed' |
| 202 | + " |
| 203 | +
|
| 204 | + - name: Build RPM package in container |
| 205 | + run: | |
| 206 | + docker exec almalinux-test bash -c " |
| 207 | + cd /workspace |
| 208 | + echo 'Building RPM package...' |
| 209 | + make clean |
| 210 | + make rpm |
| 211 | + " |
| 212 | +
|
| 213 | + - name: Verify RPM package contents |
| 214 | + run: | |
| 215 | + docker exec almalinux-test bash -c " |
| 216 | + cd /workspace |
| 217 | + echo 'Checking RPM package contents...' |
| 218 | + rpm -qlp build/rpm/RPMS/noarch/prometheus-cvmfs-exporter-*.rpm |
| 219 | + rpm -qip build/rpm/RPMS/noarch/prometheus-cvmfs-exporter-*.rpm |
| 220 | + " |
| 221 | +
|
| 222 | + - name: Install RPM package in container |
| 223 | + run: | |
| 224 | + docker exec almalinux-test bash -c " |
| 225 | + cd /workspace |
| 226 | + echo 'Installing RPM package...' |
| 227 | + rpm -ivh build/rpm/RPMS/noarch/prometheus-cvmfs-exporter-*.rpm |
| 228 | + " |
| 229 | +
|
| 230 | + - name: Verify installation in container |
| 231 | + run: | |
| 232 | + docker exec almalinux-test bash -c " |
| 233 | + echo 'Verifying installation...' |
| 234 | + ls -la /usr/libexec/cvmfs/cvmfs-prometheus.sh |
| 235 | + ls -la /usr/lib/systemd/system/cvmfs-client-prometheus* |
| 236 | + " |
| 237 | +
|
| 238 | + - name: Test script functionality in container |
| 239 | + run: | |
| 240 | + docker exec almalinux-test bash -c " |
| 241 | + echo 'Testing script functionality...' |
| 242 | + # Test script help |
| 243 | + /usr/libexec/cvmfs/cvmfs-prometheus.sh --help || true |
| 244 | +
|
| 245 | + # Test script execution (may fail without proper CVMFS setup, but should not crash) |
| 246 | + timeout 10 /usr/libexec/cvmfs/cvmfs-prometheus.sh || echo 'Script execution test completed' |
| 247 | + " |
| 248 | +
|
| 249 | + - name: Start systemd services in container |
| 250 | + run: | |
| 251 | + docker exec almalinux-test bash -c " |
| 252 | + echo 'Starting systemd services...' |
| 253 | + systemctl daemon-reload |
| 254 | + systemctl enable cvmfs-client-prometheus.socket |
| 255 | + systemctl start cvmfs-client-prometheus.socket |
| 256 | + systemctl status cvmfs-client-prometheus.socket --no-pager |
| 257 | + " |
| 258 | +
|
| 259 | + - name: Test metrics endpoint in container |
| 260 | + run: | |
| 261 | + docker exec almalinux-test bash -c " |
| 262 | + echo 'Testing metrics endpoint...' |
| 263 | + # Wait for socket to be ready |
| 264 | + sleep 5 |
| 265 | +
|
| 266 | + # Test the metrics endpoint with timeout and timing |
| 267 | + echo 'Attempting to connect to localhost:9868...' |
| 268 | + start_time=\$(date +%s.%N) |
| 269 | +
|
| 270 | + # Use curl with timeout and proper error handling |
| 271 | + if timeout 30 curl -f -s http://localhost:9868 > metrics_output.txt; then |
| 272 | + end_time=\$(date +%s.%N) |
| 273 | + response_time=\$(echo \"\$end_time - \$start_time\" | bc) |
| 274 | + echo \"✅ Metrics endpoint responded successfully in \${response_time} seconds\" |
| 275 | +
|
| 276 | + # Verify Prometheus metrics format |
| 277 | + if grep -q \"^# HELP\" metrics_output.txt && grep -q \"^# TYPE\" metrics_output.txt; then |
| 278 | + echo \"✅ Response contains valid Prometheus metrics format\" |
| 279 | + echo \"Sample metrics:\" |
| 280 | + head -20 metrics_output.txt |
| 281 | + else |
| 282 | + echo \"❌ Response does not contain valid Prometheus metrics\" |
| 283 | + echo \"Response content:\" |
| 284 | + cat metrics_output.txt |
| 285 | + exit 1 |
| 286 | + fi |
| 287 | + else |
| 288 | + echo \"❌ Failed to connect to metrics endpoint\" |
| 289 | + echo \"Checking service status...\" |
| 290 | + systemctl status cvmfs-client-prometheus.socket --no-pager || true |
| 291 | + journalctl -u cvmfs-client-prometheus.socket --no-pager -n 20 || true |
| 292 | + exit 1 |
| 293 | + fi |
| 294 | + " |
| 295 | +
|
| 296 | + - name: Cleanup container |
| 297 | + if: always() |
| 298 | + run: | |
| 299 | + docker stop almalinux-test || true |
| 300 | + docker rm almalinux-test || true |
| 301 | +
|
| 302 | + - name: Upload RPM package artifact |
| 303 | + uses: actions/upload-artifact@v4 |
| 304 | + if: always() |
| 305 | + with: |
| 306 | + name: rpm-package |
| 307 | + path: build/rpm/RPMS/noarch/prometheus-cvmfs-exporter-*.rpm |
| 308 | + retention-days: 7 |
0 commit comments