nextcloud / helm

A community maintained helm chart for deploying Nextcloud on Kubernetes.
GNU Affero General Public License v3.0
295 stars 258 forks source link

Include nextcloud service in trusted domains for metrics exporter #483

Closed darkowlzz closed 3 weeks ago

darkowlzz commented 7 months ago

Pull Request

Description of the change

When nextcloud-exporter is used by enabling metrics, it fails to fetch the serverinfo with 400 response code.

nextcloud-exporter log

level=error msg="Error during scrape: unexpected status code: 400"

nextcloud log

10.244.0.38 - admin [24/Nov/2023:22:34:50 +0000] "GET /ocs/v2.php/apps/serverinfo/api/v1/info?format=json HTTP/1.1" 400 11344 "-" "nextcloud-exporter/0.6.1"

This is related to the switch from ingress to local service endpoint for nextcloud-exporter in https://github.com/nextcloud/helm/pull/388.

To fix this, in addition to .Values.nextcloud.host, the nextcloud service also needs to be included in the trusted domains. In config/config.php

  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => 'nextcloud.kube.home',
    2 => 'nextcloud',
  ),

where nextcloud is the service name.

This solution is based on https://github.com/xperimental/nextcloud-exporter/issues/14 , an upstream issue for the same problem.

Benefits

The nextcloud-exporter will be able to fetch and export the metrics properly.

Possible drawbacks

None

Applicable issues

None

Additional information

Without this, the metrics exporter exported metrics about itself only:

# HELP nextcloud_exporter_info Information about the nextcloud-exporter.
# TYPE nextcloud_exporter_info gauge
nextcloud_exporter_info{commit="98d4d4607e9d020dc19b8c21e1401b6b27a5d3a8",version="0.6.1"} 1
# HELP nextcloud_scrape_errors_total Counts the number of scrape errors by this collector.
# TYPE nextcloud_scrape_errors_total counter
nextcloud_scrape_errors_total{cause="other"} 2
# HELP nextcloud_up Indicates if the metrics could be scraped by the exporter.
# TYPE nextcloud_up gauge
nextcloud_up 0

Once the issue is fixed, it exports all the nextcloud app metrics:

# HELP nextcloud_active_users_daily_total Number of active users in the last 24 hours.
# TYPE nextcloud_active_users_daily_total gauge
nextcloud_active_users_daily_total 0
# HELP nextcloud_active_users_hourly_total Number of active users in the last hour.
# TYPE nextcloud_active_users_hourly_total gauge
nextcloud_active_users_hourly_total 0
# HELP nextcloud_active_users_total Number of active users for the last five minutes.
# TYPE nextcloud_active_users_total gauge
nextcloud_active_users_total 0
# HELP nextcloud_apps_installed_total Number of currently installed apps
# TYPE nextcloud_apps_installed_total gauge
nextcloud_apps_installed_total 42
# HELP nextcloud_apps_updates_available_total Number of apps that have available updates
# TYPE nextcloud_apps_updates_available_total gauge
nextcloud_apps_updates_available_total 0
...

Checklist

jessebot commented 7 months ago

Thanks for submitting this! I've approved the workflow run, but do not have time to test this further, so I will add some other PR reviewers :)

christensenjairus commented 3 weeks ago

Here's a quick fix for those (like me) that can't wait for the chart to be fixed. This file's values will override those in config/config.php.

nextcloud:
  configs: # I've taken the standard trusted domains and added one that's necessary for the exporter to work
    trusted-domains.config.php: |-
      <?php 
      $CONFIG = [
        'trusted_domains' =>
        array (
          0 => 'localhost',
          1 => 'nextcloud.example.com',
          2 => 'nextcloud.nextcloud.svc.cluster.local'
        ),
      ];
      ?>