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

fix: PodMonitor doesn't honor sonarWebContext and fails to monitor SonarQube #452

Merged
merged 1 commit into from Apr 12, 2024

Conversation

wwsean08
Copy link
Contributor

@wwsean08 wwsean08 commented Mar 14, 2024

Hello,

Currently if you set the sonarWebContext and enable the PodMonitor via prometheusMonitoring.podMonitor.enabled, then it will fail to monitor, this is because while it is hard coded to poll /api/monitoring/metrics, SonarQube is listening at (as an example) /sonarqube/api/monitoring/metrics.

As a note, this change is based on how the readiness and liveness probes work, seen here for determining the URL.

Testing:

Validate SonarQube DCE with the podmonitor enabled but the sonar web context blank via the helm template command

---
# Source: sonarqube-dce/templates/prometheus-podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: sonarqube-dce
  namespace: "default"
  labels:
    app: sonarqube-dce
spec:
  namespaceSelector:
    matchNames:
    - default
  selector:
    matchLabels:
      app: sonarqube-dce
  podMetricsEndpoints:
  - port: http
    path: /api/monitoring/metrics
    scheme: http
    interval: 30s
    bearerTokenSecret:
      name: sonarqube-dce-sonarqube-dce-monitoring-passcode
      key: SONAR_WEB_SYSTEMPASSCODE

Validate SonarQube DCE with the podmonitor enabled but the sonar web context /sonarqube via the helm template command

---
# Source: sonarqube-dce/templates/prometheus-podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: sonarqube-dce
  namespace: "default"
  labels:
    app: sonarqube-dce
spec:
  namespaceSelector:
    matchNames:
    - default
  selector:
    matchLabels:
      app: sonarqube-dce
  podMetricsEndpoints:
  - port: http
    path: /sonarqube/api/monitoring/metrics
    scheme: http
    interval: 30s
    bearerTokenSecret:
      name: sonarqube-dce-sonarqube-dce-monitoring-passcode
      key: SONAR_WEB_SYSTEMPASSCODE

Validate SonarQube with the podmonitor enabled but the sonar web context blank via the helm template command

---
# Source: sonarqube/templates/prometheus-podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: sonarqube
  namespace: "default"
  labels:
    app: sonarqube
spec:
  namespaceSelector:
    matchNames:
    - default
  selector:
    matchLabels:
      app: sonarqube
  podMetricsEndpoints:
  - port: http
    path: /api/monitoring/metrics
    scheme: http
    interval: 30s
    bearerTokenSecret:
      name: sonarqube-sonarqube-monitoring-passcode
      key: SONAR_WEB_SYSTEMPASSCODE

Validate SonarQube with the podmonitor enabled but the sonar web context /sonarqube via the helm template command

---
# Source: sonarqube/templates/prometheus-podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: sonarqube
  namespace: "default"
  labels:
    app: sonarqube
spec:
  namespaceSelector:
    matchNames:
    - default
  selector:
    matchLabels:
      app: sonarqube
  podMetricsEndpoints:
  - port: http
    path: /sonarqube/api/monitoring/metrics
    scheme: http
    interval: 30s
    bearerTokenSecret:
      name: sonarqube-sonarqube-monitoring-passcode
      key: SONAR_WEB_SYSTEMPASSCODE

Please ensure your pull request adheres to the following guidelines:

  • explain your motives to contribute this change: what problem you are trying to fix, what improvement you are trying to make
  • Document your Changes in the CHANGELOG.md file of the respected chart as well as the Chart.yaml

@wwsean08
Copy link
Contributor Author

Hey @davividal, just checking in on this, anything I can do to help you review this change?

@carminevassallo
Copy link
Contributor

Dear @wwsean08,

Thanks for contributing to our helm chart!

Your suggestion is correct; we don't consider the sonarWebContext when setting the Prometheus-native endpoint in our PodMonitor. I just tested your proposed changes locally, and they work as expected. Kudos 👏

Given that we recently pushed some changes related to the monitoring part, could you please integrate those changes quickly and solve the small conflicts in the change descriptions?

@wwsean08
Copy link
Contributor Author

Hey @carminevassallo, thanks for taking a look, I've rebased this based on main and have resolved the merge conflicts, hopefully it's good to go now.

Copy link
Contributor

@carminevassallo carminevassallo left a comment

Choose a reason for hiding this comment

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

Thanks, it looks all good to me 🎊

@carminevassallo carminevassallo merged commit c9d7306 into SonarSource:master Apr 12, 2024
7 of 9 checks passed
@wwsean08 wwsean08 deleted the fix-podmonitor branch April 13, 2024 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants