mirror of
https://github.com/jangraefen/hcloud-pricing-exporter
synced 2024-11-10 05:54:15 +00:00
feat: Add type label for IPs (#41)
* feat: Add type label for IPs * Fix tests
This commit is contained in:
parent
154bcd2d3e
commit
954c98f013
6 changed files with 28 additions and 20 deletions
|
@ -46,12 +46,12 @@ helm upgrade --install hcloud-pricing-exporter hcloud-pricing-exporter/hcloud-pr
|
|||
|
||||
## Exported metrics
|
||||
|
||||
- `hcloud_pricing_floatingip_hourly{name, location}` _(Estimated based on the monthly price)_
|
||||
- `hcloud_pricing_floatingip_monthly{name, location}`
|
||||
- `hcloud_pricing_primaryip_hourly{name, location}` _(Estimated based on the monthly price)_
|
||||
- `hcloud_pricing_primaryip_monthly{name, location}`
|
||||
- `hcloud_pricing_floatingip_hourly{name, location, type}` _(Estimated based on the monthly price)_
|
||||
- `hcloud_pricing_floatingip_monthly{name, location, type}`
|
||||
- `hcloud_pricing_loadbalancer_hourly{name, location, type}`
|
||||
- `hcloud_pricing_loadbalancer_monthly{name, location, type}`
|
||||
- `hcloud_pricing_primaryip_hourly{name, datacenter, type}`
|
||||
- `hcloud_pricing_primaryip_monthly{name, datacenter, type}`
|
||||
- `hcloud_pricing_server_hourly{name, location, type}`
|
||||
- `hcloud_pricing_server_monthly{name, location, type}`
|
||||
- `hcloud_pricing_server_backups_hourly{name, location, type}`
|
||||
|
|
|
@ -29,19 +29,21 @@ var _ = Describe("For floating IPs", Ordered, Label("floatingips"), func() {
|
|||
waitUntilActionSucceeds(ctx, res.Action)
|
||||
})
|
||||
|
||||
//nolint:dupl
|
||||
When("getting prices", func() {
|
||||
It("should fetch them", func() {
|
||||
Expect(sut.Run(testClient)).To(Succeed())
|
||||
})
|
||||
|
||||
It("should get prices for correct values", func() {
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "fsn1"))).Should(BeNumerically(">", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-floatingip", "fsn1"))).Should(BeNumerically(">", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "fsn1", "ipv6"))).Should(BeNumerically(">", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-floatingip", "fsn1", "ipv6"))).Should(BeNumerically(">", 0.0))
|
||||
})
|
||||
|
||||
It("should get zero for incorrect values", func() {
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "nbg1"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1", "ipv6"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "nbg1", "ipv6"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-floatingip", "fsn1", "ipv4"))).Should(BeNumerically("==", 0))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -41,6 +41,7 @@ var _ = Describe("For primary IPs", Ordered, Label("primaryips"), func() {
|
|||
waitUntilActionSucceeds(ctx, resv6.Action)
|
||||
})
|
||||
|
||||
//nolint:dupl
|
||||
When("getting prices", func() {
|
||||
It("should fetch them", func() {
|
||||
By("Running the price collection")
|
||||
|
@ -49,22 +50,26 @@ var _ = Describe("For primary IPs", Ordered, Label("primaryips"), func() {
|
|||
|
||||
It("should get prices for correct values for v4", func() {
|
||||
By("Checking IPv4 prices")
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryipv4", "fsn1-dc14"))).Should(BeNumerically(">", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-primaryipv4", "fsn1-dc14"))).Should(BeNumerically(">", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryipv4", "fsn1-dc14", "ipv4"))).Should(BeNumerically(">", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-primaryipv4", "fsn1-dc14", "ipv4"))).Should(BeNumerically(">", 0.0))
|
||||
})
|
||||
|
||||
It("should get prices for correct values for v6", func() {
|
||||
By("Checking IPv6 prices")
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryipv6", "fsn1-dc14"))).Should(BeNumerically("==", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-primaryipv6", "fsn1-dc14"))).Should(BeNumerically("==", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryipv6", "fsn1-dc14", "ipv6"))).Should(BeNumerically("==", 0.0))
|
||||
Expect(testutil.ToFloat64(sut.GetMonthly().WithLabelValues("test-primaryipv6", "fsn1-dc14", "ipv6"))).Should(BeNumerically("==", 0.0))
|
||||
})
|
||||
|
||||
It("should get zero for incorrect values", func() {
|
||||
By("Checking IPv4 prices")
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1-dc14"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1-dc14", "ipv4"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv4", "nbg1-dc14", "ipv4"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv4", "fsn1-dc14", "ipv6"))).Should(BeNumerically("==", 0))
|
||||
|
||||
By("Checking IPv6 prices")
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("test-primaryip", "nbg1-dc14"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("invalid-name", "fsn1-dc14", "ipv6"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv6", "nbg1-dc14", "ipv6"))).Should(BeNumerically("==", 0))
|
||||
Expect(testutil.ToFloat64(sut.GetHourly().WithLabelValues("est-primaryipv6", "fsn1-dc14", "ipv4"))).Should(BeNumerically("==", 0))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -67,6 +67,7 @@ var _ = Describe("For servers", Ordered, Label("servers"), func() {
|
|||
waitUntilActionSucceeds(ctx, action)
|
||||
})
|
||||
|
||||
//nolint:dupl
|
||||
When("getting prices", func() {
|
||||
It("should fetch them", func() {
|
||||
By("Running the price collection")
|
||||
|
|
|
@ -8,7 +8,7 @@ var _ Fetcher = &floatingIP{}
|
|||
|
||||
// NewFloatingIP creates a new fetcher that will collect pricing information on floating IPs.
|
||||
func NewFloatingIP(pricing *PriceProvider) Fetcher {
|
||||
return &floatingIP{newBase(pricing, "floatingip", "location")}
|
||||
return &floatingIP{newBase(pricing, "floatingip", "location", "type")}
|
||||
}
|
||||
|
||||
type floatingIP struct {
|
||||
|
@ -27,8 +27,8 @@ func (floatingIP floatingIP) Run(client *hcloud.Client) error {
|
|||
monthlyPrice := floatingIP.pricing.FloatingIP(f.Type, location.Name)
|
||||
hourlyPrice := pricingPerHour(monthlyPrice)
|
||||
|
||||
floatingIP.hourly.WithLabelValues(f.Name, location.Name).Set(hourlyPrice)
|
||||
floatingIP.monthly.WithLabelValues(f.Name, location.Name).Set(monthlyPrice)
|
||||
floatingIP.hourly.WithLabelValues(f.Name, location.Name, string(f.Type)).Set(hourlyPrice)
|
||||
floatingIP.monthly.WithLabelValues(f.Name, location.Name, string(f.Type)).Set(monthlyPrice)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -8,7 +8,7 @@ var _ Fetcher = &floatingIP{}
|
|||
|
||||
// NewPrimaryIP creates a new fetcher that will collect pricing information on primary IPs.
|
||||
func NewPrimaryIP(pricing *PriceProvider) Fetcher {
|
||||
return &primaryIP{newBase(pricing, "primaryip", "location")}
|
||||
return &primaryIP{newBase(pricing, "primaryip", "datacenter", "type")}
|
||||
}
|
||||
|
||||
type primaryIP struct {
|
||||
|
@ -29,8 +29,8 @@ func (primaryIP primaryIP) Run(client *hcloud.Client) error {
|
|||
return err
|
||||
}
|
||||
|
||||
primaryIP.hourly.WithLabelValues(p.Name, datacenter.Name).Set(hourlyPrice)
|
||||
primaryIP.monthly.WithLabelValues(p.Name, datacenter.Name).Set(monthlyPrice)
|
||||
primaryIP.hourly.WithLabelValues(p.Name, datacenter.Name, string(p.Type)).Set(hourlyPrice)
|
||||
primaryIP.monthly.WithLabelValues(p.Name, datacenter.Name, string(p.Type)).Set(monthlyPrice)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue