-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dependencies): add probes nodes and make more generic
Add the option to track probes dependencies as node in the manager. With this addition, the API was changed to support many node types. The watchers interface was made more generic, and Actions were introduced. The only supported Action currently available is node addition cancellation.
- Loading branch information
1 parent
32b2aab
commit 273ac35
Showing
8 changed files
with
643 additions
and
172 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package dependencies | ||
|
||
// Action is a struct representing a request by a watcher function to interact with the tree. | ||
// | ||
// Actions can perform various tasks, including but not limited to modifying the tree. | ||
// Utilizing Actions ensures that operations are executed in the proper order, avoiding | ||
// potential bugs related to operation sequencing. All interactions with the tree which | ||
// might modify the tree should be carried out through Actions, rather than directly | ||
// within a watcher's scope. | ||
type Action interface{} | ||
|
||
// CancelNodeAddAction cancels the process of adding a node to the manager. | ||
// | ||
// This method will: | ||
// 1. Cancel the addition of the specified node. | ||
// 2. Cancel the addition of all dependent nodes. | ||
// 3. Remove any dependencies that are no longer referenced by other nodes. | ||
// | ||
// The overall effect is similar to calling RemoveEvent directly on the manager, | ||
// but with additional safeguards and order of operations to ensure proper cleanup | ||
// and consistency within the system. | ||
// | ||
// Note: | ||
// - This action does not prevent other watchers from being notified. | ||
// - When the node addition is cancelled, event removal watchers will be invoked to allow for cleanup operations. | ||
// | ||
// It is recommended to use CancelNodeAddAction instead of directly calling RemoveEvent | ||
// to ensure that the cancellation and cleanup processes are handled in the correct order. | ||
type CancelNodeAddAction struct { | ||
Reason error | ||
} | ||
|
||
func NewCancelNodeAddAction(reason error) *CancelNodeAddAction { | ||
return &CancelNodeAddAction{Reason: reason} | ||
} |
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,34 @@ | ||
package dependencies | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ErrNodeAddCancelled is the error produced when cancelling a node add to the manager | ||
// using the CancelNodeAddAction Action. | ||
type ErrNodeAddCancelled struct { | ||
Reasons []error | ||
} | ||
|
||
func NewErrNodeAddCancelled(reasons []error) *ErrNodeAddCancelled { | ||
return &ErrNodeAddCancelled{Reasons: reasons} | ||
} | ||
|
||
func (cancelErr *ErrNodeAddCancelled) Error() string { | ||
var errorsStrings []string | ||
for _, err := range cancelErr.Reasons { | ||
errorsStrings = append(errorsStrings, err.Error()) | ||
} | ||
return fmt.Sprintf("node add was cancelled, reasons: \"%s\"", strings.Join(errorsStrings, "\", \"")) | ||
} | ||
|
||
func (cancelErr *ErrNodeAddCancelled) AddReason(reason error) { | ||
cancelErr.Reasons = append(cancelErr.Reasons, reason) | ||
} | ||
|
||
var ( | ||
ErrNodeType = errors.New("unsupported node type") | ||
ErrNodeNotFound = errors.New("node not found") | ||
) |
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
Oops, something went wrong.