Rename annotation methods
Change AnnotateVertex and AnnotateEdge to VertexDebugInfo EdgeDebugInfo to avoid confusion between debug output and future graph annotations.
This commit is contained in:
parent
f37b2fafed
commit
7e66df3290
12
dag/graph.go
12
dag/graph.go
|
@ -343,13 +343,17 @@ func (g *Graph) SetDebugWriter(w io.Writer) {
|
|||
g.debug.Encode(newMarshalGraph("root", g))
|
||||
}
|
||||
|
||||
func (g *Graph) AnnotateVertex(v Vertex, info string) {
|
||||
va := newVertexAnnotation(v, info)
|
||||
// DebugVertexInfo encodes arbitrary information about a vertex in the graph
|
||||
// debug logs.
|
||||
func (g *Graph) DebugVertexInfo(v Vertex, info string) {
|
||||
va := newVertexDebugInfo(v, info)
|
||||
g.debug.Encode(va)
|
||||
}
|
||||
|
||||
func (g *Graph) AnnotateEdge(e Edge, info string) {
|
||||
ea := newEdgeAnnotation(e, info)
|
||||
// DebugEdgeInfo encodes arbitrary information about an edge in the graph debug
|
||||
// logs.
|
||||
func (g *Graph) DebugEdgeInfo(e Edge, info string) {
|
||||
ea := newEdgeDebugInfo(e, info)
|
||||
g.debug.Encode(ea)
|
||||
}
|
||||
|
||||
|
|
|
@ -426,6 +426,7 @@ type marshalOperation struct {
|
|||
Type string
|
||||
Begin *string `json:",omitempty"`
|
||||
End *string `json:",omitempty"`
|
||||
Info *string `json:".omitempty"`
|
||||
}
|
||||
|
||||
func newBool(b bool) *bool { return &b }
|
||||
|
@ -468,31 +469,31 @@ func decodeGraph(r io.Reader) (*marshalGraph, error) {
|
|||
return g, nil
|
||||
}
|
||||
|
||||
// *Annotation structs allow encoding arbitrary information about the graph in
|
||||
// *DebugInfo structs allow encoding arbitrary information about the graph in
|
||||
// the logs.
|
||||
type vertexAnnotation struct {
|
||||
type vertexDebugInfo struct {
|
||||
Type string
|
||||
Vertex *marshalVertex
|
||||
Info string
|
||||
}
|
||||
|
||||
func newVertexAnnotation(v Vertex, info string) *vertexAnnotation {
|
||||
return &vertexAnnotation{
|
||||
Type: "VertexAnnotation",
|
||||
func newVertexDebugInfo(v Vertex, info string) *vertexDebugInfo {
|
||||
return &vertexDebugInfo{
|
||||
Type: "VertexDebugInfo",
|
||||
Vertex: newMarshalVertex(v),
|
||||
Info: info,
|
||||
}
|
||||
}
|
||||
|
||||
type edgeAnnotation struct {
|
||||
type edgeDebugInfo struct {
|
||||
Type string
|
||||
Edge *marshalEdge
|
||||
Info string
|
||||
}
|
||||
|
||||
func newEdgeAnnotation(e Edge, info string) *edgeAnnotation {
|
||||
return &edgeAnnotation{
|
||||
Type: "EdgeAnnotation",
|
||||
func newEdgeDebugInfo(e Edge, info string) *edgeDebugInfo {
|
||||
return &edgeDebugInfo{
|
||||
Type: "EdgeDebugInfo",
|
||||
Edge: newMarshalEdge(e),
|
||||
Info: info,
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ func TestGraphJSON_basicRecord(t *testing.T) {
|
|||
}
|
||||
|
||||
// Verify that Vertex and Edge annotations appear in the debug output
|
||||
func TestGraphJSON_annotations(t *testing.T) {
|
||||
func TestGraphJSON_debugInfo(t *testing.T) {
|
||||
var g Graph
|
||||
var buf bytes.Buffer
|
||||
g.SetDebugWriter(&buf)
|
||||
|
@ -140,9 +140,9 @@ func TestGraphJSON_annotations(t *testing.T) {
|
|||
g.Add(3)
|
||||
g.Connect(BasicEdge(1, 2))
|
||||
|
||||
g.AnnotateVertex(2, "2")
|
||||
g.AnnotateVertex(3, "3")
|
||||
g.AnnotateEdge(BasicEdge(1, 2), "1|2")
|
||||
g.DebugVertexInfo(2, "2")
|
||||
g.DebugVertexInfo(3, "3")
|
||||
g.DebugEdgeInfo(BasicEdge(1, 2), "1|2")
|
||||
|
||||
dec := json.NewDecoder(bytes.NewReader(buf.Bytes()))
|
||||
|
||||
|
@ -156,8 +156,8 @@ func TestGraphJSON_annotations(t *testing.T) {
|
|||
}
|
||||
|
||||
switch d.Type {
|
||||
case "VertexAnnotation":
|
||||
va := &vertexAnnotation{}
|
||||
case "VertexDebugInfo":
|
||||
va := &vertexDebugInfo{}
|
||||
err := json.Unmarshal(d.JSON, va)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -177,8 +177,8 @@ func TestGraphJSON_annotations(t *testing.T) {
|
|||
default:
|
||||
t.Fatalf("unexpected annotation: %#v", va)
|
||||
}
|
||||
case "EdgeAnnotation":
|
||||
ea := &edgeAnnotation{}
|
||||
case "EdgeDebugInfo":
|
||||
ea := &edgeDebugInfo{}
|
||||
err := json.Unmarshal(d.JSON, ea)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -294,7 +294,7 @@ func (g *Graph) walk(walker GraphWalker) error {
|
|||
// then callback with the output.
|
||||
log.Printf("[DEBUG] vertex '%s.%s': evaluating", path, dag.VertexName(v))
|
||||
|
||||
g.AnnotateVertex(v, fmt.Sprintf("evaluating %T(%s)", v, path))
|
||||
g.DebugVertexInfo(v, fmt.Sprintf("evaluating %T(%s)", v, path))
|
||||
|
||||
tree = walker.EnterEvalTree(v, tree)
|
||||
output, err := Eval(tree, vertexCtx)
|
||||
|
@ -310,7 +310,7 @@ func (g *Graph) walk(walker GraphWalker) error {
|
|||
path,
|
||||
dag.VertexName(v))
|
||||
|
||||
g.AnnotateVertex(v, fmt.Sprintf("expanding %T(%s)", v, path))
|
||||
g.DebugVertexInfo(v, fmt.Sprintf("expanding %T(%s)", v, path))
|
||||
|
||||
g, err := ev.DynamicExpand(vertexCtx)
|
||||
if err != nil {
|
||||
|
@ -332,7 +332,7 @@ func (g *Graph) walk(walker GraphWalker) error {
|
|||
path,
|
||||
dag.VertexName(v))
|
||||
|
||||
g.AnnotateVertex(v, fmt.Sprintf("subgraph: %T(%s)", v, path))
|
||||
g.DebugVertexInfo(v, fmt.Sprintf("subgraph: %T(%s)", v, path))
|
||||
|
||||
if rerr = sn.Subgraph().(*Graph).walk(walker); rerr != nil {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue