Skip to content

Commit

Permalink
example: Fix metrics-related dependency issue
Browse files Browse the repository at this point in the history
NewExpVarMetrics required the publish parameter which wasn't provided
by the example. Rework the API.

Signed-off-by: Jussi Maki <[email protected]>
  • Loading branch information
joamaki committed Mar 28, 2024
1 parent 927c5a9 commit c8b09a3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion reconciler/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var Hive = hive.New(
),
)

func NewReconcilerConfig(ops reconciler.Operations[*Memo], m reconciler.Metrics) reconciler.Config[*Memo] {
func NewReconcilerConfig(ops reconciler.Operations[*Memo], m *reconciler.ExpVarMetrics) reconciler.Config[*Memo] {
return reconciler.Config[*Memo]{
Metrics: m,
FullReconcilationInterval: 10 * time.Second,
Expand Down
10 changes: 9 additions & 1 deletion reconciler/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ func (m *ExpVarMetrics) IncrementalReconciliationErrors(moduleID cell.FullModule

var _ Metrics = &ExpVarMetrics{}

func NewExpVarMetrics(publish bool) *ExpVarMetrics {
func NewExpVarMetrics() *ExpVarMetrics {
return newExpVarMetrics(true)
}

func NewUnpublishedExpVarMetrics() *ExpVarMetrics {
return newExpVarMetrics(false)
}

func newExpVarMetrics(publish bool) *ExpVarMetrics {
newMap := func(name string) *expvar.Map {
if publish {
return expvar.NewMap(name)
Expand Down
2 changes: 1 addition & 1 deletion reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func New[Obj comparable](p Params[Obj]) (Reconciler[Obj], error) {
}

if p.Config.Metrics == nil {
p.Config.Metrics = NewExpVarMetrics(false)
p.Config.Metrics = NewUnpublishedExpVarMetrics()
}

idx := p.Table.PrimaryIndexer()
Expand Down
2 changes: 1 addition & 1 deletion reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func testReconciler(t *testing.T, batchOps bool) {
fakeHealth *cell.SimpleHealth
)

expVarMetrics := reconciler.NewExpVarMetrics(false)
expVarMetrics := reconciler.NewUnpublishedExpVarMetrics()

testObjects, err := statedb.NewTable[*testObject]("test-objects", idIndex, statusIndex)
require.NoError(t, err, "NewTable")
Expand Down

0 comments on commit c8b09a3

Please sign in to comment.