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

[Feature] Add pipeline variables to metrics #33

Closed
misaon opened this issue Nov 7, 2019 · 11 comments
Closed

[Feature] Add pipeline variables to metrics #33

misaon opened this issue Nov 7, 2019 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@misaon
Copy link

misaon commented Nov 7, 2019

Firstly, I would like to express my thanks for the excellent work on this exporter.
I would send PR but I have no experience with GO.

Idea:
Add variable information to metrics. See the pipelines API documentation (https://docs.gitlab.com/ee/api/pipelines.html#get-variables-of-a-pipeline).

Why?
Now, for example, in Grafana we are limited to working only with information "repository name" and "ref". I think it's a good idea to be able to add a column in Graphana to display your own information using variables from pipelines.

My scope:
I solve this problem because in my company we would like to use monitoring of export orders from our e-shops using Gitlab pipelines (via scheduler). Now we have a problem, because we have one ".gitlab-ci.yml" file, inside are defined "deploy" and "export of orders" stages. The "export of orders" stage is only started when I create a pipeline with the appropriate rules and the "deploy" starts when the merge request is created.
However, both "deploy" and "export orders" go to the metrics. It is mixed together and it is not possible to filter records.

Can you think of a solution to this problem?
Thanks a lot 👍

@mvisonneau mvisonneau added the enhancement New feature or request label Nov 7, 2019
@mvisonneau
Copy link
Owner

👋 hey @misaon, thanks for the kind feedback! 🙇

I started to put some thoughts into it. It should be doable indeed. I believe this requires quite some work though as we would need to have dynamically generated labels which implies some refactoring of the existing codebase in order to work flawlessly!

I am not planning to look into this right now but MRs are welcome! :)

@mvisonneau mvisonneau added the help wanted Extra attention is needed label Mar 21, 2020
@inge4pres
Copy link
Contributor

Hi @mvisonneau did you have already some work done on this? I can pick it up

@mvisonneau
Copy link
Owner

I have not, feel free to pick it up! :) thanks!

@inge4pres
Copy link
Contributor

Hey there @misaon what would be the desired metric layout for you to address this? Would you like a label for every variable? Or a single label with variables encoded in some format? The first implementation could blow up metrics a bit, depending on the number of variables.
Both implementations would be gated by a config flag

@inge4pres
Copy link
Contributor

I just noticed that the variables are only populated when running a pipeline manually or a schedule with variables set. @misaon can this still be useful?

@inge4pres
Copy link
Contributor

@mvisonneau do you think the variables can fit into a set of labels for the already existing metric gitlab_ci_pipeline_job_run_count or would you prefer a dedicated metric for them?

@inge4pres
Copy link
Contributor

inge4pres commented Apr 20, 2020

after digging into it for a while, I found that we could either:

  • use a NewConstMetrics with labels set as variable names (no values! as they could be sensitive data)
  • curry the job_run_count metric with more labels with some sort of encoding

I'll try and write tests for both see what the implementation could be and then we can discuss

@nfm
Copy link
Contributor

nfm commented Apr 21, 2020

Hiya 👋 I've just started experimenting with gitlab-ci-pipelines-exporter and I'm also finding it really useful. Thanks @mvisonneau! ❤️

I think I have a similar use-case to @misaon and thought it might be helpful to share on this issue.

I'd like to instrument how long our main build/test/deploy pipeline takes on the master branch so we can optimize those durations. However, we have a couple of additional scheduled pipelines that also target the master branch (for example, scheduled nightly renovate jobs). These do something totally different to our build/test/deploy pipeline. Currently it's not possible to omit these from the gitlab_ci_pipeline_last_run_duration_seconds{ref="master"} metric.

GitLab does provide a CI_PIPELINE_SOURCE variable that can be used to identify whether the pipeline was triggered from a schedule. If we could add this variable as a label to the metric, we could filter out scheduled master pipeline durations, and focus on what we need to measure.

There are a lot of pipeline variables though, so I think it would make sense to whitelist which ones are sent as labels. Alternatively if a general purpose solution is hard to architect, maybe we could enumerate some common use-cases for this and just support those.

@inge4pres
Copy link
Contributor

Hi @nfm this is another feature compared to the one discussed in this issue that, yet relevant to this, can be developed on its own once this issue is completed and some refactoring is done on the current implementattion.
@mvisonneau I am about to send a PR with a pretty big change that could allow us to create new metrics on the fly every time we scan he projects list; I will definitely need your review on this because of my limited experience with the prometheus package.

@mvisonneau
Copy link
Owner

thanks for the kind feedback @nfm 🙇 !

Indeed I reckon that this could be very useful. We need to figure out a pragmatic approach in order to let people choose which variables they would like to get.

@mvisonneau
Copy link
Owner

This feature is now part of 0.3.0

I reckon this does not cover @nfm use case though as the API only returns the user defined variables though. I'll have referenced it in another issue (#96)

@mvisonneau mvisonneau self-assigned this Apr 29, 2020
@mvisonneau mvisonneau removed the help wanted Extra attention is needed label Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants