Skip to content

Commit

Permalink
Switch Database from Postgres to Cassandra (#108)
Browse files Browse the repository at this point in the history
* integrate ycql driver

* update doc line

* fix metrics

* bumped codex-db to v0.2.0

* fix yaml config file

* ran go mod tidy
  • Loading branch information
kcajmagic authored Oct 2, 2019
1 parent a391499 commit 54ed289
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 69 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.12

require (
github.com/InVisionApp/go-health v2.1.0+incompatible
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 // indirect
github.com/c9s/goprocinfo v0.0.0-20190309065803-0b2ad9ac246b // indirect
github.com/go-kit/kit v0.8.0
github.com/goph/emperror v0.17.2
Expand All @@ -13,7 +14,7 @@ require (
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.3.0
github.com/xmidt-org/bascule v0.3.1
github.com/xmidt-org/codex-db v0.1.2
github.com/xmidt-org/codex-db v0.2.0
github.com/xmidt-org/voynicrypto v0.1.1
github.com/xmidt-org/webpa-common v1.3.0
github.com/xmidt-org/wrp-go v1.2.0
Expand Down
21 changes: 20 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bugsnag/bugsnag-go v1.4.0/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/bugsnag/panicwrap v1.2.0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
Expand Down Expand Up @@ -74,6 +77,8 @@ github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
Expand All @@ -93,6 +98,8 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
Expand Down Expand Up @@ -206,8 +213,15 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
github.com/xmidt-org/bascule v0.3.1 h1:I6qUJE6RHsfGEnwHQdbF47nFBcqOUfNqzhDTbuGj42o=
github.com/xmidt-org/bascule v0.3.1/go.mod h1:fx2JeJAwEoepVcE3Fgd6JQSBvUAccyuFDzMmct1eWYw=
github.com/xmidt-org/capacityset v0.1.1/go.mod h1:rJ00PZmbkdroZMiL0DOMzgkrwJddVfR1I5LmRX6YG2Y=
github.com/xmidt-org/codex-db v0.1.2 h1:zyKN1i808G61fnlJAm3cdKbTZIcejigHf4UaVcV7Cic=
github.com/xmidt-org/codex-db v0.1.2/go.mod h1:sNfUvP41CMKncMmLvysGW35oZw8toeurxZoK97pEHuA=
github.com/xmidt-org/codex-db v0.1.3-0.20190808222843-c56f57b13b7a h1:lzkqhvK5jwpiJN4EsM/tiFN2yAK26lqUyMuLKp9cDB0=
github.com/xmidt-org/codex-db v0.1.3-0.20190808222843-c56f57b13b7a/go.mod h1:6yjozdS4PK2zv/onPQ0XZUzszHSIB8pXNRKlfaVTR8Y=
github.com/xmidt-org/codex-db v0.1.3-0.20190815234414-df93c0a46c24 h1:0vtCW+edYhHsLWXvNkbixDQaTHCyKqfZiT65p4/6RAM=
github.com/xmidt-org/codex-db v0.1.3-0.20190815234414-df93c0a46c24/go.mod h1:6yjozdS4PK2zv/onPQ0XZUzszHSIB8pXNRKlfaVTR8Y=
github.com/xmidt-org/codex-db v0.1.3-0.20190926172442-f067e203ad30 h1:locnIQZ373OwNRWQNshMIdwKEuOhBbEs+jFdbbqSo4I=
github.com/xmidt-org/codex-db v0.1.3-0.20190926172442-f067e203ad30/go.mod h1:3sauqorqztJTopTr797lJUDp9sPVN0hKDxWok0hFZfY=
github.com/xmidt-org/codex-db v0.2.0 h1:BDP6TEQOqzJkAe58dgL132Pja/xe6BegVSJpdw70C18=
github.com/xmidt-org/codex-db v0.2.0/go.mod h1:3sauqorqztJTopTr797lJUDp9sPVN0hKDxWok0hFZfY=
github.com/xmidt-org/voynicrypto v0.1.1 h1:hMqSOgYzpkbUUpgKxJcPTVRGdmDY0jem8PufsUikh+c=
github.com/xmidt-org/voynicrypto v0.1.1/go.mod h1:YSw/rwukAL2tpkB6wSeuoCRBOIK2mhpV4OzJLX292fs=
github.com/xmidt-org/webpa-common v1.1.0/go.mod h1:oCpKzOC+9h2vYHVzAU/06tDTQuBN4RZz+rhgIXptpOI=
Expand All @@ -219,6 +233,8 @@ github.com/xmidt-org/wrp-go v1.2.0/go.mod h1:Kw0jjKWw5e94bh5r45HYKGC1wN8IrfeZlXy
github.com/xmidt-org/wrp-listener v0.1.1 h1:1PvRUkQX4456qqds3E+cSLdyfyf0gIp/d0omIx1doEw=
github.com/xmidt-org/wrp-listener v0.1.1/go.mod h1:TQJs1YbA4E7L0RaRLZxzwgYyFvM/SeIet+62dtFatYk=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yugabyte/gocql v0.0.0-20190522232832-e049977574e9 h1:BpVFCemJnLkcheWPQGmFnWzS+4CNXtHwKsgZiyvTT/I=
github.com/yugabyte/gocql v0.0.0-20190522232832-e049977574e9/go.mod h1:kXnWCffg+Tcm4uCyjKS4JcAJEsWDrMPR58Yav3pfwBc=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
Expand Down Expand Up @@ -251,6 +267,7 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -288,6 +305,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"crypto/sha1"
"fmt"
"github.com/xmidt-org/codex-db/cassandra"
olog "log"
"net/http"
_ "net/http/pprof"
Expand All @@ -45,7 +46,6 @@ import (
"github.com/xmidt-org/codex-db/batchInserter"
"github.com/xmidt-org/codex-db/blacklist"
"github.com/xmidt-org/codex-db/healthlogger"
"github.com/xmidt-org/codex-db/postgresql"
"github.com/xmidt-org/codex-db/retry"
"github.com/xmidt-org/svalinn/requestParser"
"github.com/xmidt-org/voynicrypto"
Expand Down Expand Up @@ -73,7 +73,7 @@ type SvalinnConfig struct {
Secret SecretConfig
RequestParser requestParser.Config
BatchInserter batchInserter.Config
Db postgresql.Config
Db cassandra.Config
InsertRetries RetryConfig
BlacklistInterval time.Duration
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func svalinn(arguments []string) {

var (
f, v = pflag.NewFlagSet(applicationName, pflag.ContinueOnError), viper.New()
logger, metricsRegistry, codex, err = server.Initialize(applicationName, arguments, f, v, postgresql.Metrics, dbretry.Metrics, requestParser.Metrics, batchInserter.Metrics, basculechecks.Metrics)
logger, metricsRegistry, codex, err = server.Initialize(applicationName, arguments, f, v, cassandra.Metrics, dbretry.Metrics, requestParser.Metrics, batchInserter.Metrics, basculechecks.Metrics)
)

if parseErr, done := printVersion(f, arguments); done {
Expand Down Expand Up @@ -274,7 +274,7 @@ func setupDb(config *SvalinnConfig, logger log.Logger, metricsRegistry xmetrics.
d.health = health.New()
d.health.Logger = healthlogger.NewHealthLogger(logger)

dbConn, err := postgresql.CreateDbConnection(config.Db, metricsRegistry, d.health)
dbConn, err := cassandra.CreateDbConnection(config.Db, metricsRegistry, d.health)
if err != nil {
return database{}, err
}
Expand Down
3 changes: 2 additions & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

- switched database configuration from postgres to cassandra
- bumped codex-db to v0.2.0
99 changes: 37 additions & 62 deletions svalinn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ primary:
# health defines the details needed for the health check endpoint. The
# health check endpoint is generally used by services (like AWS Route53
# or consul) to determine if this particular machine is healthy or not.
health:
health:
# port provides the port number for the endpoint to bind to.
# ":80" is ideal, but may require some special handling due to it being
# a reserved (by the kernel) port.
Expand Down Expand Up @@ -147,71 +147,48 @@ log:
# db provides the configuration for connecting to the database and database
# calls.
db:
# server is the address and port used to connect to the server.
server: "db:26257"

# username is the username to use when connecting to the database.
username: "roachadmin"

# hosts is and array of address and port used to connect to the cluster.
hosts:
- "db"
# database is the name of the database being connected to.
database: "devices"

# SSLRootCert is the root cert to use when connecting to the database.
# The SSLKey and SSLCert must also be provided in order to connect securely.
# (Optional)
#sslRootCert: "/etc/svalinn/ca.crt"

# SSLKey is the SSL key to use when connecting to the database. The
# SSLRootCert and SSLCert must also be provided in order to connect securely.
# (Optional)
#sslKey: "/etc/svalinn/client.svalinn.key"

# SSLCert is the SSL cert to use when connecting to the database. The SSLKey
# and SSLRootCert must also be provided in order to connect securely.
# (Optional)
#sslCert: "/etc/svalinn/client.svalinn.crt"

# numRetries is the number of times to retry connecting to the database. If
# numRetries is below 1, there will be no attempts to retry.
# (Optional)
numRetries: 4

# waitTimeMult is the number to multiply by 1 second in between each attempt
# to connect to the database. If there is only the initial attempt, this
# value is not used. If the multiple is set below 1, it defaults to 1.
# (Optional) defaults to 1
waitTimeMult: 5

# pingInterval is the time to wait in between pinging the database. The ping
# is a part of the health check for svalinn. If pinging fails, svalinn will
# report as unhealthy. If the ping interval is set to 0, it defaults to 1s.
# (Optional) defaults to 1s
pingInterval: 1s

# connectTimeout is the timeout for connecting to the database. If
# establishing a connection takes longer than this, it will fail. If
# the connectTimeout is set to 0, it defaults to 10s.
# (Optional) defaults to 10s
connectTimeout: 1m

# opTimeout is the timeout for database calls after svalinn is connected.
# If the opTimeout is set to 0, it defaults to 10s.
# (Optional) defaults to 10s
opTimeout: 100ms

# maxIdleConns are the maximum number of idle connections allowed at one time.
# If a value below 2 is chosen, it defaults to 2.
# (Optional) defaults to 2
#maxIdleConns: 2

# maxOpenConns are the maximum number of open connections allowed at one time.
# If the value is 0, there is an unlimited number of connections.
# (Optional)I
#maxOpenConns: 0
# # username is the username to use when connecting to the database.
# # (Optional)
# username: "cassandra"
#
# # password is the password to use when connecting to the database.
# # (Optional)
# password: "cassandra"
#
# # SSLRootCert is the root cert to use when connecting to the database.
# # The SSLKey and SSLCert must also be provided in order to connect securely.
# # (Optional)
# #sslRootCert: "/etc/svalinn/ca.crt"
#
# # SSLKey is the SSL key to use when connecting to the database. The
# # SSLRootCert and SSLCert must also be provided in order to connect securely.
# # (Optional)
# #sslKey: "/etc/svalinn/node.0.0.0.0.key"
#
# # SSLCert is the SSL cert to use when connecting to the database. The SSLKey
# # and SSLRootCert must also be provided in order to connect securely.
# # (Optional)
# #sslCert: "/etc/svalinn/node.0.0.0.0.crt"
#
# # If you want to verify the hostname and server cert (like a wildcard for cass cluster) then you should turn this on
# # This option is basically the inverse of InSecureSkipVerify
# # See InSecureSkipVerify in http://golang.org/pkg/crypto/tls/ for more info
# # (Optional) defaults to false
# #enableHostVerification: false

# insertRetries provides the information needed for making multiple attempts to
# insert the same batch of records.
insertRetries:
insertRetries:
# numRetries provides the number of times to retry if a database request
# fails. If numRetries is set to a value below 0, it is set to 1.
# (Optional)
Expand Down Expand Up @@ -266,8 +243,7 @@ batchInserter:
# If there is no encryption, use the "none" configuration below. Svalinn uses
# the first cipher on the list that loads successfully.
cipher:
-
# type is the type of encryption.
- # type is the type of encryption.
type: rsa-sym

# kid is a further identifier for what kind of encryption should be used.
Expand All @@ -277,14 +253,13 @@ cipher:
# (Optional)
params:
hash: SHA512

# keys are the keys to use for this form of encryption.
# (Optional)
keys:
publicKey: "/etc/svalinn/public.pem"

-
# type is the type of encryption.
- # type is the type of encryption.
type: none

# kid is the a further identifier for what kind of encryption should be used.
Expand Down Expand Up @@ -445,7 +420,7 @@ webhook:
# (Optional) default is [".*"]
# matcher:
# deviceID: [".*"]

# the below configuration values provide a way to add an Authorization header
# to the request to the webhook. If both basic and sat contain empty values,
# no header is sent. sat takes priority over basic if both are set.
Expand Down

0 comments on commit 54ed289

Please sign in to comment.