Skip to content

Commit

Permalink
Merge pull request #67 from wish/postgres
Browse files Browse the repository at this point in the history
Add Postgres as a database option
  • Loading branch information
zxia-wish authored Jun 29, 2021
2 parents 69ba18e + a766de6 commit 01ab2f4
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/eventmaster/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type EMConfig struct {
DataStore string `json:"data_store"`
CassConfig em.CassandraConfig `json:"cassandra_config"`
PostgresConfig em.PostgresConfig `json:"postgres_config"`
UpdateInterval int `json:"update_interval"`
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/eventmaster/eventmaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func main() {
if err != nil {
log.Fatalf("failed to create cassandra data store: %v", err)
}
} else if emConf.DataStore == "postgres" {
ds, err = em.NewPostgresStore(emConf.PostgresConfig)
if err != nil {
log.Fatalf("failed to create postgres data store: %v", err)
}
} else {
log.Fatalf("Unrecognized data store option")
}
Expand Down
4 changes: 2 additions & 2 deletions docs/api/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ POST /v1/dc
Accept: application/json
Content-Type: application/json
{
"dc": "dc1"
"DC_name": "dc1"
}
```

Expand All @@ -247,7 +247,7 @@ PUT /v1/dc/dc1
Accept: application/json
Content-Type: application/json
{
"dc": "dc3"
"DC_name": "dc3"
}
```

Expand Down
9 changes: 8 additions & 1 deletion etc/eventmaster.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"data_store": "cassandra",
"data_store": "postgres",
"postgres_config": {
"addr": "127.0.0.1",
"port": 5432,
"database": "eventmaster",
"username": "postgres",
"password": "password"
},
"cassandra_config": {
"addrs": ["127.0.0.1:9042"],
"keyspace": "event_master",
Expand Down
8 changes: 4 additions & 4 deletions event_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/pkg/errors"
"github.com/satori/go.uuid"
uuid "github.com/satori/go.uuid"
"github.com/segmentio/ksuid"
"github.com/xeipuuv/gojsonschema"

Expand Down Expand Up @@ -326,7 +326,7 @@ func (es *EventStore) AddEvent(event *UnaddedEvent) (string, error) {

if err = es.ds.AddEvent(evt); err != nil {
metrics.DBError("write")
return "", errors.Wrap(err, "Error executing insert query in Cassandra")
return "", errors.Wrap(err, "Error executing insert query")
}

return evt.EventID, nil
Expand Down Expand Up @@ -462,7 +462,7 @@ func (es *EventStore) UpdateTopic(oldName string, td Topic) (string, error) {
Schema: schemaStr,
}); err != nil {
metrics.DBError("write")
return "", errors.Wrap(err, "Error executing update query in Cassandra")
return "", errors.Wrap(err, "Error executing update query")
}

es.topicMutex.Lock()
Expand Down Expand Up @@ -493,7 +493,7 @@ func (es *EventStore) DeleteTopic(deleteReq *eventmaster.DeleteTopicRequest) err

if err := es.ds.DeleteTopic(id); err != nil {
metrics.DBError("write")
return errors.Wrap(err, "Error executing delete query in Cassandra")
return errors.Wrap(err, "Error executing delete query")
}

es.topicMutex.Lock()
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.16
require (
cloud.google.com/go v0.26.0 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/Masterminds/squirrel v1.5.0
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a // indirect
github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect
github.com/client9/misspell v0.3.4 // indirect
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/envoyproxy/protoc-gen-validate v0.1.0 // indirect
github.com/gocql/gocql v0.0.0-20210515062232-b7ef815b4556
Expand All @@ -22,6 +22,7 @@ require (
github.com/jteeuwen/go-bindata v3.0.8-0.20180305030458-6025e8de665b+incompatible // indirect
github.com/julienschmidt/httprouter v1.1.0
github.com/kelseyhightower/envconfig v1.3.0
github.com/lib/pq v1.10.2
github.com/matttproud/golang_protobuf_extensions v1.0.0 // indirect
github.com/miekg/dns v1.1.42 // indirect
github.com/pkg/errors v0.8.0
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/squirrel v1.5.0 h1:JukIZisrUXadA9pl3rMkjhiamxiB0cXiu+HGp/Y8cY8=
github.com/Masterminds/squirrel v1.5.0/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a h1:BtpsbiV638WQZwhA98cEZw2BsbnQJrbd0BI7tsy0W1c=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
Expand All @@ -9,6 +11,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/envoyproxy/go-control-plane v0.7.1/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
Expand Down Expand Up @@ -62,6 +66,12 @@ github.com/kelseyhightower/envconfig v1.3.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/matttproud/golang_protobuf_extensions v1.0.0 h1:YNOwxxSJzSUARoD9KRZLzM9Y858MNGCOACTvCW9TSAc=
github.com/matttproud/golang_protobuf_extensions v1.0.0/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.1.42 h1:gWGe42RGaIqXQZ+r3WUGEKBEtvPHY2SXo4dqixDNxuY=
Expand Down Expand Up @@ -93,6 +103,7 @@ github.com/soheilhy/cmux v0.1.3/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.1.4 h1:ToftOQTytwshuOSj6bDSolVUa3GINfJP/fg3OkkOzQQ=
github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
Expand Down
Loading

0 comments on commit 01ab2f4

Please sign in to comment.