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

Add grafana gitea-mixin #17758

Merged
merged 24 commits into from
Dec 20, 2021
Merged

Add grafana gitea-mixin #17758

merged 24 commits into from
Dec 20, 2021

Conversation

v-zhuravlev
Copy link
Contributor

This PR adds gitea-mixin, configurable Grafana dashboards (and potentially prometheus alerts+recording rules) based on Gitea metrics.

The overview dashboard is described using jsonnet and grafonnet library: https://grafana.github.io/grafonnet-lib/

Mixins help to define dashboard and alerts as code so they can be collaboratively improved by the users.

image

__

Generate config files

You can manually generate dashboards, but first you should install some tools:

go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
go get github.com/google/go-jsonnet/cmd/jsonnet
# or in brew: brew install go-jsonnet

For linting and formatting, you would also need mixtool and jsonnetfmt installed. If you
have a working Go development environment, it's easiest to run the following:

go get github.com/monitoring-mixins/mixtool/cmd/mixtool
go get github.com/google/go-jsonnet/cmd/jsonnetfmt

The files in dashboards_out need to be imported
into your Grafana server. The exact details will be depending on your environment.

Edit config.libsonnet (for example, list of Gitea metrics to be shown under stats can be adjusted). if required and then build JSON dashboard files for Grafana:

make

For more about mixins, please see:
https://github.com/monitoring-mixins/docs
https://www.youtube.com/watch?v=GDdnL5R_l-Y

@wxiaoguang
Copy link
Contributor

It seems that https://gitea.com/gitea/awesome-gitea is the better place to list this dashboard.

Usually, users do not read files in gitea/contrib directory, files in this directory are mostly development related.

So listing this dashboard and document in awesome-gitea will help more users.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 22, 2021
@v-zhuravlev
Copy link
Contributor Author

HI! Thanks for the reply,
Awesome Gitea list is the great place to link to this mixin and dashboard repo for sure! The mixin' code s still has to be placed in git and is generally recommended that this is hosted together with the app itself like here:
https://github.com/prometheus/prometheus/tree/main/documentation/prometheus-mixin
https://github.com/ceph/ceph-mixins

@techknowlogick
Copy link
Member

I think accepting this into contrib/ and then adding to awesome-gitea for visibility would be reasonable.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 23, 2021
@mkdir -p dashboards_out
jsonnet -J vendor -m dashboards_out lib/dashboards.jsonnet

build: vendor
Copy link
Member

@silverwind silverwind Nov 25, 2021

Choose a reason for hiding this comment

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

This Makefile is missing declaration of .PHONY targets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, added .PHONY targets

@silverwind
Copy link
Member

Also maybe rename folder to grafana-mixin or gitea-grafana-mixin. Just gitea-mixin seems ambiguos to me.


local giteaSelector = 'job="$job", instance="$instance"',
local giteaStatsPanel = grafana.statPanel.new(
'Gitea stats',
Copy link
Member

@silverwind silverwind Nov 25, 2021

Choose a reason for hiding this comment

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

Too much indentation? If libsonnet syntax does not require this, I would suggest follow 2-space indendation rule to make this much more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, too much, it had been generated by jsonnetfmt so I made some adjustments to make suremake fmt stick 2-spcae indendation as much as possible.

@codecov-commenter
Copy link

codecov-commenter commented Dec 13, 2021

Codecov Report

Merging #17758 (102de09) into main (1c7db70) will decrease coverage by 0.01%.
The diff coverage is 64.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17758      +/-   ##
==========================================
- Coverage   45.20%   45.19%   -0.01%     
==========================================
  Files         823      823              
  Lines       91371    91389      +18     
==========================================
- Hits        41305    41304       -1     
- Misses      43471    43492      +21     
+ Partials     6595     6593       -2     
Impacted Files Coverage Δ
cmd/dump.go 0.89% <0.00%> (ø)
modules/log/colors.go 69.86% <0.00%> (ø)
modules/util/path.go 56.17% <0.00%> (ø)
routers/api/v1/repo/pull.go 28.69% <0.00%> (-0.15%) ⬇️
routers/web/repo/pull.go 30.38% <0.00%> (-0.17%) ⬇️
routers/web/user/oauth.go 35.38% <0.00%> (ø)
services/forms/repo_form.go 41.25% <ø> (ø)
services/migrations/dump.go 0.00% <0.00%> (ø)
services/migrations/restore.go 0.00% <0.00%> (ø)
services/pull/merge.go 48.33% <25.00%> (-1.06%) ⬇️
... and 59 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff2fd08...102de09. Read the comment docs.

@v-zhuravlev
Copy link
Contributor Author

Also maybe rename folder to grafana-mixin or gitea-grafana-mixin. Just gitea-mixin seems ambiguos to me.

Thanks for the suggestion, to make it more clear, I renamed this dir to gitea-monitoring-mixin:
( https://monitoring.mixins.dev/) , as grafana dashboard is not the only possible part of the monitoring-mixin.

@v-zhuravlev
Copy link
Contributor Author

v-zhuravlev commented Dec 15, 2021

Screenshot 2021-12-15 at 19 47 10

Thanks for your reviews, I made changes as you requested as well as more improvements to the Grafana dashboard:

  1. Add optional (on by default) Issue by labels, Issues by repositories panels ( represented in Add metrics to get issues by label #17201, Add metrics to get issues by repository #17225 made by @romdum
    1.1) Issue by labels panels: use colors that correspond to colors of default gitea labels set (configurable)
  2. Add support (on by default) for metrics gitea_issues_open, gitea_issues_closed introduced here (Separate open and closed issue in metrics #16637)

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 16, 2021
@zeripath zeripath merged commit 2cd1479 into go-gitea:main Dec 20, 2021
@zeripath zeripath changed the title Add gitea-mixin Add grafana gitea-mixin Dec 20, 2021
@v-zhuravlev
Copy link
Contributor Author

Thank you! Opened PR for awesome-gitea, as had been discussed
https://gitea.com/gitea/awesome-gitea/pulls/63

Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
This PR adds gitea-mixin, configurable Grafana dashboards (and potentially prometheus alerts+recording rules) based on Gitea [metrics](https://docs.gitea.io/en-us/config-cheat-sheet/#metrics-metrics).

The overview dashboard is described using jsonnet and grafonnet library: https://grafana.github.io/grafonnet-lib/

Mixins help to define dashboard and alerts as code so they can be collaboratively improved by the users.

![image](https://user-images.githubusercontent.com/14870891/142862822-fe57b384-c74a-4103-8548-033e92f90751.png)

__
## Generate config files

You can manually generate dashboards, but first you should install some tools:

```bash
go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
go get github.com/google/go-jsonnet/cmd/jsonnet
# or in brew: brew install go-jsonnet
```

For linting and formatting, you would also need `mixtool` and `jsonnetfmt` installed. If you
have a working Go development environment, it's easiest to run the following:

```bash
go get github.com/monitoring-mixins/mixtool/cmd/mixtool
go get github.com/google/go-jsonnet/cmd/jsonnetfmt
```

The files in `dashboards_out` need to be imported
into your Grafana server.  The exact details will be depending on your environment.

Edit `config.libsonnet` (for example, list of Gitea metrics to be shown under stats can be adjusted). if required and then build JSON dashboard files for Grafana:

```bash
make
```


For more about mixins, please see:
https://github.com/monitoring-mixins/docs
https://www.youtube.com/watch?v=GDdnL5R_l-Y* add gitea mixin

* remove alerts/rules

* gitea-mixin: add interval factor of 1/2 to remove duplicated change events

* gitea-mixin: fix changes panel, add aggregation interval for changes panel

* gitea-mixin: add totals singlestat

* gitea mixin: switch change graph to timeseries type

* add color overrides for issue labels

* bump grafonnet version

* gitea-mixin: convert graphs to timeseries

* gitea-mixin:  make fmt

* gitea-mixin: add .PHONE in Makefile

* gitea-mixin: add time configration

* gitea-mixin: make fmt and collapse addPanel grid

* gitea-mixin: add static ids for shared panels

* gitea-mixin: add flags showIssuesByRepository, showIssuesByLabel to show/hide corresponding panels

* gitea-mixin: update aggregation interval

* gitea-mixin: update defaults

* gitea-mixin: update panel names

* rename dir to gitea-monitoring-mixin

* gitea-mixin: add gitea_issues_open, gitea_issues_closed metrics

* gitea-mixin: update visible name for datasource

* gitea-mixin: update README

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: zeripath <[email protected]>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants