Skip to content

Commit

Permalink
Merge pull request #2471 from lizardruss/rate-limit-lib
Browse files Browse the repository at this point in the history
fix: remove juju/ratelimit due to license concerns
  • Loading branch information
FabianKramm authored Dec 17, 2022
2 parents e69cfbe + 229782c commit 7604c58
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 724 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/docker/go-connections v0.4.0
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/evanphx/json-patch/v5 v5.1.0
github.com/fujiwara/shapeio v1.0.0
github.com/gertd/go-pluralize v0.2.0
github.com/ghodss/yaml v1.0.0
github.com/gliderlabs/ssh v0.3.5
Expand All @@ -26,7 +27,6 @@ require (
github.com/jessevdk/go-flags v1.4.0
github.com/joho/godotenv v1.3.0
github.com/json-iterator/go v1.1.12
github.com/juju/ratelimit v1.0.1
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213
github.com/loft-sh/loft-util v0.0.9-alpha
github.com/loft-sh/notify v0.0.0-20210827094439-0720dcc7feee
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960 h1:aRd8M7HJVZOqn/vhOzrGcQH0lNAMkqMn+pXUYkatmcA=
github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960/go.mod h1:9HQzr9D/0PGwMEbC3d5AB7oi67+h4TsQqItC1GVYG58=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
Expand Down Expand Up @@ -442,6 +443,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/fujiwara/shapeio v1.0.0 h1:xG5D9oNqCSUUbryZ/jQV3cqe1v2suEjwPIcEg1gKM8M=
github.com/fujiwara/shapeio v1.0.0/go.mod h1:LmEmu6L/8jetyj1oewewFb7bZCNRwE7wLCUNzDLaLVA=
github.com/fullstorydev/grpcurl v1.6.0/go.mod h1:ZQ+ayqbKMJNhzLmbpCiurTVlaK2M/3nqZCxaQ2Ze/sM=
github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASxc7x3E=
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
Expand Down Expand Up @@ -833,7 +836,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY=
github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julz/importas v0.0.0-20210419104244-841f0c0fe66d/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0=
Expand Down Expand Up @@ -1737,6 +1739,7 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
18 changes: 11 additions & 7 deletions pkg/devspace/sync/downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package sync
import (
"context"
"fmt"
"github.com/loft-sh/devspace/helper/server/ignoreparser"
"github.com/loft-sh/devspace/pkg/util/fsutil"
"io"
"os"
"path"
"path/filepath"
"strings"
"time"

"github.com/juju/ratelimit"
"github.com/pkg/errors"

"github.com/loft-sh/devspace/helper/remote"
"github.com/loft-sh/devspace/helper/server/ignoreparser"
"github.com/loft-sh/devspace/helper/util"
"github.com/loft-sh/devspace/pkg/util/fsutil"

"github.com/fujiwara/shapeio"
"github.com/pkg/errors"
)

type downstream struct {
Expand All @@ -42,10 +42,14 @@ func newDownstream(reader io.ReadCloser, writer io.WriteCloser, sync *Sync) (*do

// Apply limits if specified
if sync.Options.DownstreamLimit > 0 {
clientReader = ratelimit.Reader(reader, ratelimit.NewBucketWithRate(float64(sync.Options.DownstreamLimit), sync.Options.DownstreamLimit))
limitedReader := shapeio.NewReader(reader)
limitedReader.SetRateLimit(float64(sync.Options.DownstreamLimit))
clientReader = limitedReader
}
if sync.Options.UpstreamLimit > 0 {
clientWriter = ratelimit.Writer(writer, ratelimit.NewBucketWithRate(float64(sync.Options.UpstreamLimit), sync.Options.UpstreamLimit))
limitedWriter := shapeio.NewWriter(writer)
limitedWriter.SetRateLimit(float64(sync.Options.UpstreamLimit))
clientWriter = limitedWriter
}

// Create client connection
Expand Down
23 changes: 14 additions & 9 deletions pkg/devspace/sync/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@ import (
"context"
"fmt"
"io"
"mvdan.cc/sh/v3/expand"
"os"
"path"
"path/filepath"
"strings"
"sync"
"time"

"github.com/loft-sh/devspace/pkg/devspace/build/builder/restart"
"github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
"github.com/loft-sh/devspace/pkg/util/fsutil"

"github.com/bmatcuk/doublestar"
"github.com/juju/ratelimit"
"github.com/loft-sh/devspace/helper/remote"
"github.com/loft-sh/devspace/helper/server/ignoreparser"
"github.com/loft-sh/devspace/helper/util"
"github.com/loft-sh/devspace/helper/util/crc32"
"github.com/loft-sh/devspace/pkg/devspace/build/builder/restart"
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
"github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
"github.com/loft-sh/devspace/pkg/util/fsutil"

"github.com/loft-sh/loft-util/pkg/command"
"github.com/loft-sh/notify"

"github.com/bmatcuk/doublestar"
"github.com/fujiwara/shapeio"
"github.com/pkg/errors"
"mvdan.cc/sh/v3/expand"
)

var (
Expand Down Expand Up @@ -72,10 +73,14 @@ func newUpstream(reader io.ReadCloser, writer io.WriteCloser, sync *Sync) (*upst

// Apply limits if specified
if sync.Options.DownstreamLimit > 0 {
clientReader = ratelimit.Reader(reader, ratelimit.NewBucketWithRate(float64(sync.Options.DownstreamLimit), sync.Options.DownstreamLimit))
limitedReader := shapeio.NewReader(reader)
limitedReader.SetRateLimit(float64(sync.Options.DownstreamLimit))
clientReader = limitedReader
}
if sync.Options.UpstreamLimit > 0 {
clientWriter = ratelimit.Writer(writer, ratelimit.NewBucketWithRate(float64(sync.Options.UpstreamLimit), sync.Options.UpstreamLimit))
limitedWriter := shapeio.NewWriter(writer)
limitedWriter.SetRateLimit(float64(sync.Options.UpstreamLimit))
clientWriter = limitedWriter
}

// Create client
Expand Down
24 changes: 24 additions & 0 deletions vendor/github.com/fujiwara/shapeio/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/fujiwara/shapeio/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions vendor/github.com/fujiwara/shapeio/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions vendor/github.com/fujiwara/shapeio/shapeio.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7604c58

Please sign in to comment.