From c9159ba963b227433d0d28cd6e85f3f493600d63 Mon Sep 17 00:00:00 2001 From: Mak Muftic Date: Wed, 20 Jan 2021 13:24:46 +0100 Subject: [PATCH 1/3] Expand metrics with target block --- internal/node/metrics.go | 15 +++++++++++++-- internal/node/metrics_test.go | 36 +++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/internal/node/metrics.go b/internal/node/metrics.go index 07d457b..96cc614 100644 --- a/internal/node/metrics.go +++ b/internal/node/metrics.go @@ -16,6 +16,7 @@ type Metrics struct { PeerCount *float64 `json:"peer_count"` BestBlockHeight *float64 `json:"best_block_height"` FinalizedBlockHeight *float64 `json:"finalized_block_height"` + TargetBlockHeight *float64 `json:"target_block_height"` ReadyTransactionCount *float64 `json:"ready_transaction_count"` } @@ -36,10 +37,20 @@ func (client *client) GetMetrics() (*Metrics, error) { return nil, err } + blockMetrics := metricFamilies["polkadot_block_height"].GetMetric() + bestBlockHeight := blockMetrics[0].Gauge.Value + finalizedBlockHeight := blockMetrics[1].Gauge.Value + targetBlockHeight := bestBlockHeight + // if node not synced there is additional metric - target block + if len(blockMetrics) == 3 { + targetBlockHeight = blockMetrics[2].Gauge.Value + } + metrics := &Metrics{ metricFamilies["polkadot_sync_peers"].GetMetric()[0].Gauge.Value, - metricFamilies["polkadot_block_height"].GetMetric()[0].Gauge.Value, - metricFamilies["polkadot_block_height"].GetMetric()[1].Gauge.Value, + bestBlockHeight, + finalizedBlockHeight, + targetBlockHeight, metricFamilies["polkadot_ready_transactions_number"].GetMetric()[0].Gauge.Value, } return metrics, nil diff --git a/internal/node/metrics_test.go b/internal/node/metrics_test.go index 21a2b61..c2a3146 100644 --- a/internal/node/metrics_test.go +++ b/internal/node/metrics_test.go @@ -26,6 +26,7 @@ func TestGetMetrics(t *testing.T) { peerCount := float64(19) bestBlockHeight := float64(432933) finalizedBlockHeight := float64(432640) + targetBlockHeight := float64(1547694) readyTransactionCount := float64(0) tests := []Test{ { @@ -54,12 +55,13 @@ func TestGetMetrics(t *testing.T) { _, _ = io.WriteString(w, `invalid`) }}, { - name: "Returns metrics if prometheus response valid", + name: "Returns metrics if prometheus response valid, not synced", args: args{"valid"}, want: &Metrics{ PeerCount: &peerCount, BestBlockHeight: &bestBlockHeight, FinalizedBlockHeight: &finalizedBlockHeight, + TargetBlockHeight: &targetBlockHeight, ReadyTransactionCount: &readyTransactionCount, }, wantErr: false, @@ -80,7 +82,37 @@ func TestGetMetrics(t *testing.T) { # TYPE polkadot_ready_transactions_number gauge polkadot_ready_transactions_number 0 `) - }}, + }, + }, + { + name: "Returns metrics if prometheus response valid, synced", + args: args{"valid"}, + want: &Metrics{ + PeerCount: &peerCount, + BestBlockHeight: &bestBlockHeight, + FinalizedBlockHeight: &finalizedBlockHeight, + TargetBlockHeight: &bestBlockHeight, + ReadyTransactionCount: &readyTransactionCount, + }, + wantErr: false, + handleFunc: func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method) + _, _ = io.WriteString( + w, + ` + # HELP polkadot_sync_peers Number of peers we sync with + # TYPE polkadot_sync_peers gauge + polkadot_sync_peers 19 + # HELP polkadot_block_height Block height info of the chain + # TYPE polkadot_block_height gauge + polkadot_block_height{status="best"} 432933 + polkadot_block_height{status="finalized"} 432640 + # HELP polkadot_ready_transactions_number Number of transactions in the ready queue + # TYPE polkadot_ready_transactions_number gauge + polkadot_ready_transactions_number 0 + `) + }, + }, } for _, tt := range tests { From af573c8a55d2c096fb1ec7608d3aff085cfdeb37 Mon Sep 17 00:00:00 2001 From: Mak Muftic Date: Wed, 20 Jan 2021 13:51:07 +0100 Subject: [PATCH 2/3] Update CHANGELOG file --- CHANGELOG.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aeee23d..b14a511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,19 @@ # Changelog +## [v0.3.2](https://github.com/NodeFactoryIo/vedran-daemon/tree/v0.3.2) + +[Full Changelog](https://github.com/NodeFactoryIo/vedran-daemon/compare/v0.3.1...v0.3.2) + +### Fixed +- Add target block to metrics [\#58](https://github.com/NodeFactoryIo/vedran-daemon/pull/58) ([MakMuftic](https://github.com/MakMuftic)) + +### Added + +### Changed + ## [v0.3.1](https://github.com/NodeFactoryIo/vedran-daemon/tree/v0.3.1) -[Full Changelog](https://github.com/NodeFactoryIo/vedran-daemon/compare/v0.3.0...HEAD) +[Full Changelog](https://github.com/NodeFactoryIo/vedran-daemon/compare/v0.3.0...v0.3.1) ### Fixed - Fix displaying configuration [\#53](https://github.com/NodeFactoryIo/vedran-daemon/pull/53) ([MakMuftic](https://github.com/MakMuftic)) From e16bc27d86c9b30406ee721c3db5eafb482dbe2d Mon Sep 17 00:00:00 2001 From: Mak Muftic Date: Wed, 20 Jan 2021 13:53:10 +0100 Subject: [PATCH 3/3] Update version file --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 43feb20..94f9589 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -version=0.3.1 +version=0.3.2