Skip to content

Commit

Permalink
send events on errors
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <[email protected]>
  • Loading branch information
miklezzzz committed Dec 12, 2024
1 parent 7a6e5ec commit be030b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions pkg/module_manager/module_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ func (mm *ModuleManager) RecalculateGraph(logLabels map[string]string) bool {
EventType: events.ModuleStateChanged,
})
}

return stateChanged
}

Expand All @@ -892,6 +893,7 @@ func (mm *ModuleManager) GlobalSynchronizationNeeded() bool {
return true
}
}

return false
}

Expand Down
40 changes: 22 additions & 18 deletions pkg/module_manager/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func (s *Scheduler) Filter(extName extenders.ExtenderName, moduleName string, lo
// - true if the state of any vertex has changed (enabled/disabled) or there were any errors during the run;
// - true if some other parameters, apart from state, of a vertex has changed.
func (s *Scheduler) recalculateGraphState(logLabels map[string]string) ( /* Graph's state has changed */ bool /* list of the vertices, which updateBy statuses have changed */, []string) {
diff, updByDiff := make(map[string]bool), make(map[string]struct{}, 0)
stateDiff, metaDiff := make(map[string]bool), make(map[string]struct{}, 0)
errList := make([]string, 0)
logEntry := utils.EnrichLoggerWithLabels(s.logger, logLabels)

Expand All @@ -720,6 +720,10 @@ func (s *Scheduler) recalculateGraphState(logLabels map[string]string) ( /* Grap

outerCycle:
for _, vertex := range vertices {
var (
filterErr error
moduleStatus *bool
)
moduleName := vertex.GetName()
s.vertexStateBuffer.state[moduleName] = &vertexState{}

Expand All @@ -729,9 +733,9 @@ outerCycle:
break
}

moduleStatus, err := e.ext.Filter(moduleName, logLabels)
if err != nil {
if permanent, ok := err.(*exerror.PermanentError); ok {
moduleStatus, filterErr = e.ext.Filter(moduleName, logLabels)
if filterErr != nil {
if permanent, ok := filterErr.(*exerror.PermanentError); ok {
errList = append(errList, fmt.Sprintf("%s extender failed to filter %s module: %s", e.ext.Name(), moduleName, permanent.Error()))
break outerCycle
}
Expand Down Expand Up @@ -759,15 +763,15 @@ outerCycle:
}

if s.vertexStateBuffer.state[moduleName].enabled != vertex.GetState() {
diff[moduleName] = s.vertexStateBuffer.state[moduleName].enabled
stateDiff[moduleName] = s.vertexStateBuffer.state[moduleName].enabled
} else {
delete(diff, moduleName)
delete(stateDiff, moduleName)
}

if s.vertexStateBuffer.state[moduleName].updatedBy != vertex.GetUpdatedBy() {
updByDiff[moduleName] = struct{}{}
if s.vertexStateBuffer.state[moduleName].updatedBy != vertex.GetUpdatedBy() || filterErr != nil {
metaDiff[moduleName] = struct{}{}
} else {
delete(updByDiff, moduleName)
delete(metaDiff, moduleName)
}

if s.vertexStateBuffer.state[moduleName].enabled {
Expand Down Expand Up @@ -798,15 +802,15 @@ outerCycle:
}

// merge the state diffs
for vertexName, newDiffState := range diff {
for vertexName, newStateDiff := range stateDiff {
// if a new diff has an opposite state for the module, the module is deleted from the resulting diff
if currentDiffState, found := s.diff[vertexName]; found {
if currentDiffState != newDiffState {
if currentStateDiff, found := s.diff[vertexName]; found {
if currentStateDiff != newStateDiff {
delete(s.diff, vertexName)
}
// if current diff doesn't have the module's state - add it to the resulting diff
} else {
s.diff[vertexName] = newDiffState
s.diff[vertexName] = newStateDiff
}
}

Expand All @@ -829,13 +833,13 @@ outerCycle:
s.errList = make([]string, 0)
logEntry.Debugf("Graph was successfully updated, diff: [%v]", s.diff)

updByDiffSlice := make([]string, 0, len(updByDiff))
for moduleName := range updByDiff {
updByDiffSlice = append(updByDiffSlice, moduleName)
metaDiffSlice := make([]string, 0, len(metaDiff))
for moduleName := range metaDiff {
metaDiffSlice = append(metaDiffSlice, moduleName)
}
slices.Sort(updByDiffSlice)
slices.Sort(metaDiffSlice)

return len(diff) > 0, updByDiffSlice
return len(stateDiff) > 0, metaDiffSlice
}

// gleanGraphDiff returns modules diff list
Expand Down

0 comments on commit be030b2

Please sign in to comment.