Skip to content

Commit

Permalink
Merge pull request #78 from Clever/add-dynamo-leakybucket
Browse files Browse the repository at this point in the history
Integrate dynamodb leakybucket
  • Loading branch information
Sayan- authored Mar 31, 2020
2 parents 15982b2 + afde6c2 commit a053abe
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 66 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# v0.7.1: Add AWS DynamoDB as a backend

# v0.7.0: Add global limit key
- Allows global rate limiting irrespective of request content

Expand Down
155 changes: 140 additions & 15 deletions Gopkg.lock

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

29 changes: 5 additions & 24 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/Clever/leakybucket"
revision = "e71c0c5ef35405c601ade74f6c02b71aa68b8d0d"
version = "1.0.0"

[[constraint]]
name = "github.com/pborman/uuid"
Expand All @@ -42,3 +19,7 @@
[[constraint]]
name = "gopkg.in/tylerb/graceful.v1"
version = "1.2.15"

[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.29.32"
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ proxy:
listen: :6634 # bind to host:port. default: height of the Great Sphinx of Giza
storage:
type: memory # can be {redis,memory}
type: redis # must be one of {redis, dynamodb, memory}
host: localhost # redis hostname. required for redis
port: 6379 # redis port. required for redis
table: table # table name. required for dynamodb
region: us-west-1 # table region. required for dynamodb
limits:
test-limit:
Expand Down
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ func ValidateConfig(config Config) error {
switch strings.ToLower(store) {
default:
return fmt.Errorf("storage type needs to be memory or redis")
case "dynamodb":
if _, ok := config.Storage["region"]; !ok {
return fmt.Errorf("storage region must be set for DynamoDB")
}
if _, ok := config.Storage["table"]; !ok {
return fmt.Errorf("storage table must be set for DynamoDB")
}
case "redis":
if _, ok := config.Storage["host"]; !ok {
return fmt.Errorf("storage host must be set for Redis")
Expand Down
31 changes: 28 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ limits:
t.Errorf("Expected Storage error. Got: %s", err.Error())
}

configBuf := baseBuf
// invalid redis configs (requires both host and port)
configBuf := bytes.NewBuffer(baseBuf.Bytes())
configBuf.WriteString(`
storage:
type: redis
Expand All @@ -191,14 +192,38 @@ storage:
t.Errorf("Expected redis Storage host error. Got: %s", err.Error())
}

configBuf = baseBuf
configBuf = bytes.NewBuffer(baseBuf.Bytes())
configBuf.WriteString(`
storage:
type: redis
host: localhost
`)
_, err = LoadAndValidateYaml(configBuf.Bytes())
if err == nil || !strings.Contains(err.Error(), "port") {
t.Errorf("Expected redis Storage host error. Got: %s", err.Error())
t.Errorf("Expected redis Storage post error. Got: %s", err.Error())
}

// invalid dynamodb configs (requires table and region)
configBuf = bytes.NewBuffer(baseBuf.Bytes())
configBuf.WriteString(`
storage:
type: dynamodb
region: bar
`)
_, err = LoadAndValidateYaml(configBuf.Bytes())
if err == nil || !strings.Contains(err.Error(), "table") {
t.Errorf("Expected dynamodb Storage table error. Got: %s", err.Error())
}

configBuf = bytes.NewBuffer(baseBuf.Bytes())
configBuf.WriteString(`
storage:
type: dynamodb
table: foo
`)
_, err = LoadAndValidateYaml(configBuf.Bytes())
if err == nil || !strings.Contains(err.Error(), "region") {
t.Errorf("Expected dynamodb Storage region error. Got: %s", err.Error())
}

}
2 changes: 1 addition & 1 deletion deb/sphinx/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: sphinx
Version: 0.7.0
Version: 0.7.1
Section: base
Priority: optional
Architecture: amd64
Expand Down
8 changes: 5 additions & 3 deletions deb/sphinx/etc/sphinx/sphinx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ proxy:
listen: :6634 # height of the Great Sphinx of Giza

storage:
type: redis # can be {redis, memory}
host: localhost # not required for memory
port: 6379 # not required for memory
type: redis # must be one of {redis, dynamodb, memory}
host: localhost # redis hostname. required for redis
port: 6379 # redis port. required for redis
table: table # table name. required for dynamodb
region: us-west-1 # table region. required for dynamodb

limits:
sample-limit:
Expand Down
8 changes: 5 additions & 3 deletions example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ proxy:
allow-on-error: Yes # become passive proxy if error detected? (optional, default=No)

storage:
type: memory # can be {redis,memory}
host: localhost # redis hostname. not required for memory
port: 6379 # redis port. not required for memory
type: memory # must be one of {redis, dynamodb, memory}
host: localhost # redis hostname. required for redis
port: 6379 # redis port. required for redis
table: table # table name. required for dynamodb
region: us-west-1 # table region. required for dynamodb

health-check:
enabled: true
Expand Down
Loading

0 comments on commit a053abe

Please sign in to comment.