Skip to content

Add version string to metrics #18061

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

Closed
steled opened this issue Dec 21, 2021 · 9 comments
Closed

Add version string to metrics #18061

steled opened this issue Dec 21, 2021 · 9 comments
Labels
good first issue Likely to be an easy fix hacktoberfest

Comments

@steled
Copy link

steled commented Dec 21, 2021

Feature Description

Hi,

I'm monitoring my Gitea instance via Prometheus and Grafana.
It would be great to have a string for the current Gitea version and the new one in the metrics to set an Grafana alert for possible new version on it.

Screenshots

No response

@Flygrounder
Copy link

Sounds like a useful feature. But Prometheus does not support string metrics and adding version string as a label does not sound like a good idea.

Maybe we should convert semver to an integer e.g. 1.15.9 = 1 * 100^2 + 15 * 100 + 9 = 11509

@techknowlogick
Copy link
Member

@Flygrounder that's a good suggestion, although I'm not sure it'd work in all cases, as there are occasions when the version wouldn't always be in a format that could be converted so cleanly, ex v1.16.0-dev-796-gd228d346c

@Flygrounder
Copy link

But this is only the case with dev versions, for which you probably do not want to get alerts because they are constantly updated. Perhaps in that case reporting 11600 would be fine.

@wxiaoguang
Copy link
Contributor

I think we had better keep the original version format, and just use a new field like updateAvailable to indicate that there is a new update. Converting a version string to an (big) integer may introduce new problems.

@Flygrounder
Copy link

Flygrounder commented Jan 5, 2022

To be clear, I was talking only about converting semver to an integer in Prometheus metrics, not for the entire project.

Additional benefit of having version metric in contrast to updateAvailable is that you can correlate other metrics to the specific Gitea version and see how well each version performs.

@6543
Copy link
Member

6543 commented Jan 29, 2022

#18454 (review)

@mwasilew2
Copy link
Contributor

I think that what you use for "semi-automated" upgrades or upgrade notifications varies from environment to environment and it would be hard to provide a unified approach. This is not to say that Gitea shouldn't include an approach for that (e.g. a notification in the admin panel or an email sent to the Gitea admins saying that a new version is available).

I'm not sure what would be the best approach to populating a Prometheus metric with the latest available version of Gitea.

Some ideas for how to approach the problem of picking up new versions automatically:

Regardless of the mechanism used for updating, I think it's still useful to expose build info, so I opened: #22819

@delvh
Copy link
Member

delvh commented Feb 8, 2023

This is not to say that Gitea shouldn't include an approach for that (e.g. a notification in the admin panel or an email sent to the Gitea admins saying that a new version is available).

FYI: That exists already. https://docs.gitea.io/en-us/config-cheat-sheet/#cron----check-for-new-gitea-versions-cronupdate_checker

lafriks pushed a commit that referenced this issue Feb 8, 2023
Related to: #18061

This PR adds build info to the Prometheus metrics. This includes:
- goarch: https://pkg.go.dev/runtime#GOARCH
- goos: https://pkg.go.dev/runtime#pkg-constants
- goversion: https://pkg.go.dev/runtime#Version
- gitea version: just exposes the existing
code.gitea.io/gitea/modules/setting.AppVer

It's a similar approach to what some other Golang projects are doing,
e.g. Prometheus:
https://github.com/prometheus/common/blob/main/version/info.go

example /metrics response from Prometheus:
```
# HELP prometheus_build_info A metric with a constant '1' value labeled by version, revision, branch, goversion from which prometheus was built, and the goos and goarch for the build.
# TYPE prometheus_build_info gauge
prometheus_build_info{branch="HEAD",goarch="amd64",goos="linux",goversion="go1.19.4",revision="c0d8a56c69014279464c0e15d8bfb0e153af0dab",version="2.41.0"} 1
```

/metrics response from gitea with this PR:
```
# HELP gitea_build_info Build information
# TYPE gitea_build_info gauge
gitea_build_info{goarch="amd64",goos="linux",goversion="go1.20",version="2c6cc0b8c"} 1
```

Signed-off-by: Michal Wasilewski <[email protected]>

<!--

Please check the following:

1. Make sure you are targeting the `main` branch, pull requests on
release branches are only allowed for bug fixes.
2. Read contributing guidelines:
https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md
3. Describe what your pull request does and which issue you're targeting
(if any)

-->

Signed-off-by: Michal Wasilewski <[email protected]>
@lunny
Copy link
Member

lunny commented Jun 20, 2023

resolved by #22819

@lunny lunny closed this as completed Jun 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Likely to be an easy fix hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants