Skip to content
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

Specify a prefix for limiting the list of Gerrit Projects #391

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucamilanesio
Copy link
Member

The GerritServer thread executes an unlimited gerrit ls-projects
at startup which has two major issues:

  1. May take a very long time, because the list of projects could
    be huge, even hundreds of thousands of repositories.

  2. May cause trouble to the Gerrit Server that has to load ALL
    projects in memory to access their configuration and evaluate
    the ACLs.

By introducing a projects prefix pattern, the GerritServer startup
speed could be increased by 20x or even 100x, depending on the
Gerrit server that is connecting to.

The GerritServer thread executes an unlimited gerrit ls-projects
at startup which has two major issues:

1. May take a very long time, because the list of projects could
   be huge, even hundreds of thousands of repositories.

2. May cause trouble to the Gerrit Server that has to load *ALL*
   projects in memory to access their configuration and evaluate
   the ACLs.

By introducing a projects prefix pattern, the GerritServer startup
speed could be increased by 20x or even 100x, depending on the
Gerrit server that is connecting to.
* @param projectPrefix prefix of the projects to list from the Gerrit Server.
*/
@Exported
public void setProjectPrefix(String projectPrefix) {
Copy link
Contributor

@dpursehouse dpursehouse Jan 28, 2019

Choose a reason for hiding this comment

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

Maybe I'm missing something, but where does this get called?

If it's not called from anywhere, the projectPrefix is uninitialized which results in the full list being returned, i.e. the same behavior as before.

Copy link
Member Author

Choose a reason for hiding this comment

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

For backward compatibility, it will work as before.

Need to find a place to hook into it, do you have any suggestions? I’m not very familiar with this codebase :-(

Copy link
Member

Choose a reason for hiding this comment

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

Yes this uses an outdated way of doing Jenkins form submission. See public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException... in the decriptor.

@@ -54,8 +54,9 @@
/**
* The command for fetching projects.
*/
public static final String GERRIT_LS_PROJECTS = "gerrit ls-projects";
public static final String GERRIT_LS_PROJECTS = "gerrit ls-projects --prefix ";
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: The --prefix option is not documented on the ls-projects command for 2.14, 2.15 or 2.16.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, this needs to be fixed in Gerrit though.

With regards to the support in Gerrit < 2.13, needs to be documented in this plugin and checked as soon as the version is queried.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've posted the documentation for review https://gerrit-review.googlesource.com/c/gerrit/+/212012

Copy link
Contributor

@dpursehouse dpursehouse left a comment

Choose a reason for hiding this comment

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

See inline comments.

@@ -239,7 +242,8 @@ private void tryLoadProjectList() {
activeConfig.getGerritProxy(),
activeConfig.getGerritAuthentication()
);
List<String> projects = readProjects(sshConnection.executeCommandReader(GERRIT_LS_PROJECTS));
List<String> projects = readProjects(sshConnection
.executeCommandReader(GERRIT_LS_PROJECTS + projectPrefix));
Copy link
Member

Choose a reason for hiding this comment

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

Should we assume that htis works if projectPrefix is an empty string?
In that case I guess it won't work when it's null

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.

3 participants