mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
Improve error messages during report validation
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -40,6 +40,7 @@ docker/probe
|
|||||||
experimental/bridge/bridge
|
experimental/bridge/bridge
|
||||||
experimental/demoprobe/demoprobe
|
experimental/demoprobe/demoprobe
|
||||||
experimental/fixprobe/fixprobe
|
experimental/fixprobe/fixprobe
|
||||||
|
experimental/fixprobe/*.json
|
||||||
experimental/genreport/genreport
|
experimental/genreport/genreport
|
||||||
experimental/graphviz/graphviz
|
experimental/graphviz/graphviz
|
||||||
experimental/oneshot/oneshot
|
experimental/oneshot/oneshot
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const localUnknown = "localUnknown"
|
const localUnknown = "localUnknown"
|
||||||
@@ -274,43 +275,54 @@ func (r ByID) Less(i, j int) bool { return r[i].ID < r[j].ID }
|
|||||||
|
|
||||||
// Validate checks the topology for various inconsistencies.
|
// Validate checks the topology for various inconsistencies.
|
||||||
func (t Topology) Validate() error {
|
func (t Topology) Validate() error {
|
||||||
// Check all edge metadata keys must have the appropriate entries in adjacencies & node metadata
|
// Check all edge metadata keys must have the appropriate entries in
|
||||||
|
// adjacencies & node metadata.
|
||||||
|
var errs []string
|
||||||
for edgeID := range t.EdgeMetadatas {
|
for edgeID := range t.EdgeMetadatas {
|
||||||
srcNodeID, dstNodeID, ok := ParseEdgeID(edgeID)
|
srcNodeID, dstNodeID, ok := ParseEdgeID(edgeID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Invalid edge id: %s", edgeID)
|
errs = append(errs, fmt.Sprintf("invalid edge ID %q", edgeID))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if _, ok := t.NodeMetadatas[srcNodeID]; !ok {
|
if _, ok := t.NodeMetadatas[srcNodeID]; !ok {
|
||||||
return fmt.Errorf("Source node missing for edge id: %s", edgeID)
|
errs = append(errs, fmt.Sprintf("node metadata missing for source node ID %q (from edge %q)", srcNodeID, edgeID))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
dstNodeIDs, ok := t.Adjacency[MakeAdjacencyID(srcNodeID)]
|
||||||
adjs, ok := t.Adjacency[MakeAdjacencyID(srcNodeID)]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Adjancey entries for missing for node id: %s (from edge %s)", srcNodeID, edgeID)
|
errs = append(errs, fmt.Sprintf("adjacency entries missing for source node ID %q (from edge %q)", srcNodeID, edgeID))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if !adjs.Contains(dstNodeID) {
|
if !dstNodeIDs.Contains(dstNodeID) {
|
||||||
return fmt.Errorf("Adjancey entry missing for edge id: %s", edgeID)
|
errs = append(errs, fmt.Sprintf("adjacency destination missing for destination node ID %q (from edge %q)", dstNodeID, edgeID))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check all adjancency keys has entries in NodeMetadata
|
// Check all adjancency keys has entries in NodeMetadata.
|
||||||
for adjID := range t.Adjacency {
|
for adjacencyID := range t.Adjacency {
|
||||||
nodeID, ok := ParseAdjacencyID(adjID)
|
nodeID, ok := ParseAdjacencyID(adjacencyID)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Invalid adjacency id: %s", adjID)
|
errs = append(errs, fmt.Sprintf("invalid adjacency ID %q", adjacencyID))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := t.NodeMetadatas[nodeID]; !ok {
|
if _, ok := t.NodeMetadatas[nodeID]; !ok {
|
||||||
return fmt.Errorf("Source node missing for adjancency id: %s", adjID)
|
errs = append(errs, fmt.Sprintf("node metadata missing for source node %q (from adjacency %q)", nodeID, adjacencyID))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check all node metadata keys are parse-able (ie, contain a scope)
|
// Check all node metadata keys are parse-able (i.e. contain a scope)
|
||||||
for nodeID := range t.NodeMetadatas {
|
for nodeID := range t.NodeMetadatas {
|
||||||
if _, _, ok := ParseNodeID(nodeID); !ok {
|
if _, _, ok := ParseNodeID(nodeID); !ok {
|
||||||
return fmt.Errorf("Invalid node id: %s", nodeID)
|
errs = append(errs, fmt.Sprintf("invalid node ID %q", nodeID))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(errs) > 0 {
|
||||||
|
return fmt.Errorf(strings.Join(errs, "; "))
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func (c *realCollector) loop(batchTime time.Duration) {
|
|||||||
|
|
||||||
case r := <-c.in:
|
case r := <-c.in:
|
||||||
if err := r.Validate(); err != nil {
|
if err := r.Validate(); err != nil {
|
||||||
log.Printf("Received invalid report from: %v", err)
|
log.Printf("Received invalid report: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
current.Merge(r)
|
current.Merge(r)
|
||||||
|
|||||||
Reference in New Issue
Block a user