Skip to content

Commit

Permalink
Exporting duration correctly to seconds now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Whyeasy committed Jul 13, 2020
1 parent 21509ff commit 065cef1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/client/mergeRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
type MergeClosedStats struct {
MergeRequest MergeRequestStats
ClosedAt *time.Time
Duration time.Duration
Duration float64
}

//MergeMergedStats is the strucct for merged merge requests
type MergeMergedStats struct {
MergeRequest MergeRequestStats
MergedAt *time.Time
Duration time.Duration
Duration float64
}

//MergeRequestStats is the base struct for Gitlab Merge Requests data we want
Expand Down Expand Up @@ -192,9 +192,11 @@ func getMergedMergeRequests(c *gitlab.Client, errCh chan<- error, wg *sync.WaitG
return nil
}

duration, _ := time.ParseDuration(result.MergedAt.Sub(*result.CreatedAt).String())

resultMerged = append(resultMerged, MergeMergedStats{
MergedAt: result.MergedAt,
Duration: result.MergedAt.Sub(*result.CreatedAt),
Duration: duration.Seconds(),
MergeRequest: MergeRequestStats{
ProjectID: strconv.Itoa(result.ProjectID),
ID: strconv.Itoa(result.ID),
Expand Down Expand Up @@ -224,9 +226,11 @@ func getClosedMergeRequests(c *gitlab.Client, errCh chan<- error, wg *sync.WaitG
return nil
}

duration, _ := time.ParseDuration(result.ClosedAt.Sub(*result.CreatedAt).String())

resultClosed = append(resultClosed, MergeClosedStats{
ClosedAt: result.ClosedAt,
Duration: result.ClosedAt.Sub(*result.CreatedAt),
Duration: duration.Seconds(),
MergeRequest: MergeRequestStats{
ProjectID: strconv.Itoa(result.ProjectID),
ID: strconv.Itoa(result.ID),
Expand Down
4 changes: 2 additions & 2 deletions lib/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func collectClosedMergeRequestMetrics(c *Collector, ch chan<- prometheus.Metric,
ch <- prometheus.MustNewConstMetric(c.mergeRequestChangedFiles, prometheus.GaugeValue, changes, mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
ch <- prometheus.MustNewConstMetric(c.mergeRequestClosed, prometheus.GaugeValue, float64(time.Time(*mr.ClosedAt).Unix()), mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
ch <- prometheus.MustNewConstMetric(c.mergeRequestAssignees, prometheus.GaugeValue, float64(mr.MergeRequest.Assignees), mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
ch <- prometheus.MustNewConstMetric(c.mergeRequestDuration, prometheus.GaugeValue, float64(mr.Duration), mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
ch <- prometheus.MustNewConstMetric(c.mergeRequestDuration, prometheus.GaugeValue, mr.Duration, mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
}
}

Expand All @@ -166,7 +166,7 @@ func collectMergedMergeRequestMetrics(c *Collector, ch chan<- prometheus.Metric,
ch <- prometheus.MustNewConstMetric(c.mergeRequestChangedFiles, prometheus.GaugeValue, changes, mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
ch <- prometheus.MustNewConstMetric(c.mergeRequestMerged, prometheus.GaugeValue, float64(time.Time(*mr.MergedAt).Unix()), mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
ch <- prometheus.MustNewConstMetric(c.mergeRequestAssignees, prometheus.GaugeValue, float64(mr.MergeRequest.Assignees), mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
ch <- prometheus.MustNewConstMetric(c.mergeRequestDuration, prometheus.GaugeValue, float64(mr.Duration), mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
ch <- prometheus.MustNewConstMetric(c.mergeRequestDuration, prometheus.GaugeValue, mr.Duration, mr.MergeRequest.ID, mr.MergeRequest.ProjectID)
}
}

Expand Down

0 comments on commit 065cef1

Please sign in to comment.