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

feat(azuredevops): implement work items as issues #7809

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

slaterx
Copy link

@slaterx slaterx commented Aug 1, 2024

Summary

This PR adds support for Azure DevOps work items as issues. The main thing to consider is that in Azure DevOps, work items are connected to projects and orgs, not repositories. Furthermore, current API definitions in Azure DevOps have a few limitations on retrieving work items data. Finally, work item queries are heavy and consume a lot of TSTUs, meaning that a simple query can impact overall organization usage of Azure DevOps and block access to services.

Thus, the decision was to:

  • Break down the retrieval into two API calls, one to obtain the work item ids (using the WQL API) and another one to obtain the actual work items in small chunks (using the work item batch API), avoiding throttling issues.
  • Use custom code instead of default converter code to store data in issues table.
  • Add issue UI components to azure devops page scope configuration.
  • Add issue dashboard panels to Azure DevOps grafana page, but remove repository reference from queries.

Does this close any open issues?

Closes #5996

Screenshots

image

Other Information

With all work items collected, and their boards stored as component, having incidents mapped is as easy as querying work items with type = bug.

Copy link
Contributor

@mr-ks mr-ks left a comment

Choose a reason for hiding this comment

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

Could you please check the GitHub Actions workflow? Some of the checks are failing e.g the golangci-lint check

@@ -0,0 +1,2 @@
id,params,data,url,input
1234,"{""OrganizationId"":""johndoe"",""RepositoryId"":""0d50ba13-f9ad-49b0-9b21-d29eda50ca33"",""ProjectId"":""test-project""}",com.intellij.database.extractors.TextInfo@d75361af,https://dev.azure.com/johndoe/test-project/_apis/wit/workitemsbatch?%24skip=0&%24top=0&api-version=7.1
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please check the value of the data column? com.intellij.database.extractors.TextInfo@d75361af appears to be an export error to me.

thisRequestBody := func(reqData *api.RequestData) map[string]interface{} {
return map[string]interface{}{
"ids": currentWorkItems,
"fields": []string{"System.Id", "System.Title", "System.TeamProject", "System.Description", "System.Reason", "System.AreaPath", "System.WorkItemType", "System.State", "System.CreatedDate", "System.ChangedDate", "System.CreatedBy", "System.AssignedTo", "Microsoft.VSTS.Scheduling.Effort", "Microsoft.VSTS.Common.Priority", "Microsoft.VSTS.Common.Severity"},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to make this configurable for the end user. Due to the dynamic nature of Azure DevOps, it is very hard to make assumptions about which property is used and which is not. If I got it right, Microsoft.VSTS.Scheduling.StoryPoints is used in the Agile template instead of Microsoft.VSTS.Scheduling.Effort.


const RawWorkitemsTable = "azuredevops_go_api_workitems"

var CollectWorkitemsMeta = plugin.SubTaskMeta{
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not mistaken, this task runs for each data scope linked to a DevLake project, meaning we read all work items in an Azure DevOps project n times if n data scopes are attached. This can quickly deplete the quota for large projects with many work items.

RequestBody: func(reqData *api.RequestData) map[string]interface{} {

return map[string]interface{}{
"query": `SELECT [System.Id] FROM workitems WHERE [System.TeamProject] = "` + data.Options.ProjectId + `" ORDER BY [System.ChangedDate] DESC`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Integrating an additional time filter condition in the WHERE clause can help us to integrate the project-level sync policy settings and provide an incremental mode. There is a nice example in the jira implementation:

if apiCollector.GetSince() != nil {

thisRequestBody := func(reqData *api.RequestData) map[string]interface{} {
return map[string]interface{}{
"ids": currentWorkItems,
"fields": []string{"System.Id", "System.Title", "System.TeamProject", "System.Description", "System.Reason", "System.AreaPath", "System.WorkItemType", "System.State", "System.CreatedDate", "System.ChangedDate", "System.CreatedBy", "System.AssignedTo", "Microsoft.VSTS.Scheduling.Effort", "Microsoft.VSTS.Common.Priority", "Microsoft.VSTS.Common.Severity"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please check if all of the required fields are actually being used? System.Reason is a very special one that is also not mapped to the Devlake Issue domain type.

rawWorkItems.ForEach(func(key, value gjson.Result) bool {
currentWorkItems = append(currentWorkItems, value.String())

if len(currentWorkItems) == 9 || key.Int() == int64(len(rawWorkItems.Array())-1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please explain how you came up with this condition? Is this a restriction of the /workitemsbatch API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/plugins This issue or PR relates to plugins needs-cherrypick-v1.0 pr-type/feature-development This PR is to develop a new feature size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature][Azure devops] Collect Boards from Azure DevOps to supply incidents data for DORA
2 participants