diff --git a/canary/snapshot.go b/canary/snapshot.go new file mode 100644 index 00000000..3f6486d1 --- /dev/null +++ b/canary/snapshot.go @@ -0,0 +1,30 @@ +package canary + +import ( + "fmt" + "github.com/openziti/zrok/util" + "time" +) + +type Snapshot struct { + Operation string + Instance uint + Iteration uint64 + Started time.Time + Completed time.Time + Ok bool + Error error + Size uint64 +} + +func NewSnapshot(operation string, instance uint, iteration uint64) *Snapshot { + return &Snapshot{Operation: operation, Instance: instance, Iteration: iteration, Started: time.Now()} +} + +func (s *Snapshot) String() string { + if s.Ok { + return fmt.Sprintf("[%v, %d, %d] (ok) %v, %v", s.Operation, s.Instance, s.Iteration, s.Completed.Sub(s.Started), util.BytesToSize(int64(s.Size))) + } else { + return fmt.Sprintf("[%v, %d, %d] (err) %v, %v, (%v)", s.Operation, s.Instance, s.Iteration, s.Completed.Sub(s.Started), util.BytesToSize(int64(s.Size)), s.Error) + } +} diff --git a/canary/metrics.go b/canary/snapshotCollector.go similarity index 72% rename from canary/metrics.go rename to canary/snapshotCollector.go index b63fa197..8fe7071e 100644 --- a/canary/metrics.go +++ b/canary/snapshotCollector.go @@ -4,36 +4,11 @@ import ( "context" "fmt" influxdb2 "github.com/influxdata/influxdb-client-go/v2" - "github.com/openziti/zrok/util" "github.com/sirupsen/logrus" "slices" "sort" - "time" ) -type Snapshot struct { - Operation string - Instance uint - Iteration uint64 - Started time.Time - Completed time.Time - Ok bool - Error error - Size uint64 -} - -func NewSnapshot(operation string, instance uint, iteration uint64) *Snapshot { - return &Snapshot{Operation: operation, Instance: instance, Iteration: iteration, Started: time.Now()} -} - -func (s *Snapshot) String() string { - if s.Ok { - return fmt.Sprintf("[%v, %d, %d] (ok) %v, %v", s.Operation, s.Instance, s.Iteration, s.Completed.Sub(s.Started), util.BytesToSize(int64(s.Size))) - } else { - return fmt.Sprintf("[%v, %d, %d] (err) %v, %v, (%v)", s.Operation, s.Instance, s.Iteration, s.Completed.Sub(s.Started), util.BytesToSize(int64(s.Size)), s.Error) - } -} - type SnapshotCollector struct { InputQueue chan *Snapshot Closed chan struct{}