Skip to content

Commit

Permalink
fix: rely solely on configIdx changes to capture a TriggeredConfigChange
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoutsovasilis committed May 14, 2024
1 parent 7dec8b5 commit e907187
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
32 changes: 0 additions & 32 deletions pkg/client/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,40 +325,8 @@ func (u *Unit) updateState(

if u.configIdx != cfgIdx {
u.configIdx = cfgIdx
if !gproto.Equal(u.config.GetSource(), cfg.GetSource()) {
u.config = cfg
triggers |= TriggeredConfigChange
}
}

if u.config.GetRevision() != cfg.GetRevision() {
u.config = cfg
triggers |= TriggeredConfigChange
}

switch {
case u.config == cfg:
break
case u.config != nil && cfg == nil:
u.config = cfg
triggers |= TriggeredConfigChange
case u.config == nil && cfg != nil:
u.config = cfg
triggers |= TriggeredConfigChange
case u.config != nil && cfg != nil:
if len(u.config.Streams) != len(cfg.Streams) {
u.config = cfg
triggers |= TriggeredConfigChange
break
}

for idx, stream := range cfg.Streams {
if !gproto.Equal(stream, cfg.Streams[idx]) {
u.config = cfg
triggers |= TriggeredConfigChange
break
}
}
}

if !gproto.Equal(u.apm, expAPM) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/client/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ func TestUnitUpdateWithSameMap(t *testing.T) {
_, err = gproto.Marshal(newUnit)
require.NoError(t, err)

// This should return TriggeredNothing, as the two underlying maps in `source` are the same
// This should return TriggeredConfigChange, as the configIdx has changed (this is our criteria)
// no matter if the actual map is the same
got := defaultTest.updateState(UnitStateHealthy, UnitLogLevelDebug, 0, nil, newUnit, 2, nil)
assert.Equal(t, TriggeredNothing, got)
assert.Equal(t, TriggeredConfigChange, got)
}

func TestUnitUpdateWithNewMap(t *testing.T) {
Expand Down

0 comments on commit e907187

Please sign in to comment.