Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change set adds reporting for the following events: 1) Gossip's height is incremented - gauge metric 2) A block commit is made - histogram metric with elapsed time, with a label of the sequence of the block. 3) A block is pushed or popped from the payload buffer - gauge metric with the block sequence as the value, and also a gauge metric of the payload buffer size at time of push/pop. Change-Id: I542799097aa89cef32b81affa4bbd32f50b39ef7 Signed-off-by: Hagar Meir <hagar.meir@ibm.com>
- Loading branch information
Showing
12 changed files
with
363 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package metrics | ||
|
||
import "github.com/hyperledger/fabric/common/metrics" | ||
|
||
// GossipMetrics encapsulates all of gossip metrics | ||
type GossipMetrics struct { | ||
StateMetrics *StateMetrics | ||
} | ||
|
||
func NewGossipMetrics(p metrics.Provider) *GossipMetrics { | ||
return &GossipMetrics{ | ||
StateMetrics: newStateMetrics(p), | ||
} | ||
} | ||
|
||
// StateMetrics encapsulates gossip state related metrics | ||
type StateMetrics struct { | ||
Height metrics.Gauge | ||
CommitDuration metrics.Histogram | ||
PayloadBufferSize metrics.Gauge | ||
} | ||
|
||
func newStateMetrics(p metrics.Provider) *StateMetrics { | ||
return &StateMetrics{ | ||
Height: p.NewGauge(HeightOpts), | ||
CommitDuration: p.NewHistogram(CommitDurationOpts), | ||
PayloadBufferSize: p.NewGauge(PayloadBufferSizeOpts), | ||
} | ||
} | ||
|
||
var ( | ||
HeightOpts = metrics.GaugeOpts{ | ||
Namespace: "gossip", | ||
Subsystem: "state", | ||
Name: "height", | ||
Help: "Current ledger height", | ||
LabelNames: []string{"channel"}, | ||
StatsdFormat: "%{#fqname}.%{channel}", | ||
} | ||
|
||
CommitDurationOpts = metrics.HistogramOpts{ | ||
Namespace: "gossip", | ||
Subsystem: "state", | ||
Name: "commit_duration", | ||
Help: "Time it takes to commit a block in seconds", | ||
LabelNames: []string{"channel"}, | ||
StatsdFormat: "%{#fqname}.%{channel}", | ||
} | ||
|
||
PayloadBufferSizeOpts = metrics.GaugeOpts{ | ||
Namespace: "gossip", | ||
Subsystem: "payload_buffer", | ||
Name: "size", | ||
Help: "Size of the payload buffer", | ||
LabelNames: []string{"channel"}, | ||
StatsdFormat: "%{#fqname}.%{channel}", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package metrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric/common/metrics/metricsfakes" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
|
||
provider := &metricsfakes.Provider{} | ||
|
||
counter := &metricsfakes.Counter{} | ||
gauge := &metricsfakes.Gauge{} | ||
histogram := &metricsfakes.Histogram{} | ||
|
||
provider.NewCounterReturns(counter) | ||
provider.NewGaugeReturns(gauge) | ||
provider.NewHistogramReturns(histogram) | ||
|
||
gossipMetrics := NewGossipMetrics(provider) | ||
|
||
// make sure all metrics were created | ||
assert.NotNil(t, gossipMetrics) | ||
assert.NotNil(t, gossipMetrics.StateMetrics) | ||
assert.NotNil(t, gossipMetrics.StateMetrics.Height) | ||
assert.NotNil(t, gossipMetrics.StateMetrics.CommitDuration) | ||
assert.NotNil(t, gossipMetrics.StateMetrics.PayloadBufferSize) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.