Redis: Update Redis package to last major version
Update the Redis dependency to use the last major production version. The last version accepts a context parameter in all the network methods so it allows us to pass it through them. Change-Id: I34121b2ec3c2728602115c724933ad24c9e6e4fd
This commit is contained in:
parent
09adfc1205
commit
4c1098e571
@ -74,13 +74,13 @@ func OpenDB(ctx context.Context, dbURL string, overwrite bool) (*DB, error) {
|
|||||||
return nil, ErrDB.Wrap(err)
|
return nil, ErrDB.Wrap(err)
|
||||||
}
|
}
|
||||||
case "redis":
|
case "redis":
|
||||||
redisClient, err := redis.NewClientFrom(dbURL)
|
redisClient, err := redis.NewClientFrom(ctx, dbURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrDB.Wrap(err)
|
return nil, ErrDB.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if overwrite {
|
if overwrite {
|
||||||
if err := redisClient.FlushDB(); err != nil {
|
if err := redisClient.FlushDB(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func cmdAPIRun(cmd *cobra.Command, args []string) (err error) {
|
|||||||
err = errs.Combine(err, revocationDB.Close())
|
err = errs.Combine(err, revocationDB.Close())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
accountingCache, err := live.NewCache(log.Named("live-accounting"), runCfg.LiveAccounting)
|
accountingCache, err := live.NewCache(ctx, log.Named("live-accounting"), runCfg.LiveAccounting)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !accounting.ErrSystemOrNetError.Has(err) || accountingCache == nil {
|
if !accounting.ErrSystemOrNetError.Has(err) || accountingCache == nil {
|
||||||
return errs.New("Error instantiating live accounting cache: %w", err)
|
return errs.New("Error instantiating live accounting cache: %w", err)
|
||||||
|
@ -392,7 +392,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
|
|||||||
err = errs.Combine(err, revocationDB.Close())
|
err = errs.Combine(err, revocationDB.Close())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
liveAccounting, err := live.NewCache(log.Named("live-accounting"), runCfg.LiveAccounting)
|
liveAccounting, err := live.NewCache(ctx, log.Named("live-accounting"), runCfg.LiveAccounting)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !accounting.ErrSystemOrNetError.Has(err) || liveAccounting == nil {
|
if !accounting.ErrSystemOrNetError.Has(err) || liveAccounting == nil {
|
||||||
return errs.New("Error instantiating live accounting cache: %w", err)
|
return errs.New("Error instantiating live accounting cache: %w", err)
|
||||||
|
6
go.mod
6
go.mod
@ -9,10 +9,10 @@ require (
|
|||||||
github.com/calebcase/tmpfile v1.0.2
|
github.com/calebcase/tmpfile v1.0.2
|
||||||
github.com/cheggaaa/pb/v3 v3.0.5
|
github.com/cheggaaa/pb/v3 v3.0.5
|
||||||
github.com/fatih/color v1.9.0
|
github.com/fatih/color v1.9.0
|
||||||
github.com/go-redis/redis v6.15.9+incompatible
|
github.com/go-redis/redis/v8 v8.7.1
|
||||||
github.com/gogo/protobuf v1.3.2
|
github.com/gogo/protobuf v1.3.2
|
||||||
github.com/golang-migrate/migrate/v4 v4.7.0
|
github.com/golang-migrate/migrate/v4 v4.7.0
|
||||||
github.com/google/go-cmp v0.5.2
|
github.com/google/go-cmp v0.5.4
|
||||||
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3 // indirect
|
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3 // indirect
|
||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
github.com/gorilla/schema v1.2.0
|
github.com/gorilla/schema v1.2.0
|
||||||
@ -30,7 +30,7 @@ require (
|
|||||||
github.com/spf13/cobra v1.0.0
|
github.com/spf13/cobra v1.0.0
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/spf13/viper v1.7.1
|
github.com/spf13/viper v1.7.1
|
||||||
github.com/stretchr/testify v1.6.1
|
github.com/stretchr/testify v1.7.0
|
||||||
github.com/stripe/stripe-go v70.15.0+incompatible
|
github.com/stripe/stripe-go v70.15.0+incompatible
|
||||||
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3
|
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3
|
||||||
github.com/zeebo/assert v1.1.0
|
github.com/zeebo/assert v1.1.0
|
||||||
|
35
go.sum
35
go.sum
@ -81,7 +81,10 @@ github.com/calebcase/tmpfile v1.0.2-0.20200602150926-3af473ef8439/go.mod h1:iErL
|
|||||||
github.com/calebcase/tmpfile v1.0.2 h1:1AGuhKiUu4J6wxz6lxuF6ck3f8G2kaV6KSEny0RGCig=
|
github.com/calebcase/tmpfile v1.0.2 h1:1AGuhKiUu4J6wxz6lxuF6ck3f8G2kaV6KSEny0RGCig=
|
||||||
github.com/calebcase/tmpfile v1.0.2/go.mod h1:iErLeG/iqJr8LaQ/gYRv4GXdqssi3jg4iSzvrA06/lw=
|
github.com/calebcase/tmpfile v1.0.2/go.mod h1:iErLeG/iqJr8LaQ/gYRv4GXdqssi3jg4iSzvrA06/lw=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE=
|
github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE=
|
||||||
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
|
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
|
||||||
github.com/cheggaaa/pb/v3 v3.0.5 h1:lmZOti7CraK9RSjzExsY53+WWfub9Qv13B5m4ptEoPE=
|
github.com/cheggaaa/pb/v3 v3.0.5 h1:lmZOti7CraK9RSjzExsY53+WWfub9Qv13B5m4ptEoPE=
|
||||||
@ -124,6 +127,8 @@ 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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
|
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||||
github.com/dhui/dktest v0.3.0 h1:kwX5a7EkLcjo7VpsPQSYJcKGbXBXdjI9FGjuUj1jn6I=
|
github.com/dhui/dktest v0.3.0 h1:kwX5a7EkLcjo7VpsPQSYJcKGbXBXdjI9FGjuUj1jn6I=
|
||||||
github.com/dhui/dktest v0.3.0/go.mod h1:cyzIUfGsBEbZ6BT7tnXqAShHSXCZhSNmFl70sZ7c1yc=
|
github.com/dhui/dktest v0.3.0/go.mod h1:cyzIUfGsBEbZ6BT7tnXqAShHSXCZhSNmFl70sZ7c1yc=
|
||||||
@ -160,8 +165,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
|
|||||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||||
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
|
github.com/go-redis/redis/v8 v8.7.1 h1:8IYi6RO83fNcG5amcUUYTN/qH2h4OjZHlim3KWGFSsA=
|
||||||
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
github.com/go-redis/redis/v8 v8.7.1/go.mod h1:BRxHBWn3pO3CfjyX6vAoyeRmCquvxr6QG+2onGV2gYs=
|
||||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||||
github.com/gocql/gocql v0.0.0-20190301043612-f6df8288f9b4/go.mod h1:4Fw1eo5iaEhDUs8XyuhSVCVy52Jq3L+/3GJgYkwc+/0=
|
github.com/gocql/gocql v0.0.0-20190301043612-f6df8288f9b4/go.mod h1:4Fw1eo5iaEhDUs8XyuhSVCVy52Jq3L+/3GJgYkwc+/0=
|
||||||
@ -209,8 +214,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
|
|||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||||
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
||||||
@ -432,12 +437,14 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
|||||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||||
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
|
|
||||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||||
|
github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4=
|
||||||
|
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
|
||||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||||
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
|
||||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||||
|
github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
|
||||||
|
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
|
||||||
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
|
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
|
||||||
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
|
||||||
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
|
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
|
||||||
@ -556,8 +563,9 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
|||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stripe/stripe-go v70.15.0+incompatible h1:hNML7M1zx8RgtepEMlxyu/FpVPrP7KZm1gPFQquJQvM=
|
github.com/stripe/stripe-go v70.15.0+incompatible h1:hNML7M1zx8RgtepEMlxyu/FpVPrP7KZm1gPFQquJQvM=
|
||||||
github.com/stripe/stripe-go v70.15.0+incompatible/go.mod h1:A1dQZmO/QypXmsL0T8axYZkSN/uA/T/A64pfKdBAMiY=
|
github.com/stripe/stripe-go v70.15.0+incompatible/go.mod h1:A1dQZmO/QypXmsL0T8axYZkSN/uA/T/A64pfKdBAMiY=
|
||||||
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
||||||
@ -607,6 +615,14 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
|||||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||||
go.opencensus.io v0.22.2 h1:75k/FF0Q2YM8QYo07VPddOLBslDt1MZOdEslOHvmzAs=
|
go.opencensus.io v0.22.2 h1:75k/FF0Q2YM8QYo07VPddOLBslDt1MZOdEslOHvmzAs=
|
||||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||||
|
go.opentelemetry.io/otel v0.18.0 h1:d5Of7+Zw4ANFOJB+TIn2K3QWsgS2Ht7OU9DqZHI6qu8=
|
||||||
|
go.opentelemetry.io/otel v0.18.0/go.mod h1:PT5zQj4lTsR1YeARt8YNKcFb88/c2IKoSABK9mX0r78=
|
||||||
|
go.opentelemetry.io/otel/metric v0.18.0 h1:yuZCmY9e1ZTaMlZXLrrbAPmYW6tW1A5ozOZeOYGaTaY=
|
||||||
|
go.opentelemetry.io/otel/metric v0.18.0/go.mod h1:kEH2QtzAyBy3xDVQfGZKIcok4ZZFvd5xyKPfPcuK6pE=
|
||||||
|
go.opentelemetry.io/otel/oteltest v0.18.0 h1:FbKDFm/LnQDOHuGjED+fy3s5YMVg0z019GJ9Er66hYo=
|
||||||
|
go.opentelemetry.io/otel/oteltest v0.18.0/go.mod h1:NyierCU3/G8DLTva7KRzGii2fdxdR89zXKH1bNWY7Bo=
|
||||||
|
go.opentelemetry.io/otel/trace v0.18.0 h1:ilCfc/fptVKaDMK1vWk0elxpolurJbEgey9J6g6s+wk=
|
||||||
|
go.opentelemetry.io/otel/trace v0.18.0/go.mod h1:FzdUu3BPwZSZebfQ1vl5/tAa8LyMLXSJN57AXIt/iDk=
|
||||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||||
@ -701,8 +717,9 @@ golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
|
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
|
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U=
|
||||||
|
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
@ -764,6 +781,7 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20200610111108-226ff32320da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200610111108-226ff32320da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210112091331-59c308dcf3cc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210112091331-59c308dcf3cc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@ -809,6 +827,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
|
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
@ -60,7 +60,7 @@ func openDBBolt(ctx context.Context, path string) (*DB, error) {
|
|||||||
|
|
||||||
// openDBRedis creates a redis-backed DB.
|
// openDBRedis creates a redis-backed DB.
|
||||||
func openDBRedis(ctx context.Context, address string) (*DB, error) {
|
func openDBRedis(ctx context.Context, address string) (*DB, error) {
|
||||||
client, err := redis.NewClientFrom(address)
|
client, err := redis.NewClientFrom(ctx, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -621,7 +621,7 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
|
|||||||
|
|
||||||
planet.databases = append(planet.databases, revocationDB)
|
planet.databases = append(planet.databases, revocationDB)
|
||||||
|
|
||||||
liveAccounting, err := live.NewCache(log.Named("live-accounting"), config.LiveAccounting)
|
liveAccounting, err := live.NewCache(ctx, log.Named("live-accounting"), config.LiveAccounting)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errs.Wrap(err)
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -747,7 +747,7 @@ func (planet *Planet) newAPI(ctx context.Context, index int, identity *identity.
|
|||||||
}
|
}
|
||||||
planet.databases = append(planet.databases, revocationDB)
|
planet.databases = append(planet.databases, revocationDB)
|
||||||
|
|
||||||
liveAccounting, err := live.NewCache(log.Named("live-accounting"), config.LiveAccounting)
|
liveAccounting, err := live.NewCache(ctx, log.Named("live-accounting"), config.LiveAccounting)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errs.Wrap(err)
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alicebob/miniredis/v2"
|
"github.com/alicebob/miniredis/v2"
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis/v8"
|
||||||
|
|
||||||
"storj.io/common/processgroup"
|
"storj.io/common/processgroup"
|
||||||
)
|
)
|
||||||
@ -145,7 +145,7 @@ func Process(ctx context.Context) (Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test whether we can actually connect
|
// test whether we can actually connect
|
||||||
if err := pingServer(addr); err != nil {
|
if err := pingServer(ctx, addr); err != nil {
|
||||||
cleanup()
|
cleanup()
|
||||||
return nil, fmt.Errorf("unable to ping: %v", err)
|
return nil, fmt.Errorf("unable to ping: %v", err)
|
||||||
}
|
}
|
||||||
@ -169,10 +169,10 @@ func (process *process) Close() error {
|
|||||||
|
|
||||||
func (process *process) FastForward(_ time.Duration) {}
|
func (process *process) FastForward(_ time.Duration) {}
|
||||||
|
|
||||||
func pingServer(addr string) error {
|
func pingServer(ctx context.Context, addr string) error {
|
||||||
client := redis.NewClient(&redis.Options{Addr: addr, DB: 1})
|
client := redis.NewClient(&redis.Options{Addr: addr, DB: 1})
|
||||||
defer func() { _ = client.Close() }()
|
defer func() { _ = client.Close() }()
|
||||||
return client.Ping().Err()
|
return client.Ping(ctx).Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mini starts miniredis server.
|
// Mini starts miniredis server.
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package live
|
package live
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ type Config struct {
|
|||||||
// For this reason, the components that uses the cache should operate despite
|
// For this reason, the components that uses the cache should operate despite
|
||||||
// the backend is not responding successfully although their service is
|
// the backend is not responding successfully although their service is
|
||||||
// degraded.
|
// degraded.
|
||||||
func NewCache(log *zap.Logger, config Config) (accounting.Cache, error) {
|
func NewCache(ctx context.Context, log *zap.Logger, config Config) (accounting.Cache, error) {
|
||||||
parts := strings.SplitN(config.StorageBackend, ":", 2)
|
parts := strings.SplitN(config.StorageBackend, ":", 2)
|
||||||
var backendType string
|
var backendType string
|
||||||
if len(parts) == 0 || parts[0] == "" {
|
if len(parts) == 0 || parts[0] == "" {
|
||||||
@ -47,7 +48,7 @@ func NewCache(log *zap.Logger, config Config) (accounting.Cache, error) {
|
|||||||
backendType = parts[0]
|
backendType = parts[0]
|
||||||
switch backendType {
|
switch backendType {
|
||||||
case "redis":
|
case "redis":
|
||||||
return newRedisLiveAccounting(config.StorageBackend)
|
return newRedisLiveAccounting(ctx, config.StorageBackend)
|
||||||
default:
|
default:
|
||||||
return nil, Error.New("unrecognized live accounting backend specifier %q. Currently only redis is supported", backendType)
|
return nil, Error.New("unrecognized live accounting backend specifier %q. Currently only redis is supported", backendType)
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func TestAddGetProjectStorageAndBandwidthUsage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache, err := live.NewCache(zaptest.NewLogger(t).Named("live-accounting"), config)
|
cache, err := live.NewCache(ctx, zaptest.NewLogger(t).Named("live-accounting"), config)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer ctx.Check(cache.Close)
|
defer ctx.Check(cache.Close)
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ func TestGetAllProjectTotals(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache, err := live.NewCache(zaptest.NewLogger(t).Named("live-accounting"), config)
|
cache, err := live.NewCache(ctx, zaptest.NewLogger(t).Named("live-accounting"), config)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer ctx.Check(cache.Close)
|
defer ctx.Check(cache.Close)
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ func TestLiveAccountingCache_ProjectBandwidthUsage_expiration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache, err := live.NewCache(zaptest.NewLogger(t).Named("live-accounting"), config)
|
cache, err := live.NewCache(ctx, zaptest.NewLogger(t).Named("live-accounting"), config)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer ctx.Check(cache.Close)
|
defer ctx.Check(cache.Close)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis/v8"
|
||||||
|
|
||||||
"storj.io/common/uuid"
|
"storj.io/common/uuid"
|
||||||
"storj.io/storj/satellite/accounting"
|
"storj.io/storj/satellite/accounting"
|
||||||
@ -31,7 +31,7 @@ type redisLiveAccounting struct {
|
|||||||
// it fails then it returns an instance and accounting.ErrSystemOrNetError
|
// it fails then it returns an instance and accounting.ErrSystemOrNetError
|
||||||
// because it means that Redis may not be operative at this precise moment but
|
// because it means that Redis may not be operative at this precise moment but
|
||||||
// it may be in future method calls as it handles automatically reconnects.
|
// it may be in future method calls as it handles automatically reconnects.
|
||||||
func newRedisLiveAccounting(address string) (*redisLiveAccounting, error) {
|
func newRedisLiveAccounting(ctx context.Context, address string) (*redisLiveAccounting, error) {
|
||||||
redisurl, err := url.Parse(address)
|
redisurl, err := url.Parse(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, accounting.ErrInvalidArgument.New("address: invalid URL; %w", err)
|
return nil, accounting.ErrInvalidArgument.New("address: invalid URL; %w", err)
|
||||||
@ -63,7 +63,7 @@ func newRedisLiveAccounting(address string) (*redisLiveAccounting, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ping here to verify we are able to connect to Redis with the initialized client.
|
// ping here to verify we are able to connect to Redis with the initialized client.
|
||||||
if err := client.Ping().Err(); err != nil {
|
if err := client.Ping(ctx).Err(); err != nil {
|
||||||
return cache, accounting.ErrSystemOrNetError.New("Redis ping failed: %w", err)
|
return cache, accounting.ErrSystemOrNetError.New("Redis ping failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ func (cache *redisLiveAccounting) UpdateProjectBandwidthUsage(ctx context.Contex
|
|||||||
`, increment, increment, int(ttl.Seconds()))
|
`, increment, increment, int(ttl.Seconds()))
|
||||||
|
|
||||||
key := createBandwidthProjectIDKey(projectID, now)
|
key := createBandwidthProjectIDKey(projectID, now)
|
||||||
err = cache.client.Eval(script, []string{key}).Err()
|
err = cache.client.Eval(ctx, script, []string{key}).Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return accounting.ErrSystemOrNetError.New("Redis eval failed: %w", err)
|
return accounting.ErrSystemOrNetError.New("Redis eval failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func (cache *redisLiveAccounting) UpdateProjectBandwidthUsage(ctx context.Contex
|
|||||||
func (cache *redisLiveAccounting) AddProjectStorageUsage(ctx context.Context, projectID uuid.UUID, spaceUsed int64) (err error) {
|
func (cache *redisLiveAccounting) AddProjectStorageUsage(ctx context.Context, projectID uuid.UUID, spaceUsed int64) (err error) {
|
||||||
defer mon.Task()(&ctx, projectID, spaceUsed)(&err)
|
defer mon.Task()(&ctx, projectID, spaceUsed)(&err)
|
||||||
|
|
||||||
_, err = cache.client.IncrBy(string(projectID[:]), spaceUsed).Result()
|
_, err = cache.client.IncrBy(ctx, string(projectID[:]), spaceUsed).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return accounting.ErrSystemOrNetError.New("Redis incrby failed: %w", err)
|
return accounting.ErrSystemOrNetError.New("Redis incrby failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -136,8 +136,8 @@ func (cache *redisLiveAccounting) GetAllProjectTotals(ctx context.Context) (_ ma
|
|||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
projects := make(map[uuid.UUID]int64)
|
projects := make(map[uuid.UUID]int64)
|
||||||
it := cache.client.Scan(0, "*", 0).Iterator()
|
it := cache.client.Scan(ctx, 0, "*", 0).Iterator()
|
||||||
for it.Next() {
|
for it.Next(ctx) {
|
||||||
key := it.Val()
|
key := it.Val()
|
||||||
|
|
||||||
// skip bandwidth keys
|
// skip bandwidth keys
|
||||||
@ -182,7 +182,7 @@ func (cache *redisLiveAccounting) Close() error {
|
|||||||
func (cache *redisLiveAccounting) getInt64(ctx context.Context, key string) (_ int64, err error) {
|
func (cache *redisLiveAccounting) getInt64(ctx context.Context, key string) (_ int64, err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
val, err := cache.client.Get(key).Bytes()
|
val, err := cache.client.Get(ctx, key).Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, redis.Nil) {
|
if errors.Is(err, redis.Nil) {
|
||||||
return 0, accounting.ErrKeyNotFound.New("%q", key)
|
return 0, accounting.ErrKeyNotFound.New("%q", key)
|
||||||
|
@ -63,7 +63,7 @@ func TestGraphqlMutation(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer ctx.Check(redis.Close)
|
defer ctx.Check(redis.Close)
|
||||||
|
|
||||||
cache, err := live.NewCache(log.Named("cache"), live.Config{StorageBackend: "redis://" + redis.Addr() + "?db=0"})
|
cache, err := live.NewCache(ctx, log.Named("cache"), live.Config{StorageBackend: "redis://" + redis.Addr() + "?db=0"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
projectLimitCache := accounting.NewProjectLimitCache(db.ProjectAccounting(), 0, 0, accounting.ProjectLimitConfig{CacheCapacity: 100})
|
projectLimitCache := accounting.NewProjectLimitCache(db.ProjectAccounting(), 0, 0, accounting.ProjectLimitConfig{CacheCapacity: 100})
|
||||||
|
@ -47,7 +47,7 @@ func TestGraphqlQuery(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer ctx.Check(redis.Close)
|
defer ctx.Check(redis.Close)
|
||||||
|
|
||||||
cache, err := live.NewCache(log.Named("cache"), live.Config{StorageBackend: "redis://" + redis.Addr() + "?db=0"})
|
cache, err := live.NewCache(ctx, log.Named("cache"), live.Config{StorageBackend: "redis://" + redis.Addr() + "?db=0"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
projectLimitCache := accounting.NewProjectLimitCache(db.ProjectAccounting(), 0, 0, accounting.ProjectLimitConfig{CacheCapacity: 100})
|
projectLimitCache := accounting.NewProjectLimitCache(db.ProjectAccounting(), 0, 0, accounting.ProjectLimitConfig{CacheCapacity: 100})
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis/v8"
|
||||||
"github.com/spacemonkeygo/monkit/v3"
|
"github.com/spacemonkeygo/monkit/v3"
|
||||||
"github.com/zeebo/errs"
|
"github.com/zeebo/errs"
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns a configured Client instance, verifying a successful connection to redis.
|
// NewClient returns a configured Client instance, verifying a successful connection to redis.
|
||||||
func NewClient(address, password string, db int) (*Client, error) {
|
func NewClient(ctx context.Context, address, password string, db int) (*Client, error) {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
db: redis.NewClient(&redis.Options{
|
db: redis.NewClient(&redis.Options{
|
||||||
Addr: address,
|
Addr: address,
|
||||||
@ -51,7 +51,7 @@ func NewClient(address, password string, db int) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ping here to verify we are able to connect to redis with the initialized client.
|
// ping here to verify we are able to connect to redis with the initialized client.
|
||||||
if err := client.db.Ping().Err(); err != nil {
|
if err := client.db.Ping(ctx).Err(); err != nil {
|
||||||
return nil, Error.New("ping failed: %v", err)
|
return nil, Error.New("ping failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ func NewClient(address, password string, db int) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClientFrom returns a configured Client instance from a redis address, verifying a successful connection to redis.
|
// NewClientFrom returns a configured Client instance from a redis address, verifying a successful connection to redis.
|
||||||
func NewClientFrom(address string) (*Client, error) {
|
func NewClientFrom(ctx context.Context, address string) (*Client, error) {
|
||||||
redisurl, err := url.Parse(address)
|
redisurl, err := url.Parse(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -76,7 +76,7 @@ func NewClientFrom(address string) (*Client, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewClient(redisurl.Host, q.Get("password"), db)
|
return NewClient(ctx, redisurl.Host, q.Get("password"), db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLookupLimit sets the lookup limit.
|
// SetLookupLimit sets the lookup limit.
|
||||||
@ -109,7 +109,7 @@ func (client *Client) IncrBy(ctx context.Context, key storage.Key, value int64)
|
|||||||
if key.IsZero() {
|
if key.IsZero() {
|
||||||
return storage.ErrEmptyKey.New("")
|
return storage.ErrEmptyKey.New("")
|
||||||
}
|
}
|
||||||
_, err = client.db.IncrBy(key.String(), value).Result()
|
_, err = client.db.IncrBy(ctx, key.String(), value).Result()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func (client *Client) GetAll(ctx context.Context, keys storage.Keys) (_ storage.
|
|||||||
keyStrings[i] = v.String()
|
keyStrings[i] = v.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
results, err := client.db.MGet(keyStrings...).Result()
|
results, err := client.db.MGet(ctx, keyStrings...).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -179,7 +179,6 @@ func (client *Client) GetAll(ctx context.Context, keys storage.Keys) (_ storage.
|
|||||||
}
|
}
|
||||||
values = append(values, storage.Value(s))
|
values = append(values, storage.Value(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return values, nil
|
return values, nil
|
||||||
}
|
}
|
||||||
@ -198,7 +197,7 @@ func (client *Client) Iterate(ctx context.Context, opts storage.IterateOptions,
|
|||||||
func (client *Client) IterateWithoutLookupLimit(ctx context.Context, opts storage.IterateOptions, fn func(context.Context, storage.Iterator) error) (err error) {
|
func (client *Client) IterateWithoutLookupLimit(ctx context.Context, opts storage.IterateOptions, fn func(context.Context, storage.Iterator) error) (err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
all, err := client.allPrefixedItems(opts.Prefix, opts.First, nil, opts.Limit)
|
all, err := client.allPrefixedItems(ctx, opts.Prefix, opts.First, nil, opts.Limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -213,18 +212,18 @@ func (client *Client) IterateWithoutLookupLimit(ctx context.Context, opts storag
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FlushDB deletes all keys in the currently selected DB.
|
// FlushDB deletes all keys in the currently selected DB.
|
||||||
func (client *Client) FlushDB() error {
|
func (client *Client) FlushDB(ctx context.Context) error {
|
||||||
_, err := client.db.FlushDB().Result()
|
_, err := client.db.FlushDB(ctx).Result()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) allPrefixedItems(prefix, first, last storage.Key, limit int) (storage.Items, error) {
|
func (client *Client) allPrefixedItems(ctx context.Context, prefix, first, last storage.Key, limit int) (storage.Items, error) {
|
||||||
var all storage.Items
|
var all storage.Items
|
||||||
seen := map[string]struct{}{}
|
seen := map[string]struct{}{}
|
||||||
|
|
||||||
match := string(escapeMatch([]byte(prefix))) + "*"
|
match := string(escapeMatch([]byte(prefix))) + "*"
|
||||||
it := client.db.Scan(0, match, 0).Iterator()
|
it := client.db.Scan(ctx, 0, match, 0).Iterator()
|
||||||
for it.Next() {
|
for it.Next(ctx) {
|
||||||
key := it.Val()
|
key := it.Val()
|
||||||
if !first.IsZero() && storage.Key(key).Less(first) {
|
if !first.IsZero() && storage.Key(key).Less(first) {
|
||||||
continue
|
continue
|
||||||
@ -238,7 +237,7 @@ func (client *Client) allPrefixedItems(prefix, first, last storage.Key, limit in
|
|||||||
}
|
}
|
||||||
seen[key] = struct{}{}
|
seen[key] = struct{}{}
|
||||||
|
|
||||||
value, err := client.db.Get(key).Bytes()
|
value, err := client.db.Get(ctx, key).Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -274,7 +273,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// runs only if the watched keys remain unchanged
|
// runs only if the watched keys remain unchanged
|
||||||
_, err = tx.Pipelined(func(pipe redis.Pipeliner) error {
|
_, err = tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
|
||||||
return put(ctx, pipe, key, newValue, client.TTL)
|
return put(ctx, pipe, key, newValue, client.TTL)
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
@ -288,7 +287,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// runs only if the watched keys remain unchanged
|
// runs only if the watched keys remain unchanged
|
||||||
_, err = tx.Pipelined(func(pipe redis.Pipeliner) error {
|
_, err = tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
|
||||||
if newValue == nil {
|
if newValue == nil {
|
||||||
return delete(ctx, pipe, key)
|
return delete(ctx, pipe, key)
|
||||||
}
|
}
|
||||||
@ -298,7 +297,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.db.Watch(txf, key.String())
|
err = client.db.Watch(ctx, txf, key.String())
|
||||||
if errors.Is(err, redis.TxFailedErr) {
|
if errors.Is(err, redis.TxFailedErr) {
|
||||||
return storage.ErrValueChanged.New("%q", key)
|
return storage.ErrValueChanged.New("%q", key)
|
||||||
}
|
}
|
||||||
@ -307,7 +306,7 @@ func (client *Client) CompareAndSwap(ctx context.Context, key storage.Key, oldVa
|
|||||||
|
|
||||||
func get(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (_ storage.Value, err error) {
|
func get(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (_ storage.Value, err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
value, err := cmdable.Get(string(key)).Bytes()
|
value, err := cmdable.Get(ctx, string(key)).Bytes()
|
||||||
if errors.Is(err, redis.Nil) {
|
if errors.Is(err, redis.Nil) {
|
||||||
return nil, storage.ErrKeyNotFound.New("%q", key)
|
return nil, storage.ErrKeyNotFound.New("%q", key)
|
||||||
}
|
}
|
||||||
@ -319,7 +318,7 @@ func get(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (_ storage
|
|||||||
|
|
||||||
func put(ctx context.Context, cmdable redis.Cmdable, key storage.Key, value storage.Value, ttl time.Duration) (err error) {
|
func put(ctx context.Context, cmdable redis.Cmdable, key storage.Key, value storage.Value, ttl time.Duration) (err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
err = cmdable.Set(key.String(), []byte(value), ttl).Err()
|
err = cmdable.Set(ctx, key.String(), []byte(value), ttl).Err()
|
||||||
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
||||||
return Error.New("put error: %v", err)
|
return Error.New("put error: %v", err)
|
||||||
}
|
}
|
||||||
@ -328,7 +327,7 @@ func put(ctx context.Context, cmdable redis.Cmdable, key storage.Key, value stor
|
|||||||
|
|
||||||
func delete(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (err error) {
|
func delete(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
err = cmdable.Del(key.String()).Err()
|
err = cmdable.Del(ctx, key.String()).Err()
|
||||||
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
||||||
return Error.New("delete error: %v", err)
|
return Error.New("delete error: %v", err)
|
||||||
}
|
}
|
||||||
@ -337,7 +336,7 @@ func delete(ctx context.Context, cmdable redis.Cmdable, key storage.Key) (err er
|
|||||||
|
|
||||||
func eval(ctx context.Context, cmdable redis.Cmdable, script string, keys []string) (err error) {
|
func eval(ctx context.Context, cmdable redis.Cmdable, script string, keys []string) (err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
err = cmdable.Eval(script, keys, nil).Err()
|
err = cmdable.Eval(ctx, script, keys, nil).Err()
|
||||||
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
if err != nil && !errors.Is(err, redis.TxFailedErr) {
|
||||||
return Error.New("eval error: %v", err)
|
return Error.New("eval error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func TestSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer func() { require.NoError(t, redis.Close()) }()
|
defer func() { require.NoError(t, redis.Close()) }()
|
||||||
|
|
||||||
client, err := NewClient(redis.Addr(), "", 1)
|
client, err := NewClient(ctx, redis.Addr(), "", 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ func TestSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidConnection(t *testing.T) {
|
func TestInvalidConnection(t *testing.T) {
|
||||||
_, err := NewClient("", "", 1)
|
_, err := NewClient(context.Background(), "", "", 1)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected connection error")
|
t.Fatal("expected connection error")
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ func BenchmarkSuite(b *testing.B) {
|
|||||||
}
|
}
|
||||||
defer func() { require.NoError(b, redis.Close()) }()
|
defer func() { require.NoError(b, redis.Close()) }()
|
||||||
|
|
||||||
client, err := NewClient(redis.Addr(), "", 1)
|
client, err := NewClient(ctx, redis.Addr(), "", 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user