Skip to content

Commit

Permalink
Enhanced the webhooks example
Browse files Browse the repository at this point in the history
  • Loading branch information
mvisonneau committed Jan 28, 2021
1 parent 6dfbbd8 commit e66c6fa
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
51 changes: 48 additions & 3 deletions examples/webhooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,59 @@ You can then trigger a manual test:
If the last pipeline which ran on your project is on a ref that is configured to be exported, you will see the following logs:

```bash
~$ waypoint logs
~$ docker-compose logs -f
[..]
DEBU[2020-10-09T15:03:49+01:00] webhook request ip-address="127.0.0.1:62838" user-agent=
time="2021-01-28T09:51:28Z" level=debug msg="webhook request" ip-address="192.168.0.1:57954" user-agent=GitLab/13.9.0-pre
time="2021-01-28T09:51:28Z" level=info msg="received a pipeline webhook from GitLab for a ref, triggering metrics pull" project-name=foo/bar ref=main ref-kind=branch
[..]
```

If you query the `/metrics` endpoint of the exporter you should be able to see associated metrics:

```shell
gitlab_ci_pipeline_coverage{kind="branch",project="foo/bar",ref="main",topics="",variables=""} 0
gitlab_ci_pipeline_duration_seconds{kind="branch",project="foo/bar",ref="main",topics="",variables=""} 494
gitlab_ci_pipeline_id{kind="branch",project="foo/bar",ref="main",topics="",variables=""} 1.00308162e+08
gitlab_ci_pipeline_run_count{kind="branch",project="foo/bar",ref="main",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="canceled",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="created",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="failed",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="manual",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="pending",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="preparing",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="running",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="scheduled",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="skipped",topics="",variables=""} 0
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="success",topics="",variables=""} 1
gitlab_ci_pipeline_status{kind="branch",project="foo/bar",ref="main",status="waiting_for_resource",topics="",variables=""} 0
gitlab_ci_pipeline_timestamp{kind="branch",project="foo/bar",ref="main",topics="",variables=""} 1.611826041e+09
```

In this configuration, the exporter does not even attempt to fetch the metrics on init, this means that on start, you won't be getting any metrics populated/exported until
a webhook has been triggered). This can be mitigated by whether using it in a ["ha-fashion" with a Redis backend](../ha-setup) or by enabling the following in the exporter config:

```yaml
pull:
projects_from_wildcards:
on_init: true

environments_from_projects:
on_init: true

refs_from_projects:
on_init: true

metrics:
on_init: true
```
You can also use it in an hybrid fashion pull/push with greater pull intervals if you want to ensure you have a consistent/convergent state over time.
## Cleanup
```bash
~$ waypoint destroy
~$ docker-compose down
~$ <stop ngrok>
```

Also remove the configured test webhook on your GitLab project.
28 changes: 23 additions & 5 deletions examples/webhooks/gitlab-ci-pipelines-exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@ gitlab:
url: https://gitlab.com
token: <your_token>

redis:
url: redis://redis:6379
server:
webhook:
enabled: true
secret_token: <strong_arbitrary_secret_token>

pull:
projects_from_wildcards:
on_init: false
scheduled: false

environments_from_projects:
on_init: false
scheduled: false

refs_from_projects:
on_init: false
scheduled: false

metrics:
on_init: false
scheduled: false

# Example public projects to monitor
projects:
- name: gitlab-org/gitlab-runner
- name: gitlab-org/charts/auto-deploy-app
# Configure a project on which you are authorized to configure webhooks
- name: <your_project_path_with_namespace>

0 comments on commit e66c6fa

Please sign in to comment.