mvisonneau / gitlab-ci-pipelines-exporter

Prometheus / OpenMetrics exporter for GitLab CI pipelines insights
Apache License 2.0
1.21k stars 239 forks source link

BUG: Environments - 404 not found - after initial run #771

Open toby181 opened 6 months ago

toby181 commented 6 months ago

Hi together,

I've setup the exporter, in webhook mode, with the config below. Once the first webhook is received, the initial scrape of all projects, environments and refs of the wildcard is triggered and the environments are pulled, so far so good. Once this inital run is over, a new environment is created and a pipeline, using the new environment, triggers the webhook, it cannot get the metrics cause of a 404 exception, see below.

{"ip-address":"192.168.201.69:40774","level":"debug","msg":"webhook request","time":"2023-12-28T12:53:39Z","user-agent":"GitLab/16.5.2-ee"}
{"level":"info","msg":"received a pipeline webhook from GitLab for a ref, triggering metrics pull","project-name":"p1/gcpe-test","ref":"main","ref-kind":"branch","time":"2023-12-28T12:53:39Z"}
{"jobs-count":1,"level":"debug","msg":"found pipeline jobs","pipeline-id":19760,"project-name-or-id":"p1/gcpe-test","time":"2023-12-28T12:53:41Z"}
{"ip-address":"192.168.60.200:46118","level":"debug","msg":"webhook request","time":"2023-12-28T12:53:43Z","user-agent":"GitLab/16.5.2-ee"}
{"environment-name":"gcpe-stage2","error":"GET https://gitlab.example.com/api/v4/projects/p1/gcpe-test/environments/0: 404 {message: 404 Not found}","level":"error","msg":"updating event from GitLab API","project-name":"p1/gcpe-test","time":"2023-12-28T12:53:44Z"}
{"ip-address":"192.168.60.200:46118","level":"debug","msg":"webhook request","time":"2023-12-28T12:53:44Z","user-agent":"GitLab/16.5.2-ee"}
{"level":"info","msg":"received a pipeline webhook from GitLab for a ref, triggering metrics pull","project-name":"p1/gcpe-test","ref":"main","ref-kind":"branch","time":"2023-12-28T12:53:44Z"}
{"jobs-count":1,"level":"debug","msg":"found pipeline jobs","pipeline-id":19760,"project-name-or-id":"p1/gcpe-test","time":"2023-12-28T12:53:46Z"}
{"ip-address":"192.168.60.200:45020","level":"debug","msg":"webhook request","time":"2023-12-28T12:53:50Z","user-agent":"GitLab/16.5.2-ee"}
**{"environment-name":"gcpe-stage2","error":"GET https://gitlab.example.com/api/v4/projects/p1/gcpe-test/environments/0: 404 {message: 404 Not found}","level":"error","msg":"updating event from GitLab API","project-name":"p1/gcpe-test","time":"2023-12-28T12:53:50Z"}**
{"ip-address":"192.168.60.200:45020","level":"debug","msg":"webhook request","time":"2023-12-28T12:53:51Z","user-agent":"GitLab/16.5.2-ee"}
{"level":"info","msg":"received a pipeline webhook from GitLab for a ref, triggering metrics pull","project-name":"p1/gcpe-test","ref":"main","ref-kind":"branch","time":"2023-12-28T12:53:51Z"}
{"jobs-count":1,"level":"debug","msg":"found pipeline jobs","pipeline-id":19760,"project-name-or-id":"p1/gcpe-test","time":"2023-12-28T12:53:53Z"}
      log:
        # allowed values: trace, debug, info, warning, error, fatal or panic
        level: debug
        # allowed values: text or json
        format: json

      server:
        webhook:
          enabled: true

      redis:
        enabled: true
        master:
          updateStrategy: 
            type: OnDelete
          persistence:
            enabled: false
            storageClass: encrypted
            size: 500Mi
          resources:
            limits:
              cpu: 50m
              memory: 64Mi
            requests:
              cpu: 50m
              memory: 64Mi

      gitlab:
        url: https://gitlab.example.com

      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

      garbage_collect:
        projects:
          on_init: false
          scheduled: true
          interval_seconds: 43200 # 12 hours

        environments:
          on_init: false
          scheduled: true
          interval_seconds: 43200 # 12 hours

        refs:
          on_init: false
          scheduled: true
          interval_seconds: 1800

        metrics:
          on_init: false
          scheduled: true
          interval_seconds: 600

      project_defaults:
        pull:
          environments:
            enabled: true
            regexp: ".*"
            exclude_stopped: true
          refs:
            branches:
              enabled: true
              regexp: "^(?:main|master)$"
              most_recent: 0
              max_age_seconds: 0
              exclude_deleted: true
            tags:
              enabled: true
              regexp: ".*"
              most_recent: 0
              max_age_seconds: 0
              exclude_deleted: true
            merge_requests:
              enabled: false
              most_recent: 0
              max_age_seconds: 0
          pipeline:
            jobs:
              enabled: true
              from_child_pipelines:
                enabled: false
              runner_description:
                enabled: false
                aggregation_regexp: shared-runners-manager-(\d*)\.gitlab\.com
            variables:
              enabled: false
              regexp: ".*"
            test_reports:
              enabled: false
              test_cases:
                enabled: false

      wildcards:
        - owner:
            # Name of the owner (required)
            name: p1
            kind: group
            include_subgroups: true

Newly created branches seem to work, they appear in the dashboard.

toby181 commented 6 months ago

as workaround

      pull:
        projects_from_wildcards:
          on_init: false
          scheduled: false

        environments_from_projects:
          **on_init: true**
          scheduled: false