From 23a02bd5a7e6128d1ffca637edbdc9fb39e65edc Mon Sep 17 00:00:00 2001 From: DQ Date: Mon, 25 Jan 2021 18:53:10 +0800 Subject: [PATCH 1/2] Fix sel registration in metric label Original type is bool, should convert it to string Signed-off-by: DQ --- src/pkg/exporter/system_collector.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pkg/exporter/system_collector.go b/src/pkg/exporter/system_collector.go index 0384c0a6f..4c7f28061 100644 --- a/src/pkg/exporter/system_collector.go +++ b/src/pkg/exporter/system_collector.go @@ -2,6 +2,7 @@ package exporter import ( "encoding/json" + "strconv" "github.com/goharbor/harbor/src/lib/log" "github.com/prometheus/client_golang/prometheus" @@ -66,7 +67,7 @@ func (hc *SystemInfoCollector) getSysInfo() []prometheus.Metric { result = append(result, harborSysInfo.MustNewConstMetric(1, sysInfoResponse.AuthMode, sysInfoResponse.HarborVersion, - sysInfoResponse.SelfRegistration)) + strconv.FormatBool(sysInfoResponse.SelfRegistration))) if CacheEnabled() { CachePut(systemInfoCollectorName, result) } @@ -76,5 +77,5 @@ func (hc *SystemInfoCollector) getSysInfo() []prometheus.Metric { type responseSysInfo struct { AuthMode string `json:"auth_mode"` HarborVersion string `json:"harbor_version"` - SelfRegistration string `json:"self_registration"` + SelfRegistration bool `json:"self_registration"` } From 66fd4a9728fc114492bcfa3e3813ea99e6c8e56c Mon Sep 17 00:00:00 2001 From: DQ Date: Mon, 25 Jan 2021 21:22:11 +0800 Subject: [PATCH 2/2] change label project id to project name project_name is more accurate Signed-off-by: DQ --- src/pkg/exporter/project_collector.go | 12 ++++++------ tests/apitests/python/test_verify_metrics_enabled.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pkg/exporter/project_collector.go b/src/pkg/exporter/project_collector.go index 37c2ab5d7..bbbc9ae7d 100644 --- a/src/pkg/exporter/project_collector.go +++ b/src/pkg/exporter/project_collector.go @@ -41,28 +41,28 @@ var ( valueType: prometheus.GaugeValue, } projectUsage = typedDesc{ - desc: newDescWithLables("", "project_usage_byte", "The used resource of a project", "project_id"), + desc: newDescWithLables("", "project_usage_byte", "The used resource of a project", "project_name"), valueType: prometheus.GaugeValue, } projectQuote = typedDesc{ - desc: newDescWithLables("", "project_quota_byte", "The quota of a project", "project_id"), + desc: newDescWithLables("", "project_quota_byte", "The quota of a project", "project_name"), valueType: prometheus.GaugeValue, } projectRepoTotal = typedDesc{ - desc: newDescWithLables("", "project_repo_total", "Total project repos number", "project_id", "public"), + desc: newDescWithLables("", "project_repo_total", "Total project repos number", "project_name", "public"), valueType: prometheus.GaugeValue, } projectMemberTotal = typedDesc{ - desc: newDescWithLables("", "project_member_total", "Total members number of a project", "project_id"), + desc: newDescWithLables("", "project_member_total", "Total members number of a project", "project_name"), valueType: prometheus.GaugeValue, } artifactPullTotal = typedDesc{ - desc: newDescWithLables("", "image_pulled", "The pull number of an image", "project_id"), + desc: newDescWithLables("", "artifact_pulled", "The pull number of an artifact", "project_name"), valueType: prometheus.GaugeValue, } projectArtifactTotal = typedDesc{ - desc: newDescWithLables("", "project_artifact_total", "Total project images number", "project_id", "public", "image_type"), + desc: newDescWithLables("", "project_artifact_total", "Total project artifacts number", "project_name", "public", "artifact_type"), valueType: prometheus.GaugeValue, } ) diff --git a/tests/apitests/python/test_verify_metrics_enabled.py b/tests/apitests/python/test_verify_metrics_enabled.py index 0d4a848bf..915d9abf0 100644 --- a/tests/apitests/python/test_verify_metrics_enabled.py +++ b/tests/apitests/python/test_verify_metrics_enabled.py @@ -13,7 +13,7 @@ class TestMetricsExist(unittest.TestCase): 'core': golang_basic_metrics + ["harbor_core_http_request", "harbor_core_http_request_duration_seconds", "harbor_core_http_request_inflight"], 'registry': golang_basic_metrics + ["registry_http_in_flight_requests"], - 'exporter': golang_basic_metrics + ["harbor_image_pulled", + 'exporter': golang_basic_metrics + ["artifact_pulled", "harbor_project_artifact_total", "harbor_project_member_total", "harbor_project_quota_byte", "harbor_project_repo_total", "harbor_project_total" ]