ShivamSharma43 opened a new issue, #9422:
URL: https://github.com/apache/devlake/issues/9422

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/devlake/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### What happened
   
   `convertIncidents` in the PagerDuty plugin 
(`plugins/pagerduty/tasks/incidents_converter.go`) joins assignments and users 
to incidents without the connection id:
   
   ```go
   dal.From("_tool_pagerduty_incidents AS pi"),
   dal.Join(`LEFT JOIN _tool_pagerduty_assignments AS pa ON pa.incident_number 
= pi.number`),
   dal.Join(`LEFT JOIN _tool_pagerduty_users AS pu ON pa.user_id = pu.id`),
   dal.Where("pi.connection_id = ? AND pi.service_id = ?", ...),
   ```
   
   Only the incidents are filtered by connection. PagerDuty incident numbers 
are per account (every account starts at 1), and `_tool_pagerduty_assignments` 
and `_tool_pagerduty_users` hold the rows of all connections, each with its 
`connection_id`. So with two PagerDuty connections, incident #5 of connection 1 
is also joined to the assignments of incident #5 of connection 2, and to every 
user row with the assignee's id in any connection. As a result:
   
   - the issue gets extra `issue_assignees` rows for users of the other account;
   - `issues.assignee_id` / `assignee_name` is set to the other account's user 
when that assignment is newer (the converter keeps the latest assignment), and 
incidents with no assignee get one from the other account;
   - a user id stored under two connections returns two rows per assignment, 
and the assignee name can come from the other connection.
   
   ### What do you expect to happen
   
   An incident only gets the assignments and users of its own connection.
   
   ### How to reproduce
   
   1. Add two PagerDuty connections (two accounts) and sync a service in each, 
so both have an incident with the same number (e.g. #5).
   2. Check `issue_assignees` and `issues.assignee_name` for 
`pagerduty:Incident:1:5`: they include the assignees of incident #5 of 
connection 2.
   
   The same happens in the e2e test: after extracting connection 1, add 
`_tool_pagerduty_assignments` rows with `connection_id = 2` for incident 
numbers 5 and 6 (and their users), then run `convertIncidents` for connection 
1. Incident 6, which has no assignee, gets the connection 2 user, incident 5's 
assignee becomes the connection 2 user, and `issue_assignees` has 5 rows 
instead of 3.
   
   ### Anything else
   
   Proposed fix (I have a PR ready): join `pa.connection_id = pi.connection_id` 
and `pu.connection_id = pa.connection_id`, and extend the PagerDuty e2e test 
with rows from a second connection.
   
   ### Version
   
   main
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to