Skip to content

Commit

Permalink
Added Assignees count
Browse files Browse the repository at this point in the history
  • Loading branch information
Whyeasy committed Jun 9, 2020
1 parent 4ebc2f0 commit fe946cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type MergeRequestStats struct {
Title string
LastUpdated *time.Time
CreatedAt *time.Time
Assignees int
}

//ApprovalStats is the struct for Gitlab Approvals data we want
Expand Down Expand Up @@ -205,6 +206,7 @@ func getOpenMergeRequests(c *gitlab.Client, errCh chan<- error, wg *sync.WaitGro
ID: strconv.Itoa(mr.ID),
InternalID: mr.IID,
ChangeCount: changeCount.ChangesCount,
Assignees: len(mr.Assignees),
})

}
Expand Down Expand Up @@ -248,6 +250,7 @@ func getMergedMergeRequests(c *gitlab.Client, errCh chan<- error, wg *sync.WaitG
ID: strconv.Itoa(mr.ID),
InternalID: mr.IID,
ChangeCount: changeCount.ChangesCount,
Assignees: len(mr.Assignees),
},
})
}
Expand Down Expand Up @@ -287,6 +290,7 @@ func getClosedMergeRequests(c *gitlab.Client, errCh chan<- error, wg *sync.WaitG
ID: strconv.Itoa(mr.ID),
InternalID: mr.IID,
ChangeCount: changeCount.ChangesCount,
Assignees: len(mr.Assignees),
},
})

Expand Down
7 changes: 6 additions & 1 deletion lib/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Collector struct {
mergeRequestUpdated *prometheus.Desc
mergeRequestChanges *prometheus.Desc
mergeRequestApprovals *prometheus.Desc
mergeRequestAssignees *prometheus.Desc
}

//New creates a new Collector with Prometheus descriptors.
Expand All @@ -40,6 +41,7 @@ func New(c *client.ExporterClient) *Collector {
mergeRequestMerged: prometheus.NewDesc("gitlab_merge_request_merged", "Date of merging the merge request", []string{"merge_request_id", "target_branch", "state", "project_id", "merge_request_title"}, nil),
mergeRequestChanges: prometheus.NewDesc("gitlab_merge_request_changes", "Amount of changed files within the merge request", []string{"merge_request_id", "target_branch", "state", "project_id", "merge_request_title"}, nil),
mergeRequestApprovals: prometheus.NewDesc("gitlab_merge_request_approvals", "Amount of approvals left for approving MR", []string{"merge_request_id", "project_id"}, nil),
mergeRequestAssignees: prometheus.NewDesc("gitlab_merge_request_assignees", "Amount of assignees assigned to the MR", []string{"merge_request_id", "project_id"}, nil),
}
}

Expand All @@ -54,6 +56,7 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.mergeRequestClosed
ch <- c.mergeRequestCreated
ch <- c.mergeRequestMerged
ch <- c.mergeRequestAssignees
}

//Collect gathers the metrics that are exported.
Expand Down Expand Up @@ -100,7 +103,7 @@ func collectOpenMergeRequestMetrics(c *Collector, ch chan<- prometheus.Metric, s
ch <- prometheus.MustNewConstMetric(c.mergeRequestCreated, prometheus.GaugeValue, float64(time.Time(*mr.CreatedAt).Unix()), mr.ID, mr.TargetBranch, mr.State, mr.ProjectID, mr.Title)
ch <- prometheus.MustNewConstMetric(c.mergeRequestUpdated, prometheus.GaugeValue, time.Since(*mr.LastUpdated).Round(time.Second).Seconds(), mr.ID, mr.TargetBranch, mr.State, mr.ProjectID, mr.Title)
ch <- prometheus.MustNewConstMetric(c.mergeRequestChanges, prometheus.GaugeValue, changes, mr.ID, mr.TargetBranch, mr.State, mr.ProjectID, mr.Title)

ch <- prometheus.MustNewConstMetric(c.mergeRequestAssignees, prometheus.GaugeValue, float64(mr.Assignees), mr.ID, mr.ProjectID)
}
}

Expand All @@ -117,6 +120,7 @@ func collectClosedMergeRequestMetrics(c *Collector, ch chan<- prometheus.Metric,
ch <- prometheus.MustNewConstMetric(c.mergeRequestUpdated, prometheus.GaugeValue, time.Since(*mr.MergeRequest.LastUpdated).Round(time.Second).Seconds(), mr.MergeRequest.ID, mr.MergeRequest.TargetBranch, mr.MergeRequest.State, mr.MergeRequest.ProjectID, mr.MergeRequest.Title)
ch <- prometheus.MustNewConstMetric(c.mergeRequestChanges, prometheus.GaugeValue, changes, mr.MergeRequest.ID, mr.MergeRequest.TargetBranch, mr.MergeRequest.State, mr.MergeRequest.ProjectID, mr.MergeRequest.Title)
ch <- prometheus.MustNewConstMetric(c.mergeRequestClosed, prometheus.GaugeValue, float64(time.Time(*mr.ClosedAt).Unix()), mr.MergeRequest.ID, mr.MergeRequest.TargetBranch, mr.MergeRequest.State, mr.MergeRequest.ProjectID, mr.MergeRequest.Title)
ch <- prometheus.MustNewConstMetric(c.mergeRequestAssignees, prometheus.GaugeValue, float64(mr.MergeRequest.Assignees), mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
}
}

Expand All @@ -133,6 +137,7 @@ func collectMergedMergeRequestMetrics(c *Collector, ch chan<- prometheus.Metric,
ch <- prometheus.MustNewConstMetric(c.mergeRequestUpdated, prometheus.GaugeValue, time.Since(*mr.MergeRequest.LastUpdated).Round(time.Second).Seconds(), mr.MergeRequest.ID, mr.MergeRequest.TargetBranch, mr.MergeRequest.State, mr.MergeRequest.ProjectID, mr.MergeRequest.Title)
ch <- prometheus.MustNewConstMetric(c.mergeRequestChanges, prometheus.GaugeValue, changes, mr.MergeRequest.ID, mr.MergeRequest.TargetBranch, mr.MergeRequest.State, mr.MergeRequest.ProjectID, mr.MergeRequest.Title)
ch <- prometheus.MustNewConstMetric(c.mergeRequestMerged, prometheus.GaugeValue, 0.0, mr.MergeRequest.ID, mr.MergeRequest.TargetBranch, mr.MergeRequest.State, mr.MergeRequest.ProjectID, mr.MergeRequest.Title)
ch <- prometheus.MustNewConstMetric(c.mergeRequestAssignees, prometheus.GaugeValue, float64(mr.MergeRequest.Assignees), mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
}
}

Expand Down

0 comments on commit fe946cd

Please sign in to comment.