summaryrefslogtreecommitdiff
path: root/vendor/github.com/hpcloud/tail/ratelimiter
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-02-06 09:07:51 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-09 15:27:52 +0000
commitfa9658cbfaa94fd5d0425041404e498c01db1aa3 (patch)
tree3cacae5b613692387780209a5d41b10c2edc0940 /vendor/github.com/hpcloud/tail/ratelimiter
parent75914199f331a10eb7ed44de68c738515bdd5b2d (diff)
downloadpodman-fa9658cbfaa94fd5d0425041404e498c01db1aa3.tar.gz
podman-fa9658cbfaa94fd5d0425041404e498c01db1aa3.tar.bz2
podman-fa9658cbfaa94fd5d0425041404e498c01db1aa3.zip
podman logs: fix tailing
Fix issues with tailing of container logs as described in issue #16. Also add in the ability to use a duration or known time stamp formats for the --since flag. Signed-off-by: baude <bbaude@redhat.com> Closes: #317 Approved by: mheon
Diffstat (limited to 'vendor/github.com/hpcloud/tail/ratelimiter')
-rw-r--r--vendor/github.com/hpcloud/tail/ratelimiter/leakybucket.go97
-rw-r--r--vendor/github.com/hpcloud/tail/ratelimiter/memory.go58
-rw-r--r--vendor/github.com/hpcloud/tail/ratelimiter/storage.go6
3 files changed, 0 insertions, 161 deletions
diff --git a/vendor/github.com/hpcloud/tail/ratelimiter/leakybucket.go b/vendor/github.com/hpcloud/tail/ratelimiter/leakybucket.go
deleted file mode 100644
index 358b69e7f..000000000
--- a/vendor/github.com/hpcloud/tail/ratelimiter/leakybucket.go
+++ /dev/null
@@ -1,97 +0,0 @@
-// Package ratelimiter implements the Leaky Bucket ratelimiting algorithm with memcached and in-memory backends.
-package ratelimiter
-
-import (
- "time"
-)
-
-type LeakyBucket struct {
- Size uint16
- Fill float64
- LeakInterval time.Duration // time.Duration for 1 unit of size to leak
- Lastupdate time.Time
- Now func() time.Time
-}
-
-func NewLeakyBucket(size uint16, leakInterval time.Duration) *LeakyBucket {
- bucket := LeakyBucket{
- Size: size,
- Fill: 0,
- LeakInterval: leakInterval,
- Now: time.Now,
- Lastupdate: time.Now(),
- }
-
- return &bucket
-}
-
-func (b *LeakyBucket) updateFill() {
- now := b.Now()
- if b.Fill > 0 {
- elapsed := now.Sub(b.Lastupdate)
-
- b.Fill -= float64(elapsed) / float64(b.LeakInterval)
- if b.Fill < 0 {
- b.Fill = 0
- }
- }
- b.Lastupdate = now
-}
-
-func (b *LeakyBucket) Pour(amount uint16) bool {
- b.updateFill()
-
- var newfill float64 = b.Fill + float64(amount)
-
- if newfill > float64(b.Size) {
- return false
- }
-
- b.Fill = newfill
-
- return true
-}
-
-// The time at which this bucket will be completely drained
-func (b *LeakyBucket) DrainedAt() time.Time {
- return b.Lastupdate.Add(time.Duration(b.Fill * float64(b.LeakInterval)))
-}
-
-// The duration until this bucket is completely drained
-func (b *LeakyBucket) TimeToDrain() time.Duration {
- return b.DrainedAt().Sub(b.Now())
-}
-
-func (b *LeakyBucket) TimeSinceLastUpdate() time.Duration {
- return b.Now().Sub(b.Lastupdate)
-}
-
-type LeakyBucketSer struct {
- Size uint16
- Fill float64
- LeakInterval time.Duration // time.Duration for 1 unit of size to leak
- Lastupdate time.Time
-}
-
-func (b *LeakyBucket) Serialise() *LeakyBucketSer {
- bucket := LeakyBucketSer{
- Size: b.Size,
- Fill: b.Fill,
- LeakInterval: b.LeakInterval,
- Lastupdate: b.Lastupdate,
- }
-
- return &bucket
-}
-
-func (b *LeakyBucketSer) DeSerialise() *LeakyBucket {
- bucket := LeakyBucket{
- Size: b.Size,
- Fill: b.Fill,
- LeakInterval: b.LeakInterval,
- Lastupdate: b.Lastupdate,
- Now: time.Now,
- }
-
- return &bucket
-}
diff --git a/vendor/github.com/hpcloud/tail/ratelimiter/memory.go b/vendor/github.com/hpcloud/tail/ratelimiter/memory.go
deleted file mode 100644
index 8f6a5784a..000000000
--- a/vendor/github.com/hpcloud/tail/ratelimiter/memory.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package ratelimiter
-
-import (
- "errors"
- "time"
-)
-
-const GC_SIZE int = 100
-
-type Memory struct {
- store map[string]LeakyBucket
- lastGCCollected time.Time
-}
-
-func NewMemory() *Memory {
- m := new(Memory)
- m.store = make(map[string]LeakyBucket)
- m.lastGCCollected = time.Now()
- return m
-}
-
-func (m *Memory) GetBucketFor(key string) (*LeakyBucket, error) {
-
- bucket, ok := m.store[key]
- if !ok {
- return nil, errors.New("miss")
- }
-
- return &bucket, nil
-}
-
-func (m *Memory) SetBucketFor(key string, bucket LeakyBucket) error {
-
- if len(m.store) > GC_SIZE {
- m.GarbageCollect()
- }
-
- m.store[key] = bucket
-
- return nil
-}
-
-func (m *Memory) GarbageCollect() {
- now := time.Now()
-
- // rate limit GC to once per minute
- if now.Add(60*time.Second).Unix() > m.lastGCCollected.Unix() {
-
- for key, bucket := range m.store {
- // if the bucket is drained, then GC
- if bucket.DrainedAt().Unix() > now.Unix() {
- delete(m.store, key)
- }
- }
-
- m.lastGCCollected = now
- }
-}
diff --git a/vendor/github.com/hpcloud/tail/ratelimiter/storage.go b/vendor/github.com/hpcloud/tail/ratelimiter/storage.go
deleted file mode 100644
index 89b2fe882..000000000
--- a/vendor/github.com/hpcloud/tail/ratelimiter/storage.go
+++ /dev/null
@@ -1,6 +0,0 @@
-package ratelimiter
-
-type Storage interface {
- GetBucketFor(string) (*LeakyBucket, error)
- SetBucketFor(string, LeakyBucket) error
-}