Documentation
¶
Index ¶
- func BuildChildToParentsMap(nodes map[string]*Node) (childToParents map[string]ChildToParents)
- func DiffLeft(left, right []string) []string
- func GetCandidateDagObjects(g *Graph, doneDagObjects ...string) (sets.Set[string], error)
- type Analysis
- type AnalysisItem
- type ChildToParents
- type DependencyNode
- type Graph
- type Node
- type Object
- type ObjectExecution
- type Objects
- type RunnerResults
- func (r *RunnerResults) BuildDependencyTree(phaseMap map[int][]ObjectExecution, childToParents map[string]ChildToParents) []DependencyNode
- func (r *RunnerResults) GetPhaseMap() map[int][]ObjectExecution
- func (r *RunnerResults) HasAnError() bool
- func (r *RunnerResults) ToAnalysis(sourceOfExecution string, timeConsumingThresholdMs int64) Analysis
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildChildToParentsMap ¶
func BuildChildToParentsMap(nodes map[string]*Node) (childToParents map[string]ChildToParents)
BuildChildToParentsMap constructs a mapping from each child node to its parent nodes. Given a map of node keys to Node pointers, it returns a map where each key is a child node's key, and the value is a ChildToParents struct containing the child key and a slice of its parent keys. This function ensures that all nodes and their parents are represented in the resulting map.
func DiffLeft ¶
DiffLeft returns a slice containing elements that are present in the 'left' slice but not in the 'right' slice. It compares elements using equality and preserves the order from the 'left' slice. Duplicate elements in 'left' that are not in 'right' will be included in the result.
func GetCandidateDagObjects ¶
GetCandidateDagObjects returns a set of DAG object names that are candidates for scheduling, given a graph and a list of completed DAG object names. It traverses the graph from its roots, determines which objects are schedulable based on their dependencies, and ensures that the provided list of completed objects is valid (i.e., no object is marked as done before its ancestors). If the list of completed objects is invalid, an error is returned.
Types ¶
type Analysis ¶
type Analysis struct {
TotalTimeMilliseconds int64 `json:"totalTimeMilliseconds" yaml:"totalTimeMilliseconds" doc:"Total time taken to execute all objects in milliseconds"`
All []AnalysisItem `json:"all" yaml:"all" doc:"All objects with their execution details"`
Failed []AnalysisItem `json:"failed" yaml:"failed" doc:"objects that failed during execution"`
TimeConsuming []AnalysisItem `json:"timeConsuming" yaml:"timeConsuming" doc:"objects that took a long time to execute (over 10ms)"`
}
Analysis represents the execution analysis of a set of objects, including total execution time, details for all objects, failed objects, and those that took a significant amount of time to execute.
type AnalysisItem ¶
type AnalysisItem struct {
Name string `json:"name" yaml:"name" doc:"The name of the object"`
Position int `json:"position" yaml:"position" doc:"The position of the object in the execution order"`
TotalTimeMilliSeconds int64 `json:"totalTimeMilliSeconds" yaml:"totalTimeMilliSeconds" doc:"Total time taken to execute the object in milliseconds"`
Error error `json:"error,omitempty" yaml:"error,omitempty" doc:"Error encountered during object execution"`
Phase int `json:"phase,omitempty" yaml:"phase,omitempty" doc:"The phase in which the object was executed"`
TimeConsuming bool `` /* 131-byte string literal not displayed */
SourceExecution string `` /* 155-byte string literal not displayed */
}
AnalysisItem represents an object analyzed during DAG execution. It contains metadata about the object's execution, including its name, position in the execution order, total execution time, any error encountered, the phase of execution, and flags indicating if it was time-consuming or executed in a particular state.
type ChildToParents ¶
type ChildToParents struct {
Child string `json:"child" yaml:"child" doc:"The child object"`
Parents []string `json:"parents" yaml:"parents" doc:"The parent objects"`
}
ChildToParents represents a relationship between a child object and its parent objects. It contains the name of the child and a list of its parent names.
type DependencyNode ¶
type DependencyNode struct {
Name string `json:"name" yaml:"name" doc:"The name of the object" example:"platformAdministratorsGroup" pattern:"^(.|\\n|\\r)*"`
Children map[string]*DependencyNode `json:"children,omitempty" yaml:"children,omitempty" doc:"The child nodes of the dependency tree" required:"false" `
TotalTime time.Duration `json:"totalTime" yaml:"totalTime" doc:"The total time taken to execute this object"`
Phase int `` /* 143-byte string literal not displayed */
}
DependencyNode represents a node in a dependency tree, containing information about the object, its child dependencies, execution time, and execution phase. Name is the identifier for the object. Children is a map of child nodes in the dependency tree. TotalTime records the total time taken to execute this object. Phase indicates the execution phase of the object.
type Graph ¶
type Graph struct {
// Nodes maps node identifiers to their corresponding Node instances, representing the set of nodes in the DAG.
Nodes map[string]*Node
}
Graph represents a directed acyclic graph (DAG) structure, where Nodes is a map of node identifiers to their corresponding Node objects.
func Build ¶
Build constructs a directed acyclic graph (DAG) from the provided dagObjects and their dependencies. It first adds all DAG items to the graph, ensuring no duplicates. Then, it checks for cycles in the dependency map and returns an error if any are found. Finally, it processes all dependency constraints to establish links between nodes in the graph. Returns the constructed Graph or an error if any issues are encountered during the process.
Parameters:
- dagObjects: Objects containing the DAG items to be added to the graph.
- deps: A map where keys are DAG object identifiers and values are slices of identifiers representing dependencies.
Returns:
- *Graph: The constructed DAG.
- error: An error if a duplicate DAG object is found, a cycle is detected, or a link cannot be established.
type Node ¶
type Node struct {
// Key represent a unique name of the node in a graph
Key string
// Prev represent all the Previous object Nodes for the current object
Prev []*Node
// Next represent all the Next object Nodes for the current object
Next []*Node
}
Node represents a node in a directed acyclic graph (DAG). Each node has a unique key and maintains references to its previous and next nodes in the graph.
Key: A unique identifier for the node. Prev: A slice of pointers to the previous nodes in the graph. Next: A slice of pointers to the next nodes in the graph.
func (*Node) Compare ¶
Compare checks whether the current Node is structurally equal to another Node. It compares the Key, the length of Prev and Next slices, and the Keys of all Nodes in Prev and Next. Returns true if all these properties match, false otherwise.
func (*Node) GetAllPrevKeys ¶
GetAllPrevKeys returns a sorted list of all unique keys of ancestor nodes for the current node. It traverses the graph recursively and ensures that each key appears only once, even if there are multiple paths to the same ancestor.
type Object ¶
type Object interface {
DagKey() string
GetDependencyKeys(objectNamesMap map[string]string, apiDepsMap map[string][]string, aliasMap map[string]string) []string
}
Object represents an object within a directed acyclic graph (DAG). It provides methods to retrieve a unique key for the object and to obtain the keys of its dependencies based on provided mappings.
DagKey returns a unique string key identifying the DAG object.
GetDependencyKeys returns a slice of dependency keys for the DAG object. It uses the provided objectNamesMap, apiDepsMap, and aliasMap to resolve dependencies:
- objectNamesMap: maps object names to their keys i.e. resolver name would be the key and the value
- apiDepsMap: maps object keys to their API dependencies.
- aliasMap: maps aliases to object keys.
type ObjectExecution ¶
type ObjectExecution struct {
Name string `json:"name" yaml:"name" doc:"The name of the object"`
ObjectType string `json:"objectType" yaml:"objectType" doc:"The type of the object"`
Position int `json:"position" yaml:"position" doc:"The position of the object in the execution order"`
TotalTime time.Duration `json:"totalTime" yaml:"totalTime" doc:"Total time taken to execute the object"`
Error error `json:"error,omitempty" yaml:"error,omitempty" doc:"Error encountered during object execution"`
Phase int `json:"phase,omitempty" yaml:"phase,omitempty" doc:"The phase in which the object was executed"`
WasExecuted bool `json:"wasExecuted,omitempty" yaml:"wasExecuted,omitempty" doc:"Indicates if the object was executed"`
Value map[string]any `json:"value,omitempty" yaml:"value,omitempty" doc:"The value or result of the object execution" required:"false"`
}
ObjectExecution represents the execution details of an object within a DAG. It contains metadata such as the object's name, type, execution position, total execution time, any error encountered, the phase of execution, whether it was executed, and the result value.
type Objects ¶
type Objects interface {
DagItems() []Object
}
Objects represents a collection of Object instances that can be retrieved as a slice. Implementations of this interface should provide the DagItems method to return all contained Object elements.
type RunnerResults ¶
type RunnerResults struct {
TotalTime time.Duration `json:"totalTime" yaml:"totalTime" doc:"Total time taken to execute all objects"`
ExecutionOrder []ObjectExecution `json:"executionOrder" yaml:"executionOrder" doc:"The order in which objects were executed"`
}
RunnerResults holds the results of executing a set of objects, including the total execution time and the order in which each object was executed.
func (*RunnerResults) BuildDependencyTree ¶
func (r *RunnerResults) BuildDependencyTree(phaseMap map[int][]ObjectExecution, childToParents map[string]ChildToParents) []DependencyNode
BuildDependencyTree constructs a dependency tree of execution objects based on the provided phase map and child-to-parents relationships. It initializes nodes for each execution in the runner results, links children to their respective parent nodes, and returns the root nodes corresponding to the top-level executions (phase 1). The resulting tree allows traversal of dependencies between executions.
Parameters:
- phaseMap: a map where the key is the phase number and the value is a slice of ObjectExecution representing executions in that phase.
- childToParents: a map where the key is the child's name and the value is a ChildToParents struct containing its parent names.
Returns:
- A slice of DependencyNode representing the root nodes of the constructed dependency tree.
func (*RunnerResults) GetPhaseMap ¶
func (r *RunnerResults) GetPhaseMap() map[int][]ObjectExecution
GetPhaseMap constructs and returns a map where the keys are phase identifiers (int) and the values are slices of ObjectExecution corresponding to each phase. It iterates over the ExecutionOrder field of RunnerResults, grouping ObjectExecution instances by their Phase value.
func (*RunnerResults) HasAnError ¶
func (r *RunnerResults) HasAnError() bool
HasAnError checks if any item in the ExecutionOrder has a non-nil Error. It returns true if at least one error is found, otherwise false.
func (*RunnerResults) ToAnalysis ¶
func (r *RunnerResults) ToAnalysis(sourceOfExecution string, timeConsumingThresholdMs int64) Analysis
ToAnalysis generates an Analysis report from the RunnerResults. It takes a sourceOfExecution string and a timeConsumingThresholdMs value (in milliseconds). The function categorizes execution items into all, failed, and time-consuming groups based on their execution time and error status. Returns an Analysis struct containing the categorized results and total execution time.