immobiliare / backstage-plugin-gitlab

Backstage plugins to interact with GitLab
Apache License 2.0
115 stars 39 forks source link

Error when using self hosted GitLab with subpath + GitLab filler processor #333

Closed dfl-aeb closed 11 months ago

dfl-aeb commented 11 months ago

I'm experiencing an issue because our self hosted gitlab instance runs under a subpath. e.g. git.company.com/gitlab

When trying to access git.company.com/gitlab/genc/infrastructure/docker the GitLab Filler Processor tries to call git.company.com/projects/gitlab/genc/infrastructure/docker instead of git.company.com/gitlab/projects/genc/infrastructure/docker --> http://localhost:8080/api/gitlab/rest/git.company.com/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker

Maybe related to: https://github.com/immobiliare/backstage-plugin-gitlab/issues/236

Everything else works fine, just the gitlab filler processor does not.

antoniomuso commented 11 months ago

Can you post your Backstage gitlab configurations?

dfl-aeb commented 11 months ago
integrations:
  gitlab:
    - host: git.company.com
      apiBaseUrl: https://git.company.com/gitlab/api/v4
      baseUrl: https://git.company.com/gitlab
      token: ${GITLAB_TOKEN}

proxy:
  '/gitlabci':
    target: 'https://git.company.com/gitlab/api/v4'
    allowedMethods: ['GET', 'POST']
    headers:
      PRIVATE-TOKEN: '${GITLAB_TOKEN}'

gitlab: #for gitlab plugin: https://github.com/immobiliare/backstage-plugin-gitlab
  defaultCodeOwnersPath: .gitlab/CODEOWNERS
antoniomuso commented 11 months ago

The proxy is not needed anymore you can remove it. The URL you posted is right. PS: the processor doesn't do requests.

antoniomuso commented 11 months ago

can you post the request error ?

dfl-aeb commented 11 months ago

The request is a simple get http://localhost:8080/api/gitlab/rest/git.company.com/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker that results in a 404 not found

antoniomuso commented 11 months ago

I mean the request done by the server. Because the client's request is correct, it should be formed this way.

dfl-aeb commented 11 months ago
[1] 2023-11-23T14:34:57.936Z backstage info ::1 - - [23/Nov/2023:14:34:57 +0000] "GET /api/gitlab/rest/git.company.com/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker?? HTTP/1.1" 404 35 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0" type=incomingRequest
[1] 2023-11-23T14:34:57.940Z gitlab debug [HPM] Rewriting path from "/api/gitlab/rest/git.company.com/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker??" to "/gitlab/api/v4/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker??" type=plugin

[1] 2023-11-23T14:34:58.036Z backstage info ::1 - - [23/Nov/2023:14:34:58 +0000] "GET /api/gitlab/rest/git.company.com/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker?? HTTP/1.1" 404 35 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0" type=incomingRequest
[1] 2023-11-23T14:34:58.038Z gitlab debug [HPM] Rewriting path from "/api/gitlab/rest/git.company.com/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker??" to "/gitlab/api/v4/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker??" type=plugin
[1] 2023-11-23T14:34:58.139Z backstage info ::1 - - [23/Nov/2023:14:34:58 +0000] "GET /api/gitlab/rest/git.company.com/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker?? HTTP/1.1" 404 35 "http://localhost:3000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0" type=incomingRequest

The 404 error occurs because the project is prefixed with the subpath from our gitlab instance /gitlab

Rewriting path from "/api/gitlab/rest/git.company.com/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker??" to "/gitlab/api/v4/projects/gitlab%2Fgenc%2Finfrastructure%2Fdocker??"

Rewriting path from "/api/gitlab/rest/git.company.com/projects/
+gitlab
%2Fgenc%2Finfrastructure%2Fdocker??" 
to 
"/gitlab/api/v4/projects/
+gitlab
%2Fgenc%2Finfrastructure%2Fdocker??"

The right path should be /api/gitlab/rest/git.company.com/projects/genc%2Finfrastructure%2Fdocker??

`/api/gitlab/rest/git.company.com/projects/
-gitlab
genc%2Finfrastructure%2Fdocker??`
dfl-aeb commented 11 months ago

I think the problem is related to the gitlab configuration only using the host config value instead of the baseUrl specified here

antoniomuso commented 11 months ago

mm it is strange, can you post the annonations inside the entity?

 'gitlab.com/project-slug'
 'gitlab.com/instance'
dfl-aeb commented 11 months ago

This error only occurs, when we don't set any annotation. When setting gitlab.com/project-slug: genc/applications/genc/infrastructure/docker everthing works as expected

antoniomuso commented 11 months ago

If you go to backstage entity without setting the annotations, you click on three dots in the top right corner, you click inspect entity, and you can see the annotations assigned by the processor. Can you post the values of them?

dfl-aeb commented 11 months ago
gitlab.com/instance:
    git.company.com/gitlab
gitlab.com/project-slug:
    gitlab/genc/applications/genc/infrastructure/docker
antoniomuso commented 11 months ago

Ok, the project slug is wrong. I created a PR to fix it.

dfl-aeb commented 11 months ago

Amazing, thanks for your quick help!

antoniomuso commented 11 months ago

@dfl-aeb I created a new prerelease. Can you test it? Let me know if it works now!

dfl-aeb commented 11 months ago

That fixed it! Thank you again :)

antoniomuso commented 11 months ago

Ok thank you, I release the new version.