Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COSI-46 expose metrics service in kubernetes and E2E test #72

Open
wants to merge 5 commits into
base: feature/COSI-19-add-s3-and-iam-metrics
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/scripts/e2e_tests_metrics_service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -e

LOG_FILE=".github/e2e_tests/artifacts/logs/e2e_tests/metrics_service.log"
mkdir -p "$(dirname "$LOG_FILE")"

NAMESPACE="scality-object-storage"
SERVICE="scality-cosi-metrics"
LOCAL_PORT=8080
TARGET_PORT=8080

# Error handling function
error_handler() {
echo "An error occurred during bucket creation tests. Check the log file for details." | tee -a "$LOG_FILE"
echo "Failed command: $BASH_COMMAND" | tee -a "$LOG_FILE"
exit 1
}

# Trap errors and call the error handler
trap 'error_handler' ERR

# Log command execution to the log file for debugging
log_and_run() {
"$@" 2>&1 | tee -a "$LOG_FILE"
}
Comment on lines +22 to +25

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be replaced with the set -x option on bash


log_and_run kubectl describe svc scality-cosi-driver-metrics -n scality-object-storage

log_and_run kubectl port-forward svc/scality-cosi-driver-metrics -n scality-object-storage 8080:8080 &
PORT_FORWARD_PID=$!

if ps -p $PORT_FORWARD_PID > /dev/null; then
log_and_run echo "Port-forwarding established. Querying metrics..."

log_and_run curl -f http://localhost:$LOCAL_PORT/metrics > metrics_output.txt

if [ $? -eq 0 ]; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might lose the curl return code with the pipe | tee
https://unix.stackexchange.com/a/14276

log_and_run echo "Metrics fetched successfully. Metrics output:"
log_and_run cat metrics_output.txt
METRICS_WORKING=true
else
log_and_run echo "Failed to fetch metrics from http://localhost:$LOCAL_PORT/metrics"
METRICS_WORKING=false
fi

log_and_run kill $PORT_FORWARD_PID
else
log_and_run echo "Port-forwarding failed to establish."
METRICS_WORKING=false
fi

if [ "$METRICS_WORKING" = true ]; then
log_and_run echo "Metrics service is working as expected."
exit 0
else
log_and_run echo "Metrics service is not working as expected."
exit 1
fi

4 changes: 4 additions & 0 deletions .github/workflows/ci-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ jobs:
run: |
.github/scripts/e2e_tests_brownfield_use_case.sh

- name: E2E tests for metrics service using kustomize
run: |
.github/scripts/e2e_tests_metrics_service.sh

- name: "Delay completion"
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
uses: scality/actions/[email protected]
Expand Down
5 changes: 5 additions & 0 deletions helm/scality-cosi-driver/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/part-of: container-object-storage-interface
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/metrics"

spec:
replicas: {{ .Values.replicaCount }}
Expand All @@ -27,6 +31,7 @@ spec:
args:
- "--driver-prefix=cosi"
- "--v={{ .Values.logLevels.driver }}"
- "--metrics-address=0.0.0.0:8080"
resources:
limits:
cpu: {{ .Values.resources.limits.cpu }}
Expand Down
16 changes: 16 additions & 0 deletions helm/scality-cosi-driver/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "scality-cosi-driver.fullname" . }}-metrics
labels:
app.kubernetes.io/name: {{ include "scality-cosi-driver.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/part-of: container-object-storage-interface
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
selector:
app.kubernetes.io/name: {{ include "scality-cosi-driver.name" . }}
ports:
- protocol: TCP
port: {{ .Values.metrics.port }}
targetPort: {{ .Values.metrics.port }}
Copy link

@BourgoisMickael BourgoisMickael Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline at end of some files

4 changes: 4 additions & 0 deletions helm/scality-cosi-driver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ serviceAccount:
name: scality-object-storage-provisioner
create: true

metrics:
enabled: true
port: 8080


resources:
limits:
Expand Down
5 changes: 5 additions & 0 deletions kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ spec:
app.kubernetes.io/component: driver
app.kubernetes.io/version: main
app.kubernetes.io/managed-by: kustomize
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/metrics"
spec:
serviceAccountName: scality-object-storage-provisioner
containers:
Expand All @@ -24,6 +28,7 @@ spec:
args:
- "--driver-prefix=cosi"
- "--v=$(COSI_DRIVER_LOG_LEVEL)"
- "--metrics-address=0.0.0.0:8080"
volumeMounts:
- mountPath: /var/lib/cosi
name: socket
Expand Down
1 change: 1 addition & 0 deletions kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ resources:
- serviceaccount.yaml
- rbac.yaml
- deployment.yaml
- metrics-service.yaml
14 changes: 14 additions & 0 deletions kustomize/base/metrics-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: scality-cosi-metrics
labels:
app.kubernetes.io/name: scality-cosi-driver
app.kubernetes.io/part-of: container-object-storage-interface
spec:
selector:
app.kubernetes.io/name: scality-cosi-driver
ports:
- protocol: TCP
port: 8080 # The port Prometheus will scrape
targetPort: 8080 # The port exposed by the container
3 changes: 3 additions & 0 deletions kustomize/base/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ rules:
- apiGroups: [""]
resources: ["secrets", "events"]
verbs: ["get", "delete", "update", "create"]
- apiGroups: [""]
resources: ["services", "endpoints"]
verbs: ["get", "list", "watch"]

---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
1 change: 1 addition & 0 deletions kustomize/overlays/dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ resources:
- ../../base/namespace.yaml
- ../../base/serviceaccount.yaml
- ../../base/rbac.yaml
- ../../metrics-service.yaml

commonLabels:
app.kubernetes.io/version: main
Expand Down
Loading