Skip to content

Commit 4b15d92

Browse files
authored
Merge pull request #168 from NodeFactoryIo/mmuftic/fix-data-collection-interval
Custom stats collecting intervals
2 parents ad3b508 + 82d4e1f commit 4b15d92

5 files changed

Lines changed: 94 additions & 19 deletions

File tree

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.4.1
1+
version=0.4.2

CHANGELOG.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
# Changelog
22

3+
## [v0.4.2]((https://github.com/NodeFactoryIo/vedran/tree/v0.4.2))
4+
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.4.1...v0.4.2\)
5+
6+
### Added
7+
8+
### Fix
9+
10+
### Changed
11+
- Custom stats collecting intervals [\#168](https://github.com/NodeFactoryIo/vedran/pull/168) ([MakMuftic](https://github.com/MakMuftic))
12+
313
## [v0.4.1]((https://github.com/NodeFactoryIo/vedran/tree/v0.4.1))
4-
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.4.0...v0.4.1)
14+
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.4.0...v0.4.1\)
515

616
### Added
717

818
### Fix
9-
- Fix manual payout #165 [#\165](https://github.com/NodeFactoryIo/vedran/pull/165) ([MakMuftic](https://github.com/MakMuftic))
19+
- Fix manual payout [\#165](https://github.com/NodeFactoryIo/vedran/pull/165) ([MakMuftic](https://github.com/MakMuftic))
1020

1121
### Changed
1222

1323
## [v0.4.0]((https://github.com/NodeFactoryIo/vedran/tree/v0.4.0))
1424
[Full Changelog](https://github.com/NodeFactoryIo/vedran/compare/v0.3.1...v0.4.0)
1525

1626
### Added
17-
- Provide LB fee information [#\158](https://github.com/NodeFactoryIo/vedran/pull/158) ([MakMuftic](https://github.com/MakMuftic))
27+
- Provide LB fee information [\#158](https://github.com/NodeFactoryIo/vedran/pull/158) ([MakMuftic](https://github.com/MakMuftic))
1828

1929
### Fix
20-
- Metrics endpoint and grafana dashboard example [#\138](https://github.com/NodeFactoryIo/vedran/pull/138) ([mpetrun5](https://github.com/mpetrun5))
21-
- Fix next payout date prometheus value [#\161](https://github.com/NodeFactoryIo/vedran/pull/161) ([mpetrun5](https://github.com/mpetrun5))
30+
- Metrics endpoint and grafana dashboard example [\#138](https://github.com/NodeFactoryIo/vedran/pull/138) ([mpetrun5](https://github.com/mpetrun5))
31+
- Fix next payout date prometheus value [\#161](https://github.com/NodeFactoryIo/vedran/pull/161) ([mpetrun5](https://github.com/mpetrun5))
2232

2333
### Changed
2434

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ This demo starts five separate dockerized components:
4141

4242
### Trigger Manual Payout
4343

44-
Our compose setup runs dev chain and our load balancer uses Allice account to do payout
44+
Our compose setup runs dev chain, and our load balancer uses Allice account to do payout,
4545
so you don't have to obtain dev DOTs. Polkadot node operator is Bob (he received payout from Allice).
46-
Load balancer in this setup runs payout daily, if you don't wan't to wait,
47-
you can run following command which will create additional container (in compose network) and trigger payout from Allice account:
46+
Load balancer in this setup runs payout daily, if you don't want to wait,
47+
you can run following command which will create an additional container (in compose network) and trigger payout from Allice account:
4848

4949
```
50-
docker run --network vedran_default nodefactory/vedran:v0.3.0 payout --private-key 0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a --payout-reward 100 --load-balancer-url "http://vedran:4000/ws"
50+
docker run --network vedran_default nodefactory/vedran:latest payout --private-key 0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a --payout-reward 100 --load-balancer-url "http://vedran:4000/ws"
5151
```
5252

5353
## Get **vedran** binary releases
@@ -194,6 +194,20 @@ Monitoring is done via grafana and prometheus which are expected to be installed
194194
- ### Prometheus
195195
Prometheus should be configured to scrape metrics from vedran's `/metrics` endpoint
196196
via prometheus .yml configuration. Example of which can be found [here](./infra/prometheus/prometheus.yml)
197+
198+
### Stats collection intervals
199+
200+
It is possible to change default calculation intervals for specific statistic categories. These intervals define how
201+
often will these statistics be recalculated.
202+
203+
Valid values are time intervals such as "5s", "1.5h" or "2h45m". Valid time units are "ms", "s", "m", "h"
204+
205+
| ENV | Description | Default value |
206+
|----|-----------|:--------:|
207+
|`PROM_FEE_STATS_INTERVAL`|payout fees for nodes and load balancer|12 hours|
208+
|`PROM_NODE_STATS_INTERVAL`|active and penalized nodes|15 seconds|
209+
|`PROM_REQUEST_STATS_INTERVAL`|successful and failed requests|15 seconds|
210+
|`PROM_PAYOUT_STATS_INTERVAL`|payout distribution|1 minute|
197211

198212

199213
## Vedran loadbalancer API

docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ services:
1717
1818
vedran:
1919
command: start --auth-secret=test-secret --log-level debug --public-ip vedran --server-port 4000 --private-key ${VEDRAN_LB_PK:-0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a} --payout-interval 1 --payout-reward ${VEDRAN_LB_REWARD_POOL:-10}
20-
image: nodefactory/vedran:v0.4.1
20+
image: nodefactory/vedran:v0.4.2
21+
environment:
22+
- PROM_FEE_STATS_INTERVAL=10s
23+
- PROM_PAYOUT_STATS_INTERVAL=5s
2124
ports:
2225
- "4000:4000"
2326
container_name: "vedran"

internal/prometheus/prometheus.go

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package prometheus
33
import (
44
"fmt"
55
"github.com/NodeFactoryIo/vedran/internal/stats"
6+
"os"
67
"runtime"
78
"strconv"
89
"time"
@@ -19,8 +20,22 @@ import (
1920

2021
const (
2122
nextPayoutDateLayout = "Mon, Jan 2 2006."
23+
24+
FeeStatsIntervalEnv = "PROM_FEE_STATS_INTERVAL"
25+
DefaultFeeStatsCollectionInterval = 12 * time.Hour
26+
NodeStatsIntervalEnv = "PROM_NODE_STATS_INTERVAL"
27+
DefaultNodeStatsCollectionInterval = 15 * time.Second
28+
RequestStatsIntervalEnv = "PROM_REQUEST_STATS_INTERVAL"
29+
DefaultRecordStatsCollectionInterval = 15 * time.Second
30+
PayoutStatsIntervalEnv = "PROM_PAYOUT_STATS_INTERVAL"
31+
DefaultPayoutStatsCollectionInterval = 1 * time.Minute
2232
)
2333

34+
var feeStatsCollectionInterval time.Duration
35+
var nodeStatsCollectionInterval time.Duration
36+
var requestStatsCollectionInterval time.Duration
37+
var payoutStatsCollectionInterval time.Duration
38+
2439
var (
2540
activeNodes = promauto.NewGauge(prometheus.GaugeOpts{
2641
Name: "vedran_number_of_active_nodes",
@@ -101,6 +116,8 @@ func RecordMetrics(repos repositories.Repos) {
101116
})
102117
fee.Set(float64(configuration.Config.Fee))
103118

119+
setUpCollectionIntervals()
120+
104121
go recordPayoutDistribution(repos)
105122
go recordActiveNodeCount(repos.NodeRepo)
106123
go recordPenalizedNodeCount(repos.NodeRepo)
@@ -122,7 +139,7 @@ func recordNodeFees(repos repositories.FeeRepository) {
122139
for _, fee := range *fees {
123140
nodeFees.With(prometheus.Labels{"node": fee.NodeId}).Set(float64(fee.TotalFee))
124141
}
125-
time.Sleep(12 * time.Hour)
142+
time.Sleep(feeStatsCollectionInterval)
126143
}
127144
}
128145

@@ -144,7 +161,7 @@ func recordLbFeeAmount(payoutRepo repositories.PayoutRepository) {
144161
totalFeeCollected += p.LbFee
145162
}
146163
totalFee.Set(totalFeeCollected)
147-
time.Sleep(12 * time.Hour)
164+
time.Sleep(feeStatsCollectionInterval)
148165
}
149166
}
150167

@@ -176,7 +193,7 @@ func recordPayoutDistribution(repos repositories.Repos) {
176193
)
177194
}
178195

179-
time.Sleep(1 * time.Minute)
196+
time.Sleep(payoutStatsCollectionInterval)
180197
}
181198
}
182199

@@ -188,37 +205,68 @@ func recordPayoutDate(repos repositories.Repos) {
188205
} else {
189206
payoutDate.With(prometheus.Labels{"date": date.Format(nextPayoutDateLayout)}).Set(1)
190207
}
191-
time.Sleep(12 * time.Hour)
208+
time.Sleep(feeStatsCollectionInterval)
192209
}
193210
}
194211

195212
func recordActiveNodeCount(nodeRepo repositories.NodeRepository) {
196213
for {
197214
activeNodes.Set(float64(len(*nodeRepo.GetAllActiveNodes())))
198-
time.Sleep(15 * time.Second)
215+
time.Sleep(nodeStatsCollectionInterval)
199216
}
200217
}
201218

202219
func recordPenalizedNodeCount(nodeRepo repositories.NodeRepository) {
203220
for {
204221
nodes, _ := nodeRepo.GetPenalizedNodes()
205222
penalizedNodes.Set(float64(len(*nodes)))
206-
time.Sleep(15 * time.Second)
223+
time.Sleep(nodeStatsCollectionInterval)
207224
}
208225
}
209226

210227
func recordSuccessfulRequestCount(recordRepo repositories.RecordRepository) {
211228
for {
212229
count, _ := recordRepo.CountSuccessfulRequests()
213230
successfulRequests.Set(float64(count))
214-
time.Sleep(15 * time.Second)
231+
time.Sleep(requestStatsCollectionInterval)
215232
}
216233
}
217234

218235
func recordFailedRequestCount(recordRepo repositories.RecordRepository) {
219236
for {
220237
count, _ := recordRepo.CountFailedRequests()
221238
failedRequests.Set(float64(count))
222-
time.Sleep(15 * time.Second)
239+
time.Sleep(requestStatsCollectionInterval)
240+
}
241+
}
242+
243+
func setUpCollectionIntervals() {
244+
fsi := os.Getenv(FeeStatsIntervalEnv)
245+
if fsi != "" {
246+
feeStatsCollectionInterval, _ = time.ParseDuration(fsi)
247+
}
248+
if feeStatsCollectionInterval == 0 {
249+
feeStatsCollectionInterval = DefaultFeeStatsCollectionInterval
250+
}
251+
nsi := os.Getenv(NodeStatsIntervalEnv)
252+
if nsi != "" {
253+
nodeStatsCollectionInterval, _ = time.ParseDuration(nsi)
254+
}
255+
if nodeStatsCollectionInterval == 0 {
256+
nodeStatsCollectionInterval = DefaultNodeStatsCollectionInterval
257+
}
258+
rsi := os.Getenv(RequestStatsIntervalEnv)
259+
if rsi != "" {
260+
requestStatsCollectionInterval, _ = time.ParseDuration(rsi)
261+
}
262+
if requestStatsCollectionInterval == 0 {
263+
requestStatsCollectionInterval = DefaultRecordStatsCollectionInterval
264+
}
265+
psi := os.Getenv(PayoutStatsIntervalEnv)
266+
if psi != "" {
267+
payoutStatsCollectionInterval, _ = time.ParseDuration(psi)
268+
}
269+
if payoutStatsCollectionInterval == 0 {
270+
payoutStatsCollectionInterval = DefaultPayoutStatsCollectionInterval
223271
}
224272
}

0 commit comments

Comments
 (0)