Skip to content

Commit

Permalink
fix artifacts metrics collection (#76)
Browse files Browse the repository at this point in the history
* fix artifacts metrics collection

* remove binary (oops)
  • Loading branch information
dkulchinsky authored Jan 26, 2021
1 parent 345a695 commit fe2994f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
github.com/prometheus/client_golang v1.7.0 h1:wCi7urQOGBsYcQROHqpUUX4ct84xp40t9R9JX0FuA/U=
github.com/prometheus/client_golang v1.7.0/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.9.0 h1:Rrch9mh17XcxvEu9D9DEpb4isxjGBtcevQjKvxPRQIU=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
11 changes: 7 additions & 4 deletions metric_artifacts.go → metrics_artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"net/url"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -38,9 +39,10 @@ type scanOverview struct {
Summary struct {
Fixable int `json:"fixable"`
Summary struct {
High int `json:"High"`
Low int `json:"Low"`
Medium int `json:"Medium"`
Critical int `json:"Critical"`
High int `json:"High"`
Medium int `json:"Medium"`
Low int `json:"Low"`
} `json:"summary"`
Total int `json:"total"`
} `json:"summary"`
Expand Down Expand Up @@ -138,6 +140,7 @@ func (h *HarborExporter) collectArtifactsMetric(ch chan<- prometheus.Metric) boo
ch <- prometheus.MustNewConstMetric(vulnMI.Desc, vulnMI.Type, float64(scanInfo.Summary.Summary.Low), projectName, projectID, repoName, repoID, artName, artID, reportID, "low")
ch <- prometheus.MustNewConstMetric(vulnMI.Desc, vulnMI.Type, float64(scanInfo.Summary.Summary.Medium), projectName, projectID, repoName, repoID, artName, artID, reportID, "medium")
ch <- prometheus.MustNewConstMetric(vulnMI.Desc, vulnMI.Type, float64(scanInfo.Summary.Summary.High), projectName, projectID, repoName, repoID, artName, artID, reportID, "high")
ch <- prometheus.MustNewConstMetric(vulnMI.Desc, vulnMI.Type, float64(scanInfo.Summary.Summary.Critical), projectName, projectID, repoName, repoID, artName, artID, reportID, "critical")

// Scan Status.
ch <- prometheus.MustNewConstMetric(scansDurMI.Desc, scansDurMI.Type, float64(scanInfo.Duration), projectName, projectID, repoName, repoID, artName, artID, reportID)
Expand Down Expand Up @@ -249,7 +252,7 @@ func (h *HarborExporter) loadArtifacts(projectName string, repoData repositories
var reqURL string
if h.isV2 {
reqURL = "/projects/" + projectName +
"/repositories" + strings.TrimLeft(repoData[i].Name, projectName) +
"/repositories/" + url.PathEscape(strings.TrimLeft(repoData[i].Name, projectName+"/")) +
"/artifacts?with_tag=true&with_scan_overview=true"
} else {
panic("No v1 API support")
Expand Down

0 comments on commit fe2994f

Please sign in to comment.