Skip to content

Conversation

@spbolton
Copy link
Contributor

@spbolton spbolton commented Aug 26, 2025

Description

This PR adds comprehensive Prometheus metrics scraping support to the DotCMS Helm chart, enabling automated discovery and monitoring of DotCMS pods by Prometheus. The implementation provides full configurability while maintaining backward compatibility.

Changes

📊 Prometheus Configuration (values.yaml)

  • Added new prometheus configuration section with full control over scraping behavior
  • Configurable scrape annotations: scrape, port, and path
  • Default values: scrape: "true", port: "8090", path: "/dotmgt/metrics"
  • Feature can be completely disabled via prometheus.enabled: false

🏷️ Pod Annotations (statefulset.yaml)

  • Conditional Prometheus annotations added to StatefulSet pod template
  • Annotations only applied when prometheus.enabled: true
  • Standard Prometheus discovery annotations: prometheus.io/scrape, prometheus.io/port, prometheus.io/path

🔧 Helper Functions (_helpers.tpl)

  • Created reusable dotcms.version helper function for consistent version handling
  • Special case handling: "1.0.0-SNAPSHOT""SNAPSHOT" for cleaner version labels
  • Extended environment variable rendering to support Kubernetes downward API via FIELD: prefix
  • Enhanced secret and field reference handling in environment variable processing

🏃‍♂️ Environment Variables for Metrics Tagging

When Prometheus is enabled, the following environment variables are automatically injected for consistent metric labeling:

  • DOT_METRICS_TAG_APP - Application name (e.g., "dotcms")
  • DOT_METRICS_TAG_ENV - Environment name (e.g., "prod")
  • DOT_METRICS_TAG_VER - Version tag (truncated, e.g., "21.06.14" or "SNAPSHOT")
  • DOT_METRICS_TAG_CUST - Customer name (e.g., "dotcms-dev")
  • DOT_METRICS_TAG_FULLNAME - Full deployment name (e.g., "dotcms-dotcms-dev-prod")
  • DOT_METRICS_TAG_HOSTNAME - Pod hostname with StatefulSet index via Kubernetes downward API

🔄 Kubernetes Integration

  • Hostname environment variable uses proper Kubernetes downward API (valueFrom.fieldRef.fieldPath: "metadata.name")
  • Provides actual pod names like dotcms-dotcms-dev-prod-0, dotcms-dotcms-dev-prod-1 for StatefulSet replica identification
  • Compatible with Kubernetes service discovery patterns

Testing

  • ✅ Validated Helm template rendering with Prometheus enabled/disabled
  • ✅ Confirmed annotations appear only when prometheus.enabled: true
  • ✅ Verified environment variables render correctly with proper values
  • ✅ Tested custom annotation values override defaults properly
  • ✅ Validated version helper function handles both regular tags and SNAPSHOT case
  • ✅ Confirmed downward API field reference syntax for hostname

Example Usage

Enable with defaults:

prometheus:
  enabled: true

Custom configuration:

prometheus:
  enabled: true
  annotations:
    scrape: "false"
    port: "9090" 
    path: "/custom/metrics"

Disable entirely:

prometheus:
  enabled: false

Impact

  • Zero breaking changes - Feature is opt-in and disabled by default
  • Enhanced observability - Enables automated Prometheus monitoring of DotCMS deployments
  • Flexible configuration - All aspects of metrics scraping are customizable
  • StatefulSet friendly - Proper hostname tagging for replica identification
  • Consistent labeling - Standardized environment variables for metric consistency across deployments

Closes #60

Issue: Add configurable prometheus metrics annotation support to helm chart

- Add prometheus metrics configuration section to values.yaml
- Include conditional pod annotations for Prometheus scraping
- Add environment variables for metrics tagging when enabled
- Create reusable dotcms.version helper function
- Support downward API for hostname environment variable
- Special handling for SNAPSHOT version tags

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
spbolton and others added 5 commits August 26, 2025 12:24
- Increment version for Prometheus metrics feature addition

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add containerPort 8090 to container spec when Prometheus enabled
- Expose management port 8090 in service when Prometheus enabled
- Maintain backward compatibility with conditional port exposure
- Named ports for better service discovery (http, management)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add separate management.enabled and management.port configuration
- Make Prometheus metrics use management port instead of hardcoded 8090
- Auto-enable management port when Prometheus metrics are enabled
- Remove hardcoded port references for DRY principle
- Support custom management port configuration
- Maintain backward compatibility with conditional port exposure

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Merge duplicate port sections into single comprehensive list
- Include all DotCMS ports: api (8080), web-insecure (8081), web-secure (8082), hazelcast (5701)
- Add management port (8090) conditionally when management or Prometheus enabled
- Maintain IsUpgradeJob condition to exclude ports from upgrade containers
- Add protocol: TCP for all ports for consistency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Member

@dcolina dcolina left a comment

Choose a reason for hiding this comment

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

Looks good. Prometheus support to the helm chart.

@spbolton spbolton merged commit 8007c67 into main Aug 26, 2025
3 checks passed
@spbolton spbolton deleted the issue-60-add-configurable-prometheus-metrics-annotation branch August 26, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configurable prometheus metrics annotation support to helm chart

2 participants