mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 18:09:59 +00:00
Add a timestamp on each report saying when it was generated
Not currently used in the code, but useful when troubleshooting.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/armon/go-metrics"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/weaveworks/common/mtime"
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/weaveworks/scope/report"
|
||||
@@ -185,6 +186,7 @@ func (p *Probe) report() report.Report {
|
||||
}
|
||||
|
||||
result := report.MakeReport()
|
||||
result.TS = mtime.Now()
|
||||
for i := 0; i < cap(reports); i++ {
|
||||
result.UnsafeMerge(<-reports)
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ func TestProbe(t *testing.T) {
|
||||
node := report.MakeNodeWith("a", map[string]string{"b": "c"})
|
||||
|
||||
want.Endpoint.AddNode(node)
|
||||
want.TS = now
|
||||
|
||||
pub := mockPublisher{make(chan report.Report, 10)}
|
||||
|
||||
|
||||
@@ -85,6 +85,9 @@ var topologyNames = []string{
|
||||
// stored by apps. It's composed of multiple topologies, each representing
|
||||
// a different (related, but not equivalent) view of the network.
|
||||
type Report struct {
|
||||
// TS is the time this report was generated
|
||||
TS time.Time
|
||||
|
||||
// Endpoint nodes are individual (address, port) tuples on each host.
|
||||
// They come from inspecting active connections and can (theoretically)
|
||||
// be traced back to a process. Edges are present.
|
||||
@@ -321,6 +324,7 @@ func MakeReport() Report {
|
||||
// Copy returns a value copy of the report.
|
||||
func (r Report) Copy() Report {
|
||||
newReport := Report{
|
||||
TS: r.TS,
|
||||
DNS: r.DNS.Copy(),
|
||||
Sampling: r.Sampling,
|
||||
Window: r.Window,
|
||||
@@ -336,6 +340,10 @@ func (r Report) Copy() Report {
|
||||
|
||||
// UnsafeMerge merges another Report into the receiver. The original is modified.
|
||||
func (r *Report) UnsafeMerge(other Report) {
|
||||
// Merged report has the earliest non-zero timestamp
|
||||
if !other.TS.IsZero() && (r.TS.IsZero() || other.TS.Before(r.TS)) {
|
||||
r.TS = other.TS
|
||||
}
|
||||
r.DNS = r.DNS.Merge(other.DNS)
|
||||
r.Sampling = r.Sampling.Merge(other.Sampling)
|
||||
r.Window = r.Window + other.Window
|
||||
|
||||
Reference in New Issue
Block a user