-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package metrics | ||
|
||
import ( | ||
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" | ||
|
||
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types" | ||
"github.com/smartcontractkit/chainlink-solana/pkg/solana/fees" | ||
) | ||
|
||
//go:generate mockery --name Fees --output ./mocks/ | ||
|
||
type Fees interface { | ||
Set(txFee uint64, computeUnitPrice fees.ComputeUnitPrice, feedInput FeedInput) | ||
Cleanup(feedInput FeedInput) | ||
} | ||
|
||
var _ Fees = (*feeMetrics)(nil) | ||
|
||
type feeMetrics struct { | ||
txFee simpleGauge | ||
computeUnit simpleGauge | ||
} | ||
|
||
func NewFees(log commonMonitoring.Logger) *feeMetrics { | ||
return &feeMetrics{ | ||
txFee: newSimpleGauge(log, types.TxFeeMetric), | ||
computeUnit: newSimpleGauge(log, types.ComputeUnitPriceMetric), | ||
} | ||
} | ||
|
||
func (sh *feeMetrics) Set(txFee uint64, computeUnitPrice fees.ComputeUnitPrice, feedInput FeedInput) { | ||
sh.txFee.set(float64(txFee), feedInput.ToPromLabels()) | ||
sh.computeUnit.set(float64(computeUnitPrice), feedInput.ToPromLabels()) | ||
} | ||
|
||
func (sh *feeMetrics) Cleanup(feedInput FeedInput) { | ||
sh.txFee.delete(feedInput.ToPromLabels()) | ||
sh.computeUnit.delete(feedInput.ToPromLabels()) | ||
} |
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,45 @@ | ||
package metrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"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" | ||
"github.com/smartcontractkit/chainlink-solana/pkg/solana/fees" | ||
) | ||
|
||
func TestFees(t *testing.T) { | ||
lgr := logger.Test(t) | ||
m := NewFees(lgr) | ||
|
||
// fetching gauges | ||
gFees, ok := gauges[types.TxFeeMetric] | ||
require.True(t, ok) | ||
gComputeUnits, ok := gauges[types.ComputeUnitPriceMetric] | ||
require.True(t, ok) | ||
|
||
v0 := 1 | ||
v1 := 10 | ||
l := FeedInput{NetworkID: t.Name()} | ||
|
||
// set gauge | ||
assert.NotPanics(t, func() { | ||
m.Set(uint64(v0), fees.ComputeUnitPrice(v1), l) | ||
}) | ||
num := testutil.ToFloat64(gFees.With(l.ToPromLabels())) | ||
assert.Equal(t, float64(v0), num) | ||
num = testutil.ToFloat64(gComputeUnits.With(l.ToPromLabels())) | ||
assert.Equal(t, float64(v1), num) | ||
|
||
// cleanup gauges | ||
assert.Equal(t, 1, testutil.CollectAndCount(gFees)) | ||
assert.Equal(t, 1, testutil.CollectAndCount(gComputeUnits)) | ||
assert.NotPanics(t, func() { m.Cleanup(l) }) | ||
assert.Equal(t, 0, testutil.CollectAndCount(gFees)) | ||
assert.Equal(t, 0, testutil.CollectAndCount(gComputeUnits)) | ||
} |
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