-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add slot height metric + SlotHeight type
- Loading branch information
Showing
6 changed files
with
130 additions
and
2 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" | ||
|
||
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types" | ||
) | ||
|
||
//go:generate mockery --name SlotHeight --output ./mocks/ | ||
|
||
type SlotHeight interface { | ||
Set(slot types.SlotHeight, chain, url string) | ||
Cleanup() | ||
} | ||
|
||
var _ SlotHeight = (*slotHeight)(nil) | ||
|
||
type slotHeight struct { | ||
simpleGauge | ||
labels prometheus.Labels | ||
} | ||
|
||
func NewSlotHeight(log commonMonitoring.Logger) *slotHeight { | ||
return &slotHeight{ | ||
simpleGauge: newSimpleGauge(log, types.SlotHeightMetric), | ||
} | ||
} | ||
|
||
func (sh *slotHeight) Set(slot types.SlotHeight, chain, url string) { | ||
sh.labels = prometheus.Labels{"chain": chain, "url": url} | ||
sh.set(float64(slot), sh.labels) | ||
} | ||
|
||
func (sh *slotHeight) Cleanup() { | ||
sh.delete(sh.labels) | ||
} |
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,38 @@ | ||
package metrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
|
||
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types" | ||
) | ||
|
||
func TestSlotHeight(t *testing.T) { | ||
lgr := logger.Test(t) | ||
m := NewSlotHeight(lgr) | ||
|
||
// fetching gauges | ||
g, ok := gauges[types.SlotHeightMetric] | ||
require.True(t, ok) | ||
|
||
v := 100 | ||
|
||
// set gauge | ||
assert.NotPanics(t, func() { m.Set(types.SlotHeight(v), t.Name(), t.Name()+"_url") }) | ||
promBal := testutil.ToFloat64(g.With(prometheus.Labels{ | ||
"chain": t.Name(), | ||
"url": t.Name() + "_url", | ||
})) | ||
assert.Equal(t, float64(v), promBal) | ||
|
||
// cleanup gauges | ||
assert.Equal(t, 1, testutil.CollectAndCount(g)) | ||
assert.NotPanics(t, func() { m.Cleanup() }) | ||
assert.Equal(t, 0, testutil.CollectAndCount(g)) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package types | ||
|
||
// types.go contains simple types, more complex types should have a separate file | ||
const ( | ||
SlotHeightType = "slot_height" | ||
SlotHeightType = "slot_height" | ||
SlotHeightMetric = "sol_" + SlotHeightType | ||
) | ||
|
||
// SlotHeight type wraps the uint64 type returned by the RPC call | ||
// this helps to delineate types when sending to the exporter | ||
type SlotHeight uint64 |