Skip to content

Commit

Permalink
Remove the dot graphs from the debug log,
Browse files Browse the repository at this point in the history
and record the walk visits in the debug information.
  • Loading branch information
jbardin authored and fatmcgav committed Feb 27, 2017
1 parent a0c3741 commit b79e7e4
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 64 deletions.
34 changes: 0 additions & 34 deletions terraform/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,40 +224,6 @@ func (d *debugInfo) flush() {
}
}

// WriteGraph takes a DebugGraph and writes both the DebugGraph as a dot file
// in the debug archive, and extracts any logs that the DebugGraph collected
// and writes them to a log file in the archive.
func (d *debugInfo) WriteGraph(name string, g *Graph) error {
if d == nil || g == nil {
return nil
}
d.Lock()
defer d.Unlock()

// If we crash, the file won't be correctly closed out, but we can rebuild
// the archive if we have to as long as every file has been flushed and
// sync'ed.
defer d.flush()

dotPath := fmt.Sprintf("%s/graphs/%d-%s-%s.dot", d.name, d.step, d.phase, name)
d.step++

dotBytes := g.Dot(nil)
hdr := &tar.Header{
Name: dotPath,
Mode: 0644,
Size: int64(len(dotBytes)),
}

err := d.tar.WriteHeader(hdr)
if err != nil {
return err
}

_, err = d.tar.Write(dotBytes)
return err
}

// WriteFile writes data as a single file to the debug arhive.
func (d *debugInfo) WriteFile(name string, data []byte) error {
if d == nil {
Expand Down
24 changes: 3 additions & 21 deletions terraform/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestDebugInfo_nil(t *testing.T) {
var d *debugInfo

d.SetPhase("none")
d.WriteGraph("", nil)
d.WriteFile("none", nil)
d.Close()
}
Expand Down Expand Up @@ -120,9 +119,7 @@ func TestDebug_plan(t *testing.T) {
}
tr := tar.NewReader(gz)

files := 0
graphs := 0
json := 0
graphLogs := 0
for {
hdr, err := tr.Next()
if err == io.EOF {
Expand All @@ -134,28 +131,13 @@ func TestDebug_plan(t *testing.T) {

// record any file that contains data
if hdr.Size > 0 {
files++

// and any dot graph with data
if strings.HasSuffix(hdr.Name, ".dot") {
graphs++
}

if strings.HasSuffix(hdr.Name, "graph.json") {
json++
graphLogs++
}
}
}

if files == 0 {
t.Fatal("no files with data found")
}

if graphs == 0 {
t.Fatal("no no-empty graphs found")
}

if json == 0 {
if graphLogs == 0 {
t.Fatal("no json graphs")
}
}
Expand Down
1 change: 1 addition & 0 deletions terraform/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func (g *Graph) walk(walker GraphWalker) error {
var walkFn dag.WalkFunc
walkFn = func(v dag.Vertex) (rerr error) {
log.Printf("[DEBUG] vertex '%s.%s': walking", path, dag.VertexName(v))
g.DebugVisitInfo(v, g.debugName)

// If we have a panic wrap GraphWalker and a panic occurs, recover
// and call that. We ensure the return value is an error, however,
Expand Down
9 changes: 0 additions & 9 deletions terraform/graph_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,10 @@ func (b *BasicGraphBuilder) Build(path []string) (*Graph, error) {
}
debugOp.End(errMsg)

// always log the graph state to see what transformations may have happened
debugName := "build-" + stepName
if b.Name != "" {
debugName = b.Name + "-" + debugName
}

log.Printf(
"[TRACE] Graph after step %T:\n\n%s",
step, g.StringWithNodeTypes())

// TODO: replace entirely with the json logs
dbug.WriteGraph(debugName, g)

if err != nil {
return g, err
}
Expand Down

0 comments on commit b79e7e4

Please sign in to comment.