Skip to content

Commit

Permalink
Fix missing replication metrics (#81)
Browse files Browse the repository at this point in the history
* Fix missing replication metrics

* Extends replication metrics by repl_trigger_type label

Co-authored-by: Stephan Liegmann <[email protected]>
  • Loading branch information
v9rt3x and Stephan Liegmann authored Feb 25, 2021
1 parent 9905040 commit 8f24e7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ make dockerbuild
|harbor_repositories_star_total| |repo_id, repo_name|
|harbor_repositories_tags_total| |repo_id, repo_name|
|harbor_repositories_latency| | |
|harbor_replication_status|status of the last execution of this replication policy: Succeed = 1, any other status = 0|repl_pol_name|
|harbor_replication_tasks|number of replication tasks, with various results, in the latest execution of this replication policy|repl_pol_name, result=[failed, succeed, in_progress, stopped]|
|harbor_replication_status|status of the last execution of this replication policy: Succeed = 1, any other status = 0|repl_pol_name, repl_trigger_type[manual, scheduled, event_based]|
|harbor_replication_tasks|number of replication tasks, with various results, in the latest execution of this replication policy|repl_pol_name, repl_trigger_type[manual, scheduled, event_based], result=[failed, succeed, in_progress, stopped]|
|harbor_system_info | |auth_mode, project_creation_restriction, harbor_version, registry_storage_provider_name
|harbor_system_with_notary | |
|harbor_system_self_registration | |
Expand Down
4 changes: 2 additions & 2 deletions harbor_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ var (
artifactsVulnerabilitiesScansLabelNames = []string{"project_name", "project_id", "repo_name", "repo_id", "artifact_name", "artifact_id", "tag"}
artifactVulnerabilitiesDurationLabelNames = []string{"project_name", "project_id", "repo_name", "repo_id", "artifact_name", "artifact_id", "report_id", "tag"}
storageLabelNames = []string{"storage"}
replicationLabelNames = []string{"repl_pol_name"}
replicationTaskLabelNames = []string{"repl_pol_name", "result"}
replicationLabelNames = []string{"repl_pol_name", "repl_trigger_type"}
replicationTaskLabelNames = []string{"repl_pol_name", "repl_trigger_type", "result"}
systemInfoLabelNames = []string{"auth_mode", "project_creation_restriction", "harbor_version", "registry_storage_provider_name"}
)

Expand Down
17 changes: 9 additions & 8 deletions metrics_replications.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ func (h *HarborExporter) collectReplicationsMetric(ch chan<- prometheus.Metric)
}

for i := range policiesData {
if policiesData[i].Enabled == true && policiesData[i].Trigger.Type == "scheduled" {
if policiesData[i].Enabled == true {
policyID := strconv.FormatFloat(policiesData[i].ID, 'f', 0, 32)
policyName := policiesData[i].Name
triggerType := policiesData[i].Trigger.Type

body, _ := h.request("/replication/executions?policy_id=" + policyID + "&page=1&page_size=2")
var data policyMetric
Expand All @@ -59,11 +60,11 @@ func (h *HarborExporter) collectReplicationsMetric(ch chan<- prometheus.Metric)

if len(data) == 0 {
level.Debug(h.logger).Log("msg", "Policy "+policyName+" (ID "+policyID+") has no executions yet")
return false
continue
}

var j int = 0
if data[j].Status == "InProgress" && len(data) > 1 {
if len(data) > 1 && data[j].Status == "InProgress" {
// Current is in progress: check previous replication execution
j = 1
}
Expand All @@ -74,19 +75,19 @@ func (h *HarborExporter) collectReplicationsMetric(ch chan<- prometheus.Metric)
replStatus = 1
}
ch <- prometheus.MustNewConstMetric(
allMetrics["replication_status"].Desc, allMetrics["replication_status"].Type, replStatus, policyName,
allMetrics["replication_status"].Desc, allMetrics["replication_status"].Type, replStatus, policyName, triggerType,
)
ch <- prometheus.MustNewConstMetric(
allMetrics["replication_tasks"].Desc, allMetrics["replication_tasks"].Type, data[j].Failed, policyName, "failed",
allMetrics["replication_tasks"].Desc, allMetrics["replication_tasks"].Type, data[j].Failed, policyName, triggerType, "failed",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["replication_tasks"].Desc, allMetrics["replication_tasks"].Type, data[j].Succeed, policyName, "succeed",
allMetrics["replication_tasks"].Desc, allMetrics["replication_tasks"].Type, data[j].Succeed, policyName, triggerType, "succeed",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["replication_tasks"].Desc, allMetrics["replication_tasks"].Type, data[j].InProgress, policyName, "in_progress",
allMetrics["replication_tasks"].Desc, allMetrics["replication_tasks"].Type, data[j].InProgress, policyName, triggerType, "in_progress",
)
ch <- prometheus.MustNewConstMetric(
allMetrics["replication_tasks"].Desc, allMetrics["replication_tasks"].Type, data[j].Stopped, policyName, "stopped",
allMetrics["replication_tasks"].Desc, allMetrics["replication_tasks"].Type, data[j].Stopped, policyName, triggerType, "stopped",
)
}
}
Expand Down

0 comments on commit 8f24e7e

Please sign in to comment.