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

Include Nextcloud update availability information #116

Merged
merged 6 commits into from
Aug 2, 2024

Conversation

monofox
Copy link
Contributor

@monofox monofox commented Apr 13, 2024

This commit introduces new option and metric about nextcloud update availabilty information.

A new option was introduced called --enable-info-update which will append the to the Nextcloud serverinfo-URL a &skipUpdate=false.

In response, the update information is returned and provided in a new metric called nextcloud_system_update_available.

Example output if update available:

# HELP nextcloud_system_update_available Contains information whether a system update is available (0 = no, 1 = yes). In case of 1=yes, available_version label contains the new version.
# TYPE nextcloud_system_update_available gauge
nextcloud_system_update_available{available_version="28.0.4.1"} 1

Example output if update not available:

# HELP nextcloud_system_update_available Contains information whether a system update is available (0 = no, 1 = yes). In case of 1=yes, available_version label contains the new version.
# TYPE nextcloud_system_update_available gauge
nextcloud_system_update_available{available_version=""} 0

It was a bit tricky, as Nextcloud is reporting conflicting information (shortened excerpt):

{
  "system": {
    "version": "28.0.4.1",
    "update": {
      "lastupdatedat": 0,
      "available": true,
      "available_version": "28.0.4.1"
    }
  }
}

Fixes #115

This commit introduces new option and metric about nextcloud
update availabilty information.

A new option was introduced called `--enable-info-update`
which will append the to the Nextcloud serverinfo-URL a
`&skipUpdate=false`.

In response, the update information is returned and provided in a new
metric called `nextcloud_system_update_available`.

Fixes xperimental#115
@xperimental
Copy link
Owner

Hi @monofox . Thanks for the contribution 👍

I have seen the issue and this PR, but I had no time to look at this thoroughly yet. I had an idea to add this information when adding the skipApps code as well.

I'll probably not get to this until after the weekend, but I already enabled CI for this PR and it seems some tests need to be updated for the new code.

@monofox
Copy link
Contributor Author

monofox commented Apr 18, 2024

Thank you @xperimental . No hurry.
The failed tests results of situation, that the tests are currently running against a non-existing nextcloud.example.com. I wondered during extension of the tests, but expected to have a corresponding docker-container during test phase running to spawn this domain in an isolated test environment.

Just let me know, if (and which) changes should be done in this way.

@PReimers
Copy link

PReimers commented Apr 30, 2024

@monofox I checked your tests.

The problem with the test is the expected URL does not match the actual URL.

Example 1:
expected: https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false
actual: https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false

Example 2:
expected: https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipUpdate=false&skipApps=false
actual: https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false

If I'm correct, the following code (serverinfo/url.go) would fix the tests:
(Changing the wantURL parameter to always include the skipApps and skipUpdate parameters, in exactly that order)

                {
			desc:      "do not skip apps",
			serverURL: "https://nextcloud.example.com",
			wantURL:   "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false",
		},
		{
			desc:      "skip apps",
			serverURL: "https://nextcloud.example.com",
			skipApps:  true,
			wantURL:   "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=true&skipUpdate=false",
		},
		{
			desc:       "do not skip update",
			serverURL:  "https://nextcloud.example.com",
			skipUpdate: false,
			wantURL:    "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false",
		},
		{
			desc:       "skip update",
			serverURL:  "https://nextcloud.example.com",
			skipUpdate: true,
			wantURL:    "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=true",
		},
		{
			desc:       "do not skip update and do not skip apps",
			serverURL:  "https://nextcloud.example.com",
			skipApps:   false,
			skipUpdate: false,
			wantURL:    "https://nextcloud.example.com/ocs/v2.php/apps/serverinfo/api/v1/info?format=json&skipApps=false&skipUpdate=false",
		},

@monofox
Copy link
Contributor Author

monofox commented May 2, 2024

Thank you @PReimers for review and giving the right hint. I was blind for it. Fixed it. Test is fine on local machine.

@xperimental
Copy link
Owner

Sorry, I have been busy / away the past weekends. This PR is not forgotten though. 🙂

Copy link
Owner

@xperimental xperimental left a comment

Choose a reason for hiding this comment

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

Finally managed to have a look at this (it's GPN 🎉 ). Works fine, thanks for the contribution 🙂

I have added some small comments.

internal/config/config.go Outdated Show resolved Hide resolved
internal/metrics/collector.go Outdated Show resolved Hide resolved
internal/metrics/collector.go Show resolved Hide resolved
internal/metrics/collector.go Outdated Show resolved Hide resolved
serverinfo/serverinfo.go Outdated Show resolved Hide resolved
@xperimental
Copy link
Owner

@monofox Do you have time to go through the review comments or do you want me to take over the PR?

@monofox
Copy link
Contributor Author

monofox commented Jul 18, 2024

@monofox Do you have time to go through the review comments or do you want me to take over the PR?

Took a bit longer to get again free time. Thanks for your grateful comments. I've addressed them. Unfortunately, the check on the version number seems to be essential for proper indication whether an update is really available. See my comments above.

@xperimental xperimental merged commit 77d9357 into xperimental:master Aug 2, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System update available information
3 participants