Skip to content

Commit

Permalink
reduced indentation (for jeff)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstonematt committed Jun 14, 2024
1 parent b43e298 commit 89ebf69
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 74 deletions.
10 changes: 2 additions & 8 deletions cmd/solana_exporter/dynamic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import (

func TestSolanaCollector_Collect_Dynamic(t *testing.T) {
client := newDynamicRPCClient()
collector := createSolanaCollector(
client,
slotPacerSchedule,
)
collector := createSolanaCollector(client, slotPacerSchedule)
prometheus.NewPedanticRegistry().MustRegister(collector)

// start off by testing initial state:
Expand Down Expand Up @@ -155,10 +152,7 @@ func TestSolanaCollector_WatchSlots_Dynamic(t *testing.T) {

// create clients:
client := newDynamicRPCClient()
collector := createSolanaCollector(
client,
300*time.Millisecond,
)
collector := createSolanaCollector(client, 300*time.Millisecond)
prometheus.NewPedanticRegistry().MustRegister(collector)

// start client/collector and wait a bit:
Expand Down
36 changes: 10 additions & 26 deletions cmd/solana_exporter/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,40 +94,24 @@ func TestSolanaCollector_WatchSlots_Static(t *testing.T) {
go collector.WatchSlots(ctx)
time.Sleep(1 * time.Second)

firstSlot := staticEpochInfo.AbsoluteSlot - staticEpochInfo.SlotIndex
lastSlot := firstSlot + staticEpochInfo.SlotsInEpoch
tests := []struct {
expectedValue float64
metric prometheus.Gauge
}{
{
expectedValue: float64(staticEpochInfo.AbsoluteSlot),
metric: confirmedSlotHeight,
},
{
expectedValue: float64(staticEpochInfo.TransactionCount),
metric: totalTransactionsTotal,
},
{
expectedValue: float64(staticEpochInfo.Epoch),
metric: currentEpochNumber,
},
{
expectedValue: float64(staticEpochInfo.AbsoluteSlot - staticEpochInfo.SlotIndex),
metric: epochFirstSlot,
},
{
expectedValue: float64(staticEpochInfo.AbsoluteSlot - staticEpochInfo.SlotIndex + staticEpochInfo.SlotsInEpoch),
metric: epochLastSlot,
},
{expectedValue: float64(staticEpochInfo.AbsoluteSlot), metric: confirmedSlotHeight},
{expectedValue: float64(staticEpochInfo.TransactionCount), metric: totalTransactionsTotal},
{expectedValue: float64(staticEpochInfo.Epoch), metric: currentEpochNumber},
{expectedValue: float64(firstSlot), metric: epochFirstSlot},
{expectedValue: float64(lastSlot), metric: epochLastSlot},
}

for _, testCase := range tests {
name := extractName(testCase.metric.Desc())
t.Run(
name,
func(t *testing.T) {
assert.Equal(t, testCase.expectedValue, testutil.ToFloat64(testCase.metric))
},
)
t.Run(name, func(t *testing.T) {
assert.Equal(t, testCase.expectedValue, testutil.ToFloat64(testCase.metric))
})
}

metrics := map[string]*prometheus.CounterVec{
Expand Down
51 changes: 11 additions & 40 deletions cmd/solana_exporter/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/certusone/solana_exporter/pkg/rpc"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
"math/rand"
"regexp"
"testing"
Expand Down Expand Up @@ -39,16 +40,8 @@ type (
)

var (
identities = []string{
"aaa",
"bbb",
"ccc",
}
identityVotes = map[string]string{
"aaa": "AAA",
"bbb": "BBB",
"ccc": "CCC",
}
identities = []string{"aaa", "bbb", "ccc"}
identityVotes = map[string]string{"aaa": "AAA", "bbb": "BBB", "ccc": "CCC"}
nv = len(identities)
staticEpochInfo = rpc.EpochInfo{
AbsoluteSlot: 166598,
Expand All @@ -62,18 +55,9 @@ var (
FirstSlot: 100000000,
LastSlot: 200000000,
Hosts: map[string]rpc.BlockProductionPerHost{
"bbb": {
LeaderSlots: 40000000,
BlocksProduced: 36000000,
},
"ccc": {
LeaderSlots: 30000000,
BlocksProduced: 29600000,
},
"aaa": {
LeaderSlots: 30000000,
BlocksProduced: 10000000,
},
"bbb": {LeaderSlots: 40000000, BlocksProduced: 36000000},
"ccc": {LeaderSlots: 30000000, BlocksProduced: 29600000},
"aaa": {LeaderSlots: 30000000, BlocksProduced: 10000000},
},
}
staticVoteAccounts = rpc.VoteAccounts{
Expand Down Expand Up @@ -307,10 +291,7 @@ func (c *dynamicRPCClient) GetVoteAccounts(
currentVoteAccounts = append(currentVoteAccounts, voteAccount)
}
}
return &rpc.VoteAccounts{
Current: currentVoteAccounts,
Delinquent: delinquentVoteAccounts,
}, nil
return &rpc.VoteAccounts{Current: currentVoteAccounts, Delinquent: delinquentVoteAccounts}, nil
}

//goland:noinspection GoUnusedParameter
Expand Down Expand Up @@ -347,10 +328,8 @@ func (c *dynamicRPCClient) GetBlockProduction(
func extractName(desc *prometheus.Desc) string {
// Get the string representation of the descriptor
descString := desc.String()

// Use regex to extract the metric name and help message from the descriptor string
reName := regexp.MustCompile(`fqName: "([^"]+)"`)

nameMatch := reName.FindStringSubmatch(descString)

var name string
Expand All @@ -368,17 +347,9 @@ type collectionTest struct {

func runCollectionTests(t *testing.T, collector prometheus.Collector, testCases []collectionTest) {
for _, test := range testCases {
t.Run(
test.Name,
func(t *testing.T) {
if err := testutil.CollectAndCompare(
collector,
bytes.NewBufferString(test.ExpectedResponse),
test.Name,
); err != nil {
t.Errorf("unexpected collecting result for %s: \n%s", test.Name, err)
}
},
)
t.Run(test.Name, func(t *testing.T) {
err := testutil.CollectAndCompare(collector, bytes.NewBufferString(test.ExpectedResponse), test.Name)
assert.Nilf(t, "unexpected collecting result for %s: \n%s", test.Name, err)
})
}
}

0 comments on commit 89ebf69

Please sign in to comment.