Skip to content

Commit

Permalink
share naming + test cov
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed Apr 17, 2024
1 parent 3dffb07 commit 3d5d3cf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/monitoring/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ func main() {
slotHeightSourceFactory,
)

// exporter names
promExporter := "solana-prom-exporter"
promMetrics := "solana-metrics"

// per-feed exporters
feedBalancesExporterFactory := exporter.NewFeedBalancesFactory(
logger.With(log, "component", "solana-prom-exporter"),
metrics.NewFeedBalances(logger.With(log, "component", "solana-metrics")),
logger.With(log, "component", promExporter),
metrics.NewFeedBalances(logger.With(log, "component", promMetrics)),
)
reportObservationsFactory := exporter.NewReportObservationsFactory(
logger.With(log, "component", "solana-prome-exporter"),
metrics.NewReportObservations(logger.With(log, "component", "solana-metrics")),
metrics.NewReportObservations(logger.With(log, "component", promMetrics)),
)
monitor.ExporterFactories = append(monitor.ExporterFactories,
feedBalancesExporterFactory,
Expand All @@ -101,12 +105,12 @@ func main() {

// network exporters
nodeBalancesExporterFactory := exporter.NewNodeBalancesFactory(
logger.With(log, "component", "solana-prom-exporter"),
logger.With(log, "component", promExporter),
metrics.NewNodeBalances,
)
slotHeightExporterFactory := exporter.NewSlotHeightFactory(
logger.With(log, "component", "solana-prom-exporter"),
metrics.NewSlotHeight(logger.With(log, "component", "solana-metrics")),
logger.With(log, "component", promExporter),
metrics.NewSlotHeight(logger.With(log, "component", promMetrics)),
)
monitor.NetworkExporterFactories = append(monitor.NetworkExporterFactories,
nodeBalancesExporterFactory,
Expand Down
37 changes: 37 additions & 0 deletions pkg/monitoring/source_slotheight_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package monitoring

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/mocks"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types"
)

func TestSlotHeightSource(t *testing.T) {
cr := mocks.NewChainReader(t)
lgr := logger.Test(t)
ctx := utils.Context(t)

factory := NewSlotHeightSourceFactory(cr, lgr)
assert.Equal(t, types.SlotHeightType, factory.GetType())

// generate source
source, err := factory.NewSource(nil, nil)
assert.Error(t, err)
source, err = factory.NewSource(nil, nil)

cr.On("GetSlot", mock.Anything, mock.Anything, mock.Anything).Return(uint64(1), nil).Once()

// happy path
out, err := source.Fetch(ctx)
require.NoError(t, err)
slot, ok := out.(types.SlotHeight)
require.True(t, ok)
assert.Equal(t, types.SlotHeight(1), slot)
}

0 comments on commit 3d5d3cf

Please sign in to comment.