[Robustness] Fswalker should ignore host name
Fix fswalker to ignore hostname to allow reporting
on walks done across different hosts. Also prevent
Before and After walk data from printing to reduce log size.
@@ -45,23 +45,43 @@ func NewWalkCompare() *WalkCompare {
// Gather meets the checker.Comparer interface. It performs a fswalker Walk
// and returns the resulting Walk as a protobuf Marshaled buffer.
func (chk *WalkCompare) Gather(ctx context.Context, path string) ([]byte, error) {
- walkData, err := walker.WalkPathHash(ctx, path)
+ walkData, err := performWalk(ctx, path)
if err != nil {
return nil, errors.Wrap(err, "walk with hashing error during gather phase")
}
- err = rerootWalkDataPaths(walkData, path)
- if err != nil {
- return nil, errors.Wrap(err, "reroot walk paths error during gather phase")
- }
-
// Store the walk data along with the snapshot ID
b, err := proto.Marshal(walkData)
+
+ return b, errors.Wrap(err, "walk data proto marshal error")
+}
+
+func performWalk(ctx context.Context, path string) (*fspb.Walk, error) {
+ walkData, err := walker.WalkPathHash(ctx, path)
if err != nil {
- return nil, errors.Wrap(err, "walk data proto marshal error")
+ return nil, errors.Wrap(err, "walk with hashing error during gather phase")
}
- return b, nil
+ err = processWalk(walkData, path)
+
+ return walkData, errors.Wrap(err, "error during gather phase")
+}
+
+func processWalk(walk *fspb.Walk, path string) error {
+ // Hostname is cleared to allow reporting on walks done across
+ // different hosts.
+ clearHostname(walk)
+
+ // Walk paths are rerooted to be relative to the root directory
+ // so child entries of /source/rootDir/... won't be different than
+ // child entries of /target/rootDir/...
+ err := rerootWalkDataPaths(walk, path)
+
+ return errors.Wrap(err, "reroot walk paths error")
+}
+
+func clearHostname(walk *fspb.Walk) {
+ walk.Hostname = ""
}
// Compare meets the checker.Comparer interface. It performs a fswalker Walk
@@ -77,14 +97,11 @@ func (chk *WalkCompare) Compare(ctx context.Context, path string, data []byte, r
return errors.Wrap(err, "walk data unmarshal error")
}
- afterWalk, err := walker.WalkPathHash(ctx, path)
- if err != nil {
- return errors.Wrap(err, "walk with hashing error during compare phase")
- }
+ clearHostname(beforeWalk)
- err = rerootWalkDataPaths(afterWalk, path)
+ afterWalk, err := performWalk(ctx, path)
if err != nil {
- return errors.Wrap(err, "reroot walk paths error during compare phase")
+ return errors.Wrap(err, "walk with hashing error during compare phase")
}
report, err := reporter.Report(ctx, &fspb.ReportConfig{}, beforeWalk, afterWalk)
@@ -98,6 +115,11 @@ func (chk *WalkCompare) Compare(ctx context.Context, path string, data []byte, r
if err != nil && reportOut != nil {
printReportSummary(report, reportOut)
+ // Don't spew these fields. They can be enormous and
+ // are probably redundant
+ report.WalkBefore = nil
+ report.WalkAfter = nil
+
b, marshalErr := json.MarshalIndent(report, "", " ")
if marshalErr != nil {
_, reportErr := reportOut.Write([]byte(marshalErr.Error()))
@@ -115,7 +137,7 @@ func (chk *WalkCompare) Compare(ctx context.Context, path string, data []byte, r
return errors.Wrap(err, "validation error")
}
- return nil
+ return err
}
func printReportSummary(report *fswalker.Report, reportOut io.Writer) {
