merger.go 654 B

1234567891011121314151617181920212223242526272829303132
  1. package app
  2. import (
  3. "fmt"
  4. "github.com/spaolacci/murmur3"
  5. "github.com/weaveworks/scope/report"
  6. )
  7. // Merger is the type for a thing that can merge reports.
  8. type Merger interface {
  9. Merge([]report.Report) report.Report
  10. }
  11. type fastMerger struct{}
  12. // NewFastMerger makes a Merger which merges together reports, mutating the one we are building up
  13. func NewFastMerger() Merger {
  14. return fastMerger{}
  15. }
  16. func (fastMerger) Merge(reports []report.Report) report.Report {
  17. rpt := report.MakeReport()
  18. id := murmur3.New64()
  19. for _, r := range reports {
  20. rpt.UnsafeMerge(r)
  21. id.Write([]byte(r.ID))
  22. }
  23. rpt.ID = fmt.Sprintf("%x", id.Sum64())
  24. return rpt
  25. }