Skip to content

Commit bce6e73

Browse files
Add percent towards next coupon
1 parent d0f9f6d commit bce6e73

3 files changed

Lines changed: 40 additions & 12 deletions

File tree

Companion/exporter/resource_sink_collector.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
)
77

88
type ResourceSinkCollector struct {
9-
buildingEndpoint string
10-
globalResourceEndpoint string
11-
globalExplorationEndpoint string
9+
buildingEndpoint string
10+
globalResourceEndpoint string
11+
globalExplorationEndpoint string
1212
}
1313

1414
type ResourceSinkDetails struct {
@@ -17,17 +17,18 @@ type ResourceSinkDetails struct {
1717
}
1818

1919
type GlobalSinkDetails struct {
20-
SinkType string `json:"Name"`
21-
NumCoupon int `json:"NumCoupon"`
22-
TotalPoints int `json:"TotalPoints"`
23-
PointsToCoupon int `json:"PointsToCoupon"`
20+
SinkType string `json:"Name"`
21+
NumCoupon int `json:"NumCoupon"`
22+
TotalPoints int `json:"TotalPoints"`
23+
PointsToCoupon int `json:"PointsToCoupon"`
24+
Percent float64 `json:"Percent"`
2425
}
2526

2627
func NewResourceSinkCollector(buildingEndpoint, globalResourceEndpoint, globalExplorationEndpoint string) *ResourceSinkCollector {
2728
return &ResourceSinkCollector{
28-
buildingEndpoint: buildingEndpoint,
29-
globalResourceEndpoint: globalResourceEndpoint,
30-
globalExplorationEndpoint: globalExplorationEndpoint,
29+
buildingEndpoint: buildingEndpoint,
30+
globalResourceEndpoint: globalResourceEndpoint,
31+
globalExplorationEndpoint: globalExplorationEndpoint,
3132
}
3233
}
3334

@@ -49,6 +50,7 @@ func (c *ResourceSinkCollector) Collect(frmAddress string, sessionName string) {
4950
for _, d := range globalResourceDetails {
5051
ResourceSinkTotalPoints.WithLabelValues(d.SinkType, frmAddress, sessionName).Set(float64(d.TotalPoints))
5152
ResourceSinkPointsToCoupon.WithLabelValues(d.SinkType, frmAddress, sessionName).Set(float64(d.PointsToCoupon))
53+
ResourceSinkPercent.WithLabelValues(d.SinkType, frmAddress, sessionName).Set(float64(d.Percent))
5254
ResourceSinkCollectedCoupons.WithLabelValues(frmAddress, sessionName).Set(float64(d.NumCoupon))
5355
}
5456

@@ -62,6 +64,7 @@ func (c *ResourceSinkCollector) Collect(frmAddress string, sessionName string) {
6264
for _, d := range globalExplorationDetails {
6365
ResourceSinkTotalPoints.WithLabelValues(d.SinkType, frmAddress, sessionName).Set(float64(d.TotalPoints))
6466
ResourceSinkPointsToCoupon.WithLabelValues(d.SinkType, frmAddress, sessionName).Set(float64(d.PointsToCoupon))
67+
ResourceSinkPercent.WithLabelValues(d.SinkType, frmAddress, sessionName).Set(float64(d.Percent))
6568
}
6669

6770
powerInfo := map[float64]float64{}

Companion/exporter/resource_sink_collector_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,21 @@ var _ = Describe("ResourceSinkCollector", func() {
4242

4343
FRMServer.ReturnsGlobalResourceSinkData([]exporter.GlobalSinkDetails{
4444
{
45-
SinkType: "Resource",
45+
SinkType: "Resource",
4646
TotalPoints: 100,
4747
PointsToCoupon: 200,
4848
NumCoupon: 1,
49+
Percent: 0.7,
4950
},
5051
})
5152

5253
FRMServer.ReturnsGlobalExplorationSinkData([]exporter.GlobalSinkDetails{
5354
{
54-
SinkType: "Exploration",
55+
SinkType: "Exploration",
5556
TotalPoints: 1000,
5657
PointsToCoupon: 2000,
5758
NumCoupon: 1,
59+
Percent: 0.8,
5860
},
5961
})
6062
})
@@ -99,6 +101,14 @@ var _ = Describe("ResourceSinkCollector", func() {
99101
Expect(err).ToNot(HaveOccurred())
100102
Expect(val).To(Equal(200.0))
101103
})
104+
It("sets the 'resource_sink_points_to_coupon' percent with the right labels", func() {
105+
collector.Collect(url, sessionName)
106+
107+
val, err := gaugeValue(exporter.ResourceSinkPercent, "Resource", url, sessionName)
108+
109+
Expect(err).ToNot(HaveOccurred())
110+
Expect(val).To(Equal(0.7))
111+
})
102112
It("sets the 'resource_sink_points_to_coupon' metric with the right labels for exploration", func() {
103113
collector.Collect(url, sessionName)
104114

@@ -115,6 +125,14 @@ var _ = Describe("ResourceSinkCollector", func() {
115125
Expect(err).ToNot(HaveOccurred())
116126
Expect(val).To(Equal(2000.0))
117127
})
128+
It("sets the 'resource_sink_points_to_coupon' percent with the right labels for exploration", func() {
129+
collector.Collect(url, sessionName)
130+
131+
val, err := gaugeValue(exporter.ResourceSinkPercent, "Exploration", url, sessionName)
132+
133+
Expect(err).ToNot(HaveOccurred())
134+
Expect(val).To(Equal(0.8))
135+
})
118136
It("sets the 'resource_sink_collected_coupons' metric with the right labels", func() {
119137
collector.Collect(url, sessionName)
120138

Companion/exporter/resource_sink_metrics.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ var (
3333
"sink_type",
3434
})
3535

36+
ResourceSinkPercent = RegisterNewGaugeVec(prometheus.GaugeOpts{
37+
Name: "resource_sink_percent",
38+
Help: "AWESOME sink percent to next coupon",
39+
}, []string{
40+
"sink_type",
41+
})
42+
3643
ResourceSinkCollectedCoupons = RegisterNewGaugeVec(prometheus.GaugeOpts{
3744
Name: "resource_sink_collected_coupons",
3845
Help: "AWESOME sink collected coupons",

0 commit comments

Comments
 (0)