Skip to content

Commit

Permalink
chore: improve logging to debug why no projects are legible for eval …
Browse files Browse the repository at this point in the history
…cycles
  • Loading branch information
jippi committed Aug 30, 2024
1 parent c988288 commit 2c986a0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
5 changes: 4 additions & 1 deletion cmd/gitlab_server_periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func startPeriodicEvaluation(ctx context.Context, interval time.Duration, filter
return

case <-ticker.C:
// Track all log output back to a periodic evaluation cycle
ctx := slogctx.With(ctx, slog.String("periodic_eval_id", sid.MustGenerate()))

slogctx.Info(ctx, "Starting periodic evaluation cycle")

results, err := client.FindMergeRequestsForPeriodicEvaluation(ctx, filter)
Expand All @@ -72,7 +75,7 @@ func startPeriodicEvaluation(ctx context.Context, interval time.Duration, filter
continue
}

slogctx.Info(ctx, fmt.Sprintf("Found %d merge requests to evaluate", len(results)), slog.Int("number_of_projects", len(results)))
slogctx.Info(ctx, fmt.Sprintf("Found %d Merge Requests to evaluate", len(results)), slog.Int("number_of_projects", len(results)))

for _, mergeRequest := range results {
ctx := ctx // make sure we define a fresh GC-able context per merge request so we don't append to the existing forever
Expand Down
5 changes: 5 additions & 0 deletions pkg/scm/gitlab/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gitlab

import (
"context"
"fmt"
"log/slog"
"net/http"
"net/url"
Expand Down Expand Up @@ -81,9 +82,13 @@ func (client *Client) FindMergeRequestsForPeriodicEvaluation(ctx context.Context
return nil, err
}

slogctx.Debug(ctx, fmt.Sprintf("Found %d projects", len(response.Projects.Nodes)))

var result []scm.PeriodicEvaluationMergeRequest

for _, project := range response.Projects.Nodes {
slogctx.Debug(ctx, fmt.Sprintf("Project %s has %d Merge Requests", project.FullPath, len(project.MergeRequests.Nodes)))

for _, mr := range project.MergeRequests.Nodes {
item := scm.PeriodicEvaluationMergeRequest{
Project: project.FullPath,
Expand Down
70 changes: 49 additions & 21 deletions pkg/scm/gitlab/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,56 @@ package gitlab
// PeriodicEvaluationResult structs maps to the GraphQL query used to find Merge Requests
// that should be periodically evaluated.
//
// It roughly matches this GraphQL query (via Go structs and field tags)
// GraphQL query:
//
// query($project_topics: [String!], $config_file: String! = ".scm-engine.yml", $project_membership: Boolean, $mr_ignore_labels: [String!]) {
// projects(first: 100, membership: $project_membership, withMergeRequestsEnabled: true, topics: $project_topics) {
// nodes {
// fullPath
// repository {
// blobs(paths: $config_file) {
// nodes {
// rawBlob
// }
// }
// }
// mergeRequests(first: 100, state: opened, not: {labels: $mr_ignore_labels}, sort: UPDATED_ASC) {
// nodes {
// iid
// diffHeadSha
// }
// }
// }
// }
// }
// query (
// $project_topics: [String!],
// $config_file: String!,
// $project_membership: Boolean,
// $mr_ignore_labels: [String!],
// $mr_require_labels: [String!]
// ) {
// projects(
// first: 100
// membership: $project_membership
// withMergeRequestsEnabled: true
// topics: $project_topics
// ) {
// nodes {
// fullPath
// repository {
// blobs(paths: [$config_file]) {
// nodes {
// rawBlob
// }
// }
// }
// mergeRequests(
// first: 100,
// state: opened,
// not: {labels: $mr_ignore_labels},
// labels: $mr_require_labels,
// sort: UPDATED_ASC
// ) {
// nodes {
// iid
// diffHeadSha
// }
// }
// }
// }
// }
//
// Query Variables
//
// {
// "config_file": ".scm-engine.yml",
// "project_topics": ["scm-engine"],
// "project_membership": true,
// "mr_ignore_labels": ["security", "do-not-close"],
// "mr_ignore_labels": []
// }

type PeriodicEvaluationResult struct {
// Projects contains first 100 projects that matches the filtering conditions
Projects graphqlNodesOf[PeriodicEvaluationProjectNode] `graphql:"projects(first: 100, membership: $project_membership, withMergeRequestsEnabled: true, topics: $project_topics)"`
Expand Down

0 comments on commit 2c986a0

Please sign in to comment.