Introduced additional identity label to metrics.
This commit is contained in:
parent
3f6e578768
commit
f410d9893d
|
@ -20,6 +20,7 @@ const (
|
||||||
VersionLabel = "version"
|
VersionLabel = "version"
|
||||||
AddressLabel = "address"
|
AddressLabel = "address"
|
||||||
EpochLabel = "epoch"
|
EpochLabel = "epoch"
|
||||||
|
IdentityLabel = "identity"
|
||||||
|
|
||||||
StatusSkipped = "skipped"
|
StatusSkipped = "skipped"
|
||||||
StatusValid = "valid"
|
StatusValid = "valid"
|
||||||
|
@ -38,6 +39,7 @@ type SolanaCollector struct {
|
||||||
// config:
|
// config:
|
||||||
slotPace time.Duration
|
slotPace time.Duration
|
||||||
balanceAddresses []string
|
balanceAddresses []string
|
||||||
|
identity *string
|
||||||
|
|
||||||
/// descriptors:
|
/// descriptors:
|
||||||
totalValidatorsDesc *prometheus.Desc
|
totalValidatorsDesc *prometheus.Desc
|
||||||
|
@ -51,13 +53,12 @@ type SolanaCollector struct {
|
||||||
numSlotsBehind *prometheus.Desc
|
numSlotsBehind *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSolanaCollector(
|
func NewSolanaCollector(provider rpc.Provider, slotPace time.Duration, balanceAddresses []string, nodekeys []string, votekeys []string, identity *string) *SolanaCollector {
|
||||||
provider rpc.Provider, slotPace time.Duration, balanceAddresses []string, nodekeys []string, votekeys []string,
|
|
||||||
) *SolanaCollector {
|
|
||||||
collector := &SolanaCollector{
|
collector := &SolanaCollector{
|
||||||
rpcClient: provider,
|
rpcClient: provider,
|
||||||
slotPace: slotPace,
|
slotPace: slotPace,
|
||||||
balanceAddresses: CombineUnique(balanceAddresses, nodekeys, votekeys),
|
balanceAddresses: CombineUnique(balanceAddresses, nodekeys, votekeys),
|
||||||
|
identity: identity,
|
||||||
totalValidatorsDesc: prometheus.NewDesc(
|
totalValidatorsDesc: prometheus.NewDesc(
|
||||||
"solana_active_validators",
|
"solana_active_validators",
|
||||||
"Total number of active validators by state",
|
"Total number of active validators by state",
|
||||||
|
@ -103,13 +104,13 @@ func NewSolanaCollector(
|
||||||
isHealthy: prometheus.NewDesc(
|
isHealthy: prometheus.NewDesc(
|
||||||
"solana_is_healthy",
|
"solana_is_healthy",
|
||||||
"Whether the node is healthy or not.",
|
"Whether the node is healthy or not.",
|
||||||
nil,
|
[]string{IdentityLabel},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
numSlotsBehind: prometheus.NewDesc(
|
numSlotsBehind: prometheus.NewDesc(
|
||||||
"solana_num_slots_behind",
|
"solana_num_slots_behind",
|
||||||
"The number of slots that the node is behind the latest cluster confirmed slot.",
|
"The number of slots that the node is behind the latest cluster confirmed slot.",
|
||||||
nil,
|
[]string{IdentityLabel},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -241,8 +242,8 @@ func (c *SolanaCollector) collectHealth(ctx context.Context, ch chan<- prometheu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(c.isHealthy, prometheus.GaugeValue, float64(isHealthy))
|
ch <- prometheus.MustNewConstMetric(c.isHealthy, prometheus.GaugeValue, float64(isHealthy), *c.identity)
|
||||||
ch <- prometheus.MustNewConstMetric(c.numSlotsBehind, prometheus.GaugeValue, float64(numSlotsBehind))
|
ch <- prometheus.MustNewConstMetric(c.numSlotsBehind, prometheus.GaugeValue, float64(numSlotsBehind), *c.identity)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -273,8 +274,11 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Fatalf("Failed to get associated vote accounts for %v: %v", config.NodeKeys, err)
|
klog.Fatalf("Failed to get associated vote accounts for %v: %v", config.NodeKeys, err)
|
||||||
}
|
}
|
||||||
|
identity, err := client.GetIdentity(ctx)
|
||||||
collector := NewSolanaCollector(client, slotPacerSchedule, config.BalanceAddresses, config.NodeKeys, votekeys)
|
if err != nil {
|
||||||
|
klog.Fatalf("Failed to get identity: %v", err)
|
||||||
|
}
|
||||||
|
collector := NewSolanaCollector(client, slotPacerSchedule, config.BalanceAddresses, config.NodeKeys, votekeys, identity)
|
||||||
slotWatcher := NewSlotWatcher(
|
slotWatcher := NewSlotWatcher(
|
||||||
client, config.NodeKeys, votekeys, config.ComprehensiveSlotTracking, config.MonitorBlockSizes,
|
client, config.NodeKeys, votekeys, config.ComprehensiveSlotTracking, config.MonitorBlockSizes,
|
||||||
)
|
)
|
||||||
|
|
|
@ -43,6 +43,7 @@ type (
|
||||||
var (
|
var (
|
||||||
identities = []string{"aaa", "bbb", "ccc"}
|
identities = []string{"aaa", "bbb", "ccc"}
|
||||||
votekeys = []string{"AAA", "BBB", "CCC"}
|
votekeys = []string{"AAA", "BBB", "CCC"}
|
||||||
|
identity = "aaa"
|
||||||
balances = map[string]float64{"aaa": 1, "bbb": 2, "ccc": 3, "AAA": 4, "BBB": 5, "CCC": 6}
|
balances = map[string]float64{"aaa": 1, "bbb": 2, "ccc": 3, "AAA": 4, "BBB": 5, "CCC": 6}
|
||||||
identityVotes = map[string]string{"aaa": "AAA", "bbb": "BBB", "ccc": "CCC"}
|
identityVotes = map[string]string{"aaa": "AAA", "bbb": "BBB", "ccc": "CCC"}
|
||||||
nv = len(identities)
|
nv = len(identities)
|
||||||
|
@ -420,7 +421,7 @@ func runCollectionTests(t *testing.T, collector prometheus.Collector, testCases
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSolanaCollector_Collect_Static(t *testing.T) {
|
func TestSolanaCollector_Collect_Static(t *testing.T) {
|
||||||
collector := NewSolanaCollector(&staticRPCClient{}, slotPacerSchedule, nil, identities, votekeys)
|
collector := NewSolanaCollector(&staticRPCClient{}, slotPacerSchedule, nil, identities, votekeys, &identity)
|
||||||
prometheus.NewPedanticRegistry().MustRegister(collector)
|
prometheus.NewPedanticRegistry().MustRegister(collector)
|
||||||
|
|
||||||
testCases := []collectionTest{
|
testCases := []collectionTest{
|
||||||
|
@ -492,7 +493,7 @@ solana_node_version{version="1.16.7"} 1
|
||||||
|
|
||||||
func TestSolanaCollector_Collect_Dynamic(t *testing.T) {
|
func TestSolanaCollector_Collect_Dynamic(t *testing.T) {
|
||||||
client := newDynamicRPCClient()
|
client := newDynamicRPCClient()
|
||||||
collector := NewSolanaCollector(client, slotPacerSchedule, nil, identities, votekeys)
|
collector := NewSolanaCollector(client, slotPacerSchedule, nil, identities, votekeys, &identity)
|
||||||
prometheus.NewPedanticRegistry().MustRegister(collector)
|
prometheus.NewPedanticRegistry().MustRegister(collector)
|
||||||
|
|
||||||
// start off by testing initial state:
|
// start off by testing initial state:
|
||||||
|
|
|
@ -75,6 +75,7 @@ type Provider interface {
|
||||||
GetBlock(ctx context.Context, commitment Commitment, slot int64, transactionDetails string) (*Block, error)
|
GetBlock(ctx context.Context, commitment Commitment, slot int64, transactionDetails string) (*Block, error)
|
||||||
|
|
||||||
GetHealth(ctx context.Context) (*string, error)
|
GetHealth(ctx context.Context) (*string, error)
|
||||||
|
GetIdentity(ctx context.Context) (*string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Commitment) MarshalJSON() ([]byte, error) {
|
func (c Commitment) MarshalJSON() ([]byte, error) {
|
||||||
|
@ -315,3 +316,13 @@ func (c *Client) GetHealth(ctx context.Context) (*string, error) {
|
||||||
}
|
}
|
||||||
return &resp.Result, nil
|
return &resp.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIdentity Returns the identity pubkey for the current node
|
||||||
|
// See API docs: https://solana.com/docs/rpc/http/getidentity
|
||||||
|
func (c *Client) GetIdentity(ctx context.Context) (*string, error) {
|
||||||
|
var resp response[Identity]
|
||||||
|
if err := getResponse(ctx, c, "getIdentity", []any{}, &resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp.Result.Identity, nil
|
||||||
|
}
|
||||||
|
|
|
@ -98,6 +98,9 @@ type (
|
||||||
RewardType string `json:"rewardType"`
|
RewardType string `json:"rewardType"`
|
||||||
Commission uint8 `json:"commission"`
|
Commission uint8 `json:"commission"`
|
||||||
}
|
}
|
||||||
|
Identity struct {
|
||||||
|
Identity string `json:"identity"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *RPCError) Error() string {
|
func (e *RPCError) Error() string {
|
||||||
|
|
Loading…
Reference in New Issue