Bug: Jira API error when associating > 500 Jira issue keys with a deployment
This bug issue came from this thread https://gitlab.com/gitlab-org/gitlab/-/issues/431651#note_1971140316. ### About The Jira API can return an error response when we try to associate a deployment with > 500 Jira issue keys. When we have [more than 500 Jira issue keys associated here](https://gitlab.com/gitlab-org/gitlab/-/blob/c532a849858a2a0977b9cd563dea91bd9861f6d0/lib/atlassian/jira_connect/serializers/deployment_entity.rb#L37) with a deployment, after we POST to the Jira `POST /rest/deployments/0.1/bulk` endpoint, we see an error. ```json {"errorMessages":["Sum of Association values across all association types can have a maximum of 500 elements. Found 3143."] ... } ``` [Examples of the errors are included in this Kibana filter](https://log.gprd.gitlab.net/app/r/s/asbDA). From the [endpoint documentation](https://developer.atlassian.com/cloud/jira/software/rest/api-group-deployments/#api-rest-deployments-0-1-bulk-post): ![image](https://gitlab.com/-/project/278964/uploads/39421b8f38d12113c46b6c8063bf1856/image.png){width="554" height="316"} ### Problem These errors means that for the affected deployments, they are not being associated with Jira issue keys. ### Proposal In https://gitlab.com/gitlab-org/gitlab/-/issues/470092#note_1977592412 we learned that we can POST through the `associations[].values` in batches of 500 values at a time to associate a deployment with > 500 values. We currently [POST a collection of deployments](https://gitlab.com/gitlab-org/gitlab/-/blob/221f138b09c7873d21ada8e875e18ed97d6c42c9/lib/atlassian/jira_connect/client.rb#L80) in one request. Although, it looks like we currently only ever [operate on single deployments](https://gitlab.com/gitlab-org/gitlab/-/blob/a958ab444d6478f2b6d2a4516d224f0c459471a0/app/workers/jira_connect/sync_deployments_worker.rb#L22) at a time. - If all deployments in the `items` collection [here](https://gitlab.com/gitlab-org/gitlab/-/blob/221f138b09c7873d21ada8e875e18ed97d6c42c9/lib/atlassian/jira_connect/client.rb#L80) do not have any `associations` that have > 500 items [in `values`](https://gitlab.com/gitlab-org/gitlab/-/blob/789ade901e876c221d7ba3dd551f85d29e2d114c/lib/atlassian/jira_connect/serializers/deployment_entity.rb#L40) then POST as normal. - Otherwise, slice those associations values and do subsequent POSTs using those values, repeating in batches of 500. - Limit total number of batched requests to 5, limiting total number of issue keys to 2,500.
issue