Skip to content

Commit

Permalink
Add telemetry support
Browse files Browse the repository at this point in the history
This commit enables the pulpcore API metrics collection.
closes #1006

Co-authored-by: André "decko" de Brito <[email protected]>
  • Loading branch information
2 people authored and openshift-merge-robot committed Jul 25, 2023
1 parent d21b05d commit d69e413
Show file tree
Hide file tree
Showing 21 changed files with 587 additions and 40 deletions.
21 changes: 21 additions & 0 deletions .ci/scripts/telemetry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -eu

DEPLOYMENT_NAME="example-pulp-api"


echo "Validating otel-collector-config file ..."
kubectl exec -c otel-collector-sidecar deployment/$DEPLOYMENT_NAME -- /otelcol validate --config=/etc/otelcol-contrib/otel-collector-config.yaml

echo "Verifying if metrics service is available ..."
HTTP_STATUS=$(kubectl exec deployment/$DEPLOYMENT_NAME -- curl -sw "%{http_code}" -o /dev/null localhost:8889/metrics)
if [[ "$HTTP_STATUS" != 200 ]]; then
echo "error: ${HTTP_STATUS}"
exit 1
fi

echo "Verifying if \"http_server\" string is found in metrics endpoint ..."
kubectl exec deployment/$DEPLOYMENT_NAME -- curl -s localhost:8889/metrics | grep http_server &>/dev/null

echo "Telemetry ok"
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ jobs:
fail-fast: false
matrix:
include:
- INGRESS_TYPE: ingress
- INGRESS_TYPE: nodeport
- COMPONENT_TYPE: ingress
- COMPONENT_TYPE: nodeport
- COMPONENT_TYPE: telemetry
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -255,7 +256,7 @@ jobs:
echo "HTTPIE_CONFIG_DIR=$GITHUB_WORKSPACE/.ci/assets/httpie/" >> $GITHUB_ENV
echo "CI_TEST=true" >> $GITHUB_ENV
echo "TEST=pulp" >> $GITHUB_ENV
echo "INGRESS_TYPE=${{ matrix.INGRESS_TYPE }}" >> $GITHUB_ENV
echo "COMPONENT_TYPE=${{ matrix.COMPONENT_TYPE }}" >> $GITHUB_ENV
shell: bash
- name: Updating registries configuration
run: |
Expand Down Expand Up @@ -313,8 +314,10 @@ jobs:
kubectl get namespace
kubectl config set-context --current --namespace=pulp-operator-system
kubectl apply -f .ci/assets/kubernetes/pulp-admin-password.secret.yaml
if [[ "$INGRESS_TYPE" == "ingress" ]]; then
if [[ "$COMPONENT_TYPE" == "ingress" ]]; then
kubectl apply -f config/samples/simple.ingress.yaml
elif [[ "$COMPONENT_TYPE" == "telemetry" ]]; then
kubectl apply -f config/samples/telemetry.yaml
else
kubectl apply -f config/samples/simple.yaml
fi
Expand All @@ -327,9 +330,13 @@ jobs:
run: .ci/scripts/kubelinter.sh
- name: Test all components
run: |
export INGRESS_TYPE=$COMPONENT_TYPE
git clone --depth=1 https://github.com/pulp/pulp_ansible.git
git clone --depth=1 https://github.com/pulp/pulp_container.git
.ci/scripts/pulp_tests.sh -m
if [[ "$COMPONENT_TYPE" == "telemetry" ]]; then
.ci/scripts/telemetry.sh
fi
shell: bash
env:
PY_COLORS: '1'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/scripts/show_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ kubectl describe pods -l app.kubernetes.io/component=api
echo ::endgroup::

echo ::group::PULP_API_LOGS
kubectl logs --timestamps -cinit-container -l app.kubernetes.io/component=api --tail=10000
kubectl logs --timestamps -l app.kubernetes.io/component=api --tail=10000
echo ::endgroup::

Expand Down
1 change: 1 addition & 0 deletions CHANGES/1006.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the OpenTelemetry support as sidecar container for pulp-api pods.
28 changes: 28 additions & 0 deletions apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ type PulpSpec struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced"}
NoLog bool `json:"no_log,omitempty"`

// Telemetry defines the OpenTelemetry configuration
// +kubebuilder:validation:Optional
Telemetry Telemetry `json:"telemetry,omitempty"`

ResourceManager ResourceManager `json:"resource_manager,omitempty"`
}

Expand Down Expand Up @@ -1032,6 +1036,28 @@ type ResourceManager struct {
ResourceRequirements *corev1.ResourceRequirements `json:"resource_requirements,omitempty"`
}

// Telemetry defines the configuration for OpenTelemetry used by Pulp
type Telemetry struct {

// Enable Pulp Telemetry
// Default: false
// +kubebuilder:default:=false
// +kubebuilder:validation:Optional
// +nullable
Enabled bool `json:"enabled,omitempty"`

// Defines the protocol used by the instrumentator to comunicate with the collector
// Default: http/protobuf
// +kubebuilder:default:="http/protobuf"
ExporterOtlpProtocol string `json:"exporter_otlp_protocol,omitempty"`

// Defines the image to be used as collector
OpenTelemetryCollectorImage string `json:"otel_collector_image,omitempty"`

// The image version for opentelemetry-collector image. Default: \"latest\"
OpenTelemetryCollectorImageVersion string `json:"otel_collector_image_version,omitempty"`
}

// PulpStatus defines the observed state of Pulp
type PulpStatus struct {
//+operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:io.kubernetes.conditions"}
Expand All @@ -1054,6 +1080,8 @@ type PulpStatus struct {
AdminPasswordSecret string `json:"admin_password_secret,omitempty"`
// Name of the secret with the parameters to connect to an external Redis cluster
ExternalCacheSecret string `json:"external_cache_secret,omitempty"`
// Pulp metrics collection enabled
TelemetryEnabled bool `json:"telemetry_enabled,omitempty"`

// [DEPRECATED] Temporarily adding to keep compatibility with ansible version.
StoragePersistentVolumeClaim string `json:"storagePersistentVolumeClaim,omitempty"`
Expand Down
16 changes: 16 additions & 0 deletions apis/repo-manager.pulpproject.org/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bundle/manifests/pulp-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ metadata:
capabilities: Full Lifecycle
categories: Integration & Delivery
containerImage: quay.io/pulp/pulp-operator:devel
createdAt: "2023-07-17T17:24:35Z"
createdAt: "2023-07-21T14:53:03Z"
description: Pulp is a platform for managing repositories of software packages
and making them available to a large number of consumers.
operators.operatorframework.io/builder: operator-sdk-v1.29.0
Expand Down
24 changes: 24 additions & 0 deletions bundle/manifests/repo-manager.pulpproject.org_pulps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25159,6 +25159,27 @@ spec:
- Azure
- azure
type: string
telemetry:
description: Telemetry defines the OpenTelemetry configuration
properties:
enabled:
default: false
description: 'Enable Pulp Telemetry Default: false'
nullable: true
type: boolean
exporter_otlp_protocol:
default: http/protobuf
description: 'Defines the protocol used by the instrumentator
to comunicate with the collector Default: http/protobuf'
type: string
otel_collector_image:
description: Defines the image to be used as collector
type: string
otel_collector_image_version:
description: 'The image version for opentelemetry-collector image.
Default: \"latest\"'
type: string
type: object
tolerations:
description: '[DEPRECATED] Temporarily adding to keep compatibility
with ansible version. Node tolerations for the Pulp pods.'
Expand Down Expand Up @@ -27621,6 +27642,9 @@ spec:
type: string
storageType:
type: string
telemetry_enabled:
description: Pulp metrics collection enabled
type: boolean
upgradedPostgresVersion:
type: string
webURL:
Expand Down
24 changes: 24 additions & 0 deletions config/crd/bases/repo-manager.pulpproject.org_pulps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25160,6 +25160,27 @@ spec:
- Azure
- azure
type: string
telemetry:
description: Telemetry defines the OpenTelemetry configuration
properties:
enabled:
default: false
description: 'Enable Pulp Telemetry Default: false'
nullable: true
type: boolean
exporter_otlp_protocol:
default: http/protobuf
description: 'Defines the protocol used by the instrumentator
to comunicate with the collector Default: http/protobuf'
type: string
otel_collector_image:
description: Defines the image to be used as collector
type: string
otel_collector_image_version:
description: 'The image version for opentelemetry-collector image.
Default: \"latest\"'
type: string
type: object
tolerations:
description: '[DEPRECATED] Temporarily adding to keep compatibility
with ansible version. Node tolerations for the Pulp pods.'
Expand Down Expand Up @@ -27622,6 +27643,9 @@ spec:
type: string
storageType:
type: string
telemetry_enabled:
description: Pulp metrics collection enabled
type: boolean
upgradedPostgresVersion:
type: string
webURL:
Expand Down
30 changes: 30 additions & 0 deletions config/samples/telemetry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: repo-manager.pulpproject.org/v1beta2
kind: Pulp
metadata:
name: example-pulp
spec:
telemetry:
enabled: true
image_version: stable
image_web_version: stable
api:
replicas: 1
content:
replicas: 1
worker:
replicas: 1
web:
replicas: 1
database:
postgres_storage_class: standard
file_storage_access_mode: "ReadWriteOnce"
file_storage_size: "2Gi"
file_storage_storage_class: standard
ingress_type: nodeport
pulp_settings:
api_root: "/pulp/"
allowed_export_paths:
- /tmp
allowed_import_paths:
- /tmp
analytics: false
75 changes: 58 additions & 17 deletions controllers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,60 @@ func (DeploymentAPICommon) Deploy(resources any) client.Object {
image = "quay.io/pulp/pulp-minimal:stable"
}

initContainers := []corev1.Container{
{
Name: "init-container",
Image: image,
Env: envVars,
Command: []string{"/bin/sh"},
Args: []string{
"-c",
`mkdir -p /var/lib/pulp/{media,assets,tmp}
/usr/bin/wait_on_postgres.py
/usr/local/bin/pulpcore-manager migrate --noinput
ADMIN_PASSWORD_FILE=/etc/pulp/pulp-admin-password
if [[ -f "$ADMIN_PASSWORD_FILE" ]]; then
echo "pulp admin can be initialized."
PULP_ADMIN_PASSWORD=$(cat $ADMIN_PASSWORD_FILE)
fi
if [ -n "${PULP_ADMIN_PASSWORD}" ]; then
/usr/local/bin/pulpcore-manager reset-admin-password --password "${PULP_ADMIN_PASSWORD}"
fi`,
},
VolumeMounts: volumeMounts,
},
}

containers := []corev1.Container{
{
Name: "api",
Image: image,
ImagePullPolicy: corev1.PullPolicy(pulp.Spec.ImagePullPolicy),
Command: []string{"/bin/sh"},
Args: []string{
"-c",
`exec gunicorn --bind '[::]:24817' pulpcore.app.wsgi:application --name pulp-api --timeout "${PULP_GUNICORN_TIMEOUT}" --workers "${PULP_API_WORKERS}"`,
},
Env: envVars,
Ports: []corev1.ContainerPort{{
ContainerPort: 24817,
Protocol: "TCP",
}},
LivenessProbe: livenessProbe,
ReadinessProbe: readinessProbe,
Resources: resourceRequirements,
VolumeMounts: volumeMounts,
},
}

podAnnotations := map[string]string{
"kubectl.kubernetes.io/default-container": "api",
}

if pulp.Spec.Telemetry.Enabled {
containers, volumes = telemetryConfig(resources, envVars, containers, volumes)
}

// deployment definition
dep := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -581,7 +635,8 @@ func (DeploymentAPICommon) Deploy(resources any) client.Object {
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: ls,
Labels: ls,
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
Affinity: affinity,
Expand All @@ -591,22 +646,8 @@ func (DeploymentAPICommon) Deploy(resources any) client.Object {
Volumes: volumes,
ServiceAccountName: pulp.Name,
TopologySpreadConstraints: topologySpreadConstraint,
Containers: []corev1.Container{{
Name: "api",
Image: image,
ImagePullPolicy: corev1.PullPolicy(pulp.Spec.ImagePullPolicy),
Args: []string{"pulp-api"},
Env: envVars,
Ports: []corev1.ContainerPort{{
ContainerPort: 24817,
Protocol: "TCP",
}},
LivenessProbe: livenessProbe,
ReadinessProbe: readinessProbe,
Resources: resourceRequirements,
VolumeMounts: volumeMounts,
}},

InitContainers: initContainers,
Containers: containers,
/* the following configs are not defined on pulp-operator (ansible version) */
/* but i'll keep it here just in case we can manage to make deepequal usable */
RestartPolicy: restartPolicy,
Expand Down
Loading

0 comments on commit d69e413

Please sign in to comment.