-
Notifications
You must be signed in to change notification settings - Fork 243
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
No metrics for merged results pipelines #534
Comments
This is due to the regex used when checking whether a retrieved ref matches the expected pattern for merge request pipelines. Here's the line:
The Here's a patch that makes the code work for all MR pipelines (regular and merge results ones): diff --git a/pkg/controller/pipelines.go b/pkg/controller/pipelines.go
index 8173434..71e94b2 100644
--- a/pkg/controller/pipelines.go
+++ b/pkg/controller/pipelines.go
@@ -36,7 +36,7 @@ func (c *Controller) PullRefMetrics(ctx context.Context, ref schemas.Ref) error
// We need a different syntax if the ref is a merge-request
var refName string
if ref.Kind == schemas.RefKindMergeRequest {
- refName = fmt.Sprintf("refs/merge-requests/%s/head", ref.Name)
+ refName = fmt.Sprintf("refs/merge-requests/%s", ref.Name)
} else {
refName = ref.Name
}
diff --git a/pkg/gitlab/pipelines.go b/pkg/gitlab/pipelines.go
index 4557c7a..8c74721 100644
--- a/pkg/gitlab/pipelines.go
+++ b/pkg/gitlab/pipelines.go
@@ -236,6 +236,10 @@ func (c *Client) GetRefsFromPipelines(ctx context.Context, p schemas.Project, re
}
if refKind == schemas.RefKindMergeRequest {
+ // We split the ref into pieces and save the last element to figure out the type of this MR pipeline.
+ // The last element will be "/head" for regular MR pipelines, and "/merge" for merge results pipelines.
+ refParts := strings.Split(refName, "/")
+
if refName, err = schemas.GetMergeRequestIIDFromRefName(refName); err != nil {
log.WithContext(ctx).
WithField("ref", refName).
@@ -244,6 +248,9 @@ func (c *Client) GetRefsFromPipelines(ctx context.Context, p schemas.Project, re
continue
}
+
+ // We attach the MR pipeline type ("/head" or "/merge") to the refName.
+ refName = refName + "/" + refParts[len(refParts)-1]
}
ref := schemas.NewRef(
diff --git a/pkg/schemas/ref.go b/pkg/schemas/ref.go
index 8f403a8..1731410 100644
--- a/pkg/schemas/ref.go
+++ b/pkg/schemas/ref.go
@@ -10,7 +10,7 @@ import (
)
const (
- mergeRequestRegexp string = `^((\d+)|refs/merge-requests/(\d+)/head)$`
+ mergeRequestRegexp string = `^((\d+)|refs/merge-requests/(\d+)/(?:head|merge))$`
// RefKindBranch refers to a branch.
RefKindBranch RefKind = "branch" Note that the ref name that will be exported now includes a suffix. For example for a merge request with ID |
https://docs.gitlab.com/ee/ci/pipelines/merged_results_pipelines.html
It looks like metrics for merged results pipelines are never collected
The text was updated successfully, but these errors were encountered: