Skip to content

Conversation

@kashifkhan0771
Copy link
Contributor

@kashifkhan0771 kashifkhan0771 commented Dec 18, 2025

This PR refactors simplifiedGitlabEnumeration to use the legacy pagination API with keyset pagination instead of Scan2, which is currently in an experimental state. This change is intended as an experiment and does not guarantee a fix for the issue.

Additionally, it introduces retry logic to handle 500-level errors and adds logging to track the number of projects being enumerated.

Related issue on Gitlab: https://gitlab.com/gitlab-com/gl-infra/production/-/issues/7516

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

This commit rewrite simplifiedGitlabEnumeration to use legacy pagination API call with keyset pagination instead of Scan2 which is currently in experimental state. Note
that this doesn't promise to fix this problem it's just a test to check. It also adds a retry logic in case any 500 error occurs. I added some logs as well to keep track
of no of projects being enumerated.
@kashifkhan0771 kashifkhan0771 requested a review from a team December 18, 2025 09:21
@kashifkhan0771 kashifkhan0771 requested a review from a team as a code owner December 18, 2025 09:21
@kashifkhan0771 kashifkhan0771 changed the title Backoff from Scan2 which is experimental to legacy pagination API call Gitlab Source: Backoff from Scan2 which is experimental to legacy pagination API call Dec 18, 2025
Copy link
Contributor

@martinlocklear martinlocklear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this! Some notes:

  • Definitely need test coverage for this before merging in.
  • I notice in our go.mod we're overriding the version of the library we're using. Is it possible that some of the issues that we've been seeing could be fixed by newer versions of this library?

Copy link
Contributor

@martinlocklear martinlocklear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need to add unit testing before we merge this.

Reversed the gitlab cloud logic to add membership flag, so that we use the default false for non gitlab.com instances.
This can help if the issue really was membership flag as mentioned in some gitlab issues.
Also added simple flag in list projects to get only minimal fields in response instead of big json response for each project.

Added test case as well.
@kashifkhan0771
Copy link
Contributor Author

I think we still need to add unit testing before we merge this.

Added the test case

Copy link
Contributor

@camgunz camgunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! If you want you could add a couple more checks in the test, like I'm pretty sure some other sources check chunk count and so on. But up to you--I know you've done a lot of local testing w/ this.

@camgunz
Copy link
Contributor

camgunz commented Jan 8, 2026

@martinlocklear

I notice in our go.mod we're overriding the version of the library we're using. Is it possible that some of the issues that we've been seeing could be fixed by newer versions of this library?

I just had a look, and while the changelog doesn't go as far back as our pinned version, I didn't see any bug fix that would've affected us. I made INS-249 to do this some day.

@kashifkhan0771
Copy link
Contributor Author

I notice in our go.mod we're overriding the version of the library we're using. Is it possible that some of the issues that we've been seeing could be fixed by newer versions of this library?

Somehow I missed this comment. The reason we did that was the latest version at that time was v1.134.0 but it deprecated existing Auth methods, also the Scan2 API was experimental so we pinned to version to avoid any new updates which accidentally break the API.

As Charlie said there isn't any bug fix in later versions, so I would prefer to update that in a separate PR.

// use simplified gitlab enumeration
feature.UseSimplifiedGitlabEnumeration.Store(true)

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use the testing context, I think it's t.Context()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Context() returns the standard library context.Context, but this codebase uses TruffleHog’s custom context.Context (pkg/context) which extends the standard context with additional methods. Because of that, t.Context() cannot be used here - the types are incompatible.

@martinlocklear
Copy link
Contributor

Some non-blocking comments about the new test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants