Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit 9ba5f4b

Browse files
committed
pkg/metrics rename scrape to publish
1 parent 0a6913f commit 9ba5f4b

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,17 @@ func updateMetrics(provider *gophercloud.ProviderClient, eo gophercloud.Endpoint
236236
err := logError("creating openstack clients failed: %v", err)
237237
errs = append(errs, err)
238238
} else {
239-
if err := metrics.ScrapeCinderMetrics(cinderClient, clientset, tenantID); err != nil {
239+
if err := metrics.PublishCinderMetrics(cinderClient, clientset, tenantID); err != nil {
240240
err := logError("scraping cinder metrics failed: %v", err)
241241
errs = append(errs, err)
242242
}
243243

244-
if err := metrics.ScrapeNeutronMetrics(neutronClient, tenantID); err != nil {
244+
if err := metrics.PublishNeutronMetrics(neutronClient, tenantID); err != nil {
245245
err := logError("scraping neutron metrics failed: %v", err)
246246
errs = append(errs, err)
247247
}
248248

249-
if err := metrics.ScrapeLoadBalancerMetrics(loadbalancerClient, tenantID); err != nil {
249+
if err := metrics.PublishLoadBalancerMetrics(loadbalancerClient, tenantID); err != nil {
250250
err := logError("scraping load balancer metrics failed: %v", err)
251251
errs = append(errs, err)
252252
}

pkg/metrics/cinder.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ func registerCinderMetrics() {
9090
prometheus.MustRegister(cinderVolumeAttachedAt)
9191
}
9292

93-
// ScrapeCinderMetrics makes the list request to the blockstorage api and passes
94-
// the result to a scrape function.
95-
func ScrapeCinderMetrics(client *gophercloud.ServiceClient, clientset *kubernetes.Clientset, tenantID string) error {
93+
// PublishCinderMetrics makes the list request to the blockstorage api and passes
94+
// the result to a publish function.
95+
func PublishCinderMetrics(client *gophercloud.ServiceClient, clientset *kubernetes.Clientset, tenantID string) error {
9696
// get the cinder pvs to add metadata
9797
pvs, err := getPVsByCinderID(clientset)
9898
if err != nil {
@@ -106,31 +106,31 @@ func ScrapeCinderMetrics(client *gophercloud.ServiceClient, clientset *kubernete
106106
cinderVolumeSize.Reset()
107107
cinderVolumeAttachedAt.Reset()
108108

109-
// get all volumes and scrape them
109+
// get all volumes and publish them
110110
mc := newOpenStackMetric("volume", "list")
111111
pager := volumes.List(client, volumes.ListOpts{})
112112
err = pager.EachPage(func(page pagination.Page) (bool, error) {
113-
return scrapeVolumesPage(page, pvs)
113+
return publishVolumesPage(page, pvs)
114114
})
115115
if mc.Observe(err) != nil {
116-
// only warn, maybe the next scrape will work.
117-
klog.Warningf("Unable to scrape volumes: %v", err)
116+
// only warn, maybe the next list will work.
117+
klog.Warningf("Unable to list volumes: %v", err)
118118
return err
119119
}
120120

121121
mc = newOpenStackMetric("volume_quotasets_usage", "get")
122122
q, err := quotasets.GetUsage(client, tenantID).Extract()
123123
if mc.Observe(err) != nil {
124-
// only warn, maybe the next scrape will work.
125-
klog.Warningf("Unable to scrape quotas: %v", err)
124+
// only warn, maybe the next get will work.
125+
klog.Warningf("Unable to get quotas: %v", err)
126126
return err
127127
}
128-
scrapeCinderQuotas(q)
128+
publishCinderQuotas(q)
129129
return nil
130130
}
131131

132-
// scrapeCinderQuotas scrapes all cinder related quotas
133-
func scrapeCinderQuotas(q quotasets.QuotaUsageSet) {
132+
// publishCinderQuotas publishes all cinder related quotas
133+
func publishCinderQuotas(q quotasets.QuotaUsageSet) {
134134
cinderQuotaVolumes.WithLabelValues("in-use").Set(float64(q.Volumes.InUse))
135135
cinderQuotaVolumes.WithLabelValues("reserved").Set(float64(q.Volumes.Reserved))
136136
cinderQuotaVolumes.WithLabelValues("limit").Set(float64(q.Volumes.Limit))
@@ -142,25 +142,25 @@ func scrapeCinderQuotas(q quotasets.QuotaUsageSet) {
142142
cinderQuotaVolumesGigabyte.WithLabelValues("allocated").Set(float64(q.Gigabytes.Allocated))
143143
}
144144

145-
// scrapeVolumesPage iterates over a page, the result of a list request
146-
func scrapeVolumesPage(page pagination.Page, pvs map[string]corev1.PersistentVolume) (bool, error) {
145+
// publishVolumesPage iterates over a page, the result of a list request
146+
func publishVolumesPage(page pagination.Page, pvs map[string]corev1.PersistentVolume) (bool, error) {
147147
vList, err := volumes.ExtractVolumes(page)
148148
if err != nil {
149149
return false, err
150150
}
151151

152152
for _, v := range vList {
153153
if pv, ok := pvs[v.ID]; ok {
154-
scrapeVolumeMetrics(v, &pv)
154+
publishVolumeMetrics(v, &pv)
155155
} else {
156-
scrapeVolumeMetrics(v, nil)
156+
publishVolumeMetrics(v, nil)
157157
}
158158
}
159159
return true, nil
160160
}
161161

162-
// scrapeVolumeMetrics extracts data from a volume and exposes the metrics via prometheus
163-
func scrapeVolumeMetrics(v volumes.Volume, pv *corev1.PersistentVolume) {
162+
// publishVolumeMetrics extracts data from a volume and exposes the metrics via prometheus
163+
func publishVolumeMetrics(v volumes.Volume, pv *corev1.PersistentVolume) {
164164
labels := []string{v.ID, v.Description, v.Name, v.Status, v.AvailabilityZone, v.VolumeType}
165165

166166
k8sMetadata := extractK8sMetadata(pv)

pkg/metrics/loadbalancer.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ func registerLoadBalancerMetrics() {
3939
prometheus.MustRegister(loadbalancerStatus)
4040
}
4141

42-
// ScrapeLoadBalancerMetrics makes the list request to the load balancer api and
43-
// passes the result to a scrape function.
44-
func ScrapeLoadBalancerMetrics(client *gophercloud.ServiceClient, tenantID string) error {
42+
// PublishLoadBalancerMetrics makes the list request to the load balancer api and
43+
// passes the result to a publish function.
44+
func PublishLoadBalancerMetrics(client *gophercloud.ServiceClient, tenantID string) error {
4545
// first step: gather the data
4646
mc := newOpenStackMetric("loadbalancer", "list")
4747
pages, err := loadbalancers.List(client, loadbalancers.ListOpts{}).AllPages()
4848
if mc.Observe(err) != nil {
49-
// only warn, maybe the next scrape will work.
50-
klog.Warningf("Unable to scrape floating ips: %v", err)
49+
// only warn, maybe the next list will work.
50+
klog.Warningf("Unable to list load balancers: %v", err)
5151
return err
5252
}
5353
loadBalancerList, err := loadbalancers.ExtractLoadBalancers(pages)
5454
if err != nil {
55-
// only warn, maybe the next scrape will work.
56-
klog.Warningf("Unable to scrape load balancers: %v", err)
55+
// only warn, maybe the next publish will work.
56+
klog.Warningf("Unable to extract load balancers: %v", err)
5757
return err
5858
}
5959

@@ -62,14 +62,14 @@ func ScrapeLoadBalancerMetrics(client *gophercloud.ServiceClient, tenantID strin
6262

6363
// third step: publish the metrics
6464
for _, lb := range loadBalancerList {
65-
scrapeLoadBalancerMetric(lb)
65+
publishLoadBalancerMetric(lb)
6666
}
6767

6868
return nil
6969
}
7070

71-
// scrapeLoadBalancerMetric extracts data from a floating ip and exposes the metrics via prometheus
72-
func scrapeLoadBalancerMetric(lb loadbalancers.LoadBalancer) {
71+
// publishLoadBalancerMetric extracts data from a floating ip and exposes the metrics via prometheus
72+
func publishLoadBalancerMetric(lb loadbalancers.LoadBalancer) {
7373
labels := []string{lb.ID, lb.VipAddress, lb.Provider, lb.VipPortID}
7474

7575
loadbalancerAdminStateUp.WithLabelValues(labels...).Set(boolFloat64(lb.AdminStateUp))

pkg/metrics/neutron.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ func registerNeutronMetrics() {
4545
prometheus.MustRegister(neutronFloatingIPUpdatedAt)
4646
}
4747

48-
// ScrapeNeutronMetrics makes the list request to the neutron api and passes
49-
// the result to a scrape function.
50-
func ScrapeNeutronMetrics(neutronClient *gophercloud.ServiceClient, tenantID string) error {
48+
// PublishNeutronMetrics makes the list request to the neutron api and passes
49+
// the result to a publish function.
50+
func PublishNeutronMetrics(neutronClient *gophercloud.ServiceClient, tenantID string) error {
5151
// first step: gather the data
5252
mc := newOpenStackMetric("floating_ip", "list")
5353
pages, err := floatingips.List(neutronClient, floatingips.ListOpts{}).AllPages()
5454
if mc.Observe(err) != nil {
55-
// only warn, maybe the next scrape will work.
56-
klog.Warningf("Unable to scrape floating ips: %v", err)
55+
// only warn, maybe the next list will work.
56+
klog.Warningf("Unable to list floating ips: %v", err)
5757
return err
5858
}
5959
floatingIPList, err := floatingips.ExtractFloatingIPs(pages)
6060
if err != nil {
61-
// only warn, maybe the next scrape will work.
62-
klog.Warningf("Unable to scrape floating ips: %v", err)
61+
// only warn, maybe the next extract will work.
62+
klog.Warningf("Unable to extract floating ips: %v", err)
6363
return err
6464
}
6565

@@ -68,14 +68,14 @@ func ScrapeNeutronMetrics(neutronClient *gophercloud.ServiceClient, tenantID str
6868

6969
// third step: publish the metrics
7070
for _, fip := range floatingIPList {
71-
scrapeFloatingIPMetric(fip)
71+
publishFloatingIPMetric(fip)
7272
}
7373

7474
return nil
7575
}
7676

77-
// scrapeFloatingIPMetric extracts data from a floating ip and exposes the metrics via prometheus
78-
func scrapeFloatingIPMetric(fip floatingips.FloatingIP) {
77+
// publishFloatingIPMetric extracts data from a floating ip and exposes the metrics via prometheus
78+
func publishFloatingIPMetric(fip floatingips.FloatingIP) {
7979
labels := []string{fip.ID, fip.FloatingIP, fip.FixedIP, fip.PortID}
8080

8181
neutronFloatingIPStatus.WithLabelValues(labels...).Set(1)

0 commit comments

Comments
 (0)