Skip to content

Commit 4a395d1

Browse files
authored
Merge pull request #39 from ITNavent/fix-cls-parse
Fixed CLS parse that always returned 0
2 parents 5bc3daa + add4be8 commit 4a395d1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

collector/collector.go

+4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ func collectLighthouseResults(prefix string, lhr *pagespeedonline.LighthouseResu
177177

178178
for k, v := range lhr.Audits {
179179
re := regexp.MustCompile(`(\d*[.]?\d+(ms|s))|0`)
180+
timeRe := regexp.MustCompile(`(ms|s)`)
180181

181182
if timeAuditMetrics[k] {
182183
displayValue := strings.Replace(v.DisplayValue, "\u00a0", "", -1)
183184
displayValue = strings.Replace(displayValue, ",", "", -1)
185+
if !timeRe.MatchString(displayValue) {
186+
displayValue = displayValue + "s"
187+
}
184188

185189
if duration, errDuration := time.ParseDuration(re.FindString(displayValue)); errDuration == nil {
186190
ch <- prometheus.MustNewConstMetric(

0 commit comments

Comments
 (0)