diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3f7159d..1254bb7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,10 +16,10 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Set up Go 1.22 + - name: Set up Go 1.23 uses: actions/setup-go@v3 with: - go-version: "1.22" + go-version: "1.23" cache: true - name: Install dependencies run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cb816cf..c11ae53 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -23,7 +23,7 @@ jobs: - name: Install Go 🧑‍💻 uses: actions/setup-go@v3 with: - go-version: '1.22' + go-version: "1.23" - name: Lint code issues 🚨 uses: golangci/golangci-lint-action@v3 @@ -31,8 +31,7 @@ jobs: - name: Run Go tests 🔬 run: go test -cover -covermode atomic -coverprofile=profile.cov -v ./... - # Enable coverage reporting - # - name: Report coverage to coveralls 📈 - # uses: shogo82148/actions-goveralls@v1 - # with: - # path-to-profile: profile.cov + - name: Report coverage to coveralls 📈 + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: profile.cov diff --git a/.golangci.yaml b/.golangci.yaml index 9a6b69b..12b44c6 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -12,24 +12,14 @@ linters: - nlreturn - testpackage - paralleltest - - exhaustivestruct - exhaustruct - gocognit - gochecknoinits - gocyclo - - maligned - funlen - maintidx - musttag - - nosnakecase - wrapcheck - - golint - - scopelint - - interfacer - - varcheck - - deadcode - - ifshort - - structcheck linters-settings: depguard: rules: @@ -39,6 +29,7 @@ linters-settings: - "!$test" allow: - $gostd + - "github.com/gatewayd-io/gatewayd/api/v1" - "github.com/gatewayd-io/gatewayd-plugin-sdk" - "github.com/gatewayd-io/gatewayd-plugin-cache" - "github.com/prometheus/client_golang" diff --git a/go.mod b/go.mod index 1cb85e9..c6bf3b1 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,23 @@ module github.com/gatewayd-io/gatewayd-plugin-cache -go 1.22 +go 1.23.1 require ( github.com/alicebob/miniredis/v2 v2.30.5 - github.com/gatewayd-io/gatewayd-plugin-sdk v0.2.16 - github.com/getsentry/sentry-go v0.27.0 + github.com/gatewayd-io/gatewayd v0.9.7 + github.com/gatewayd-io/gatewayd-plugin-sdk v0.3.1 + github.com/getsentry/sentry-go v0.28.1 github.com/go-co-op/gocron v1.37.0 github.com/go-redis/redis/v8 v8.11.5 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.6.1 - github.com/jackc/pgx/v5 v5.6.0 - github.com/prometheus/client_golang v1.19.1 - github.com/spf13/cast v1.6.0 + github.com/jackc/pgx/v5 v5.7.0 + github.com/prometheus/client_golang v1.20.3 + github.com/spf13/cast v1.7.0 github.com/stretchr/testify v1.9.0 github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04 - google.golang.org/grpc v1.64.0 + google.golang.org/grpc v1.66.0 + google.golang.org/protobuf v1.34.2 ) require ( @@ -28,28 +30,31 @@ require ( github.com/fatih/color v1.17.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oklog/run v1.1.0 // indirect github.com/pganalyze/pg_query_go/v5 v5.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.54.0 // indirect + github.com/prometheus/common v0.59.1 // indirect github.com/prometheus/procfs v0.15.1 // indirect - github.com/redis/go-redis/v9 v9.5.2 // indirect + github.com/redis/go-redis/v9 v9.6.1 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect github.com/rs/zerolog v1.33.0 // indirect - github.com/tetratelabs/wazero v1.7.2 // indirect - github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc // indirect - github.com/wasilibs/wazero-helpers v0.0.0-20240604052452-61d7981e9a38 // indirect + github.com/tetratelabs/wazero v1.8.0 // indirect + github.com/wasilibs/go-pgquery v0.0.0-20240826014338-9ea9e19d01fd // indirect + github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect github.com/yuin/gopher-lua v1.1.0 // indirect go.uber.org/atomic v1.11.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect - google.golang.org/protobuf v1.34.1 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 4dc7b08..3037951 100644 --- a/go.sum +++ b/go.sum @@ -29,12 +29,14 @@ github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/gatewayd-io/gatewayd-plugin-sdk v0.2.16 h1:Pdk5girDTDW84BgYRAt66IpUcUSvWUN4jQMg7yJgrIc= -github.com/gatewayd-io/gatewayd-plugin-sdk v0.2.16/go.mod h1:oXAX1Ml6h7Hq6WFRq3g6mZsu1e7QKLHKubPxRzrGsQ0= -github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= -github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/gatewayd-io/gatewayd v0.9.7 h1:RlV9QwIODidmo6NkREEexPMiGsTH0yFady0gzdOtzbc= +github.com/gatewayd-io/gatewayd v0.9.7/go.mod h1:FdI0WjMM1FI+5+paxmICt9LyaUK617Sr6Db9iQHxKtg= +github.com/gatewayd-io/gatewayd-plugin-sdk v0.3.1 h1:rxR5NokOlAjGpJJQpBBYijYrLMMu/BFA7EBikYTq3t8= +github.com/gatewayd-io/gatewayd-plugin-sdk v0.3.1/go.mod h1:grehVOvLIloX+Egnam78V1XR84C0MYzxlgfSCKU5bVg= +github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k= +github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg= github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0= github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= @@ -51,6 +53,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= @@ -59,12 +63,14 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= -github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= -github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.0 h1:FG6VLIdzvAPhnYqP14sQ2xhFLkiUQHCs6ySqO91kF4g= +github.com/jackc/pgx/v5 v5.7.0/go.mod h1:awP1KNnjylvpxHuHP63gzjhnGkI1iw+PMoIwvoleN/8= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= @@ -74,6 +80,8 @@ 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/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -86,8 +94,10 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= +github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= @@ -103,16 +113,16 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= -github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/prometheus/client_golang v1.20.3 h1:oPksm4K8B+Vt35tUhw6GbSNSgVlVSBH0qELP/7u83l4= +github.com/prometheus/client_golang v1.20.3/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8= -github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ= +github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= +github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/redis/go-redis/v9 v9.5.2 h1:L0L3fcSNReTRGyZ6AqAEN0K56wYeYAwapBIhkvh0f3E= -github.com/redis/go-redis/v9 v9.5.2/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4= +github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= @@ -122,8 +132,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= -github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= +github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -134,12 +144,12 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= -github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= -github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc h1:Hgim1Xgk1+viV7p0aZh9OOrMRfG+E4mGA+JsI2uB0+k= -github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc/go.mod h1:ah6UfXIl/oA0K3SbourB/UHggVJOBXwPZ2XudDmmFac= -github.com/wasilibs/wazero-helpers v0.0.0-20240604052452-61d7981e9a38 h1:RBu75fhabyxyGJ2zhkoNuRyObBMhVeMoXqmeaPTg2CQ= -github.com/wasilibs/wazero-helpers v0.0.0-20240604052452-61d7981e9a38/go.mod h1:Z80JvMwvze8KUlVQIdw9L7OSskZJ1yxlpi4AQhoQe4s= +github.com/tetratelabs/wazero v1.8.0 h1:iEKu0d4c2Pd+QSRieYbnQC9yiFlMS9D+Jr0LsRmcF4g= +github.com/tetratelabs/wazero v1.8.0/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs= +github.com/wasilibs/go-pgquery v0.0.0-20240826014338-9ea9e19d01fd h1:sg+N4jmzrjTjOXbDBy7p5nmASwSWiGJR82EL6H2xIJk= +github.com/wasilibs/go-pgquery v0.0.0-20240826014338-9ea9e19d01fd/go.mod h1:wtFpefAF8l2Y52RXDIXZK6bJT9T7bhc9R5VBGdcO/Sk= +github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4= +github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY= github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE= github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04 h1:qXafrlZL1WsJW5OokjraLLRURHiw0OzKHD/RNdspp4w= @@ -147,10 +157,10 @@ github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04/go.mod h1:FiwNQ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -160,19 +170,21 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc= +google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= +google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/main.go b/main.go index 67fea17..c4adee0 100644 --- a/main.go +++ b/main.go @@ -12,11 +12,14 @@ import ( "github.com/gatewayd-io/gatewayd-plugin-sdk/metrics" p "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin" v1 "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1" + apiV1 "github.com/gatewayd-io/gatewayd/api/v1" "github.com/getsentry/sentry-go" "github.com/go-redis/redis/v8" "github.com/hashicorp/go-hclog" goplugin "github.com/hashicorp/go-plugin" "github.com/spf13/cast" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) func main() { @@ -52,6 +55,23 @@ func main() { go metrics.ExposeMetrics(metricsConfig, logger) } + // Initialize the API client to get proxies from GatewayD. + apiGRPCAddress := cast.ToString(cfg["apiGRPCAddress"]) + apiClientConn, err := grpc.NewClient( + apiGRPCAddress, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil || apiClientConn == nil { + logger.Error("Failed to initialize API client", "error", err) + if pluginInstance.Impl.ExitOnStartupError { + logger.Info("Exiting due to startup error") + if apiClientConn != nil { + apiClientConn.Close() + } + os.Exit(1) + } + } + defer apiClientConn.Close() + pluginInstance.Impl.APIClient = apiV1.NewGatewayDAdminAPIServiceClient(apiClientConn) + cacheBufferSize := cast.ToUint(cfg["cacheBufferSize"]) if cacheBufferSize <= 0 { cacheBufferSize = 100 // default value @@ -71,7 +91,10 @@ func main() { logger.Error("Failed to parse Redis URL", "error", err) if pluginInstance.Impl.ExitOnStartupError { logger.Info("Exiting due to startup error") - os.Exit(1) + if apiClientConn != nil { + apiClientConn.Close() + } + os.Exit(1) //nolint:gocritic } } @@ -83,6 +106,9 @@ func main() { logger.Error("Failed to ping Redis server", "error", err) if pluginInstance.Impl.ExitOnStartupError { logger.Info("Exiting due to startup error") + if apiClientConn != nil { + apiClientConn.Close() + } os.Exit(1) } } @@ -93,7 +119,6 @@ func main() { cfg["periodicInvalidatorStartDelay"]) pluginInstance.Impl.PeriodicInvalidatorInterval = cast.ToDuration( cfg["periodicInvalidatorInterval"]) - pluginInstance.Impl.APIAddress = cast.ToString(cfg["apiAddress"]) // Start the periodic invalidator. if pluginInstance.Impl.PeriodicInvalidatorEnabled { diff --git a/plugin/api_client.go b/plugin/api_client.go index cafec69..f266f53 100644 --- a/plugin/api_client.go +++ b/plugin/api_client.go @@ -1,8 +1,10 @@ package plugin import ( + "context" "encoding/json" - "net/http" + + "google.golang.org/protobuf/types/known/emptypb" ) type Proxy struct { @@ -12,25 +14,32 @@ type Proxy struct { } // getProxies returns a list of proxies from GatewayD. -func (p *Plugin) getProxies() map[string]Proxy { - if p.APIAddress == "" { - p.Logger.Error("Failed to get a list of proxies from GatewayD", "error", "APIAddress is not set") +func (p *Plugin) getProxies() map[string]map[string]Proxy { + if p.APIClient == nil { + p.Logger.Error( + "Failed to get a list of proxies from GatewayD", + "error", "API client is not initialized", + ) return nil } - //nolint: noctx - resp, err := http.Get("http://" + p.APIAddress + "/v1/GatewayDPluginService/GetProxies") + proxies, err := p.APIClient.GetProxies(context.Background(), &emptypb.Empty{}) if err != nil { p.Logger.Error("Failed to get a list of proxies from GatewayD", "error", err) return nil } - defer resp.Body.Close() - proxies := map[string]Proxy{} - if err = json.NewDecoder(resp.Body).Decode(&proxies); err != nil { - p.Logger.Error("Failed to decode response from GatewayD", "error", err) + data, err := proxies.MarshalJSON() + if err != nil { + p.Logger.Error("Failed to marshal response from GatewayD", "error", err) + return nil + } + + var pxy map[string]map[string]Proxy + if err = json.Unmarshal(data, &pxy); err != nil { + p.Logger.Error("Failed to unmarshal response from GatewayD", "error", err) return nil } - return proxies + return pxy } diff --git a/plugin/api_client_test.go b/plugin/api_client_test.go index 7ef34bb..0d39a7a 100644 --- a/plugin/api_client_test.go +++ b/plugin/api_client_test.go @@ -1,19 +1,20 @@ package plugin import ( - "net/http" - "net/http/httptest" "os" - "strings" "testing" + apiV1 "github.com/gatewayd-io/gatewayd/api/v1" "github.com/hashicorp/go-hclog" "github.com/stretchr/testify/assert" "github.com/zenizh/go-capturer" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) -// Test_Plugin_getProxies_Fails_APIAddress tests that getProxies() fails when APIAddress is not set. -func Test_Plugin_getProxies_Fails_APIAddress(t *testing.T) { +// Test_Plugin_getProxies_Fails_APIClient tests that getProxies() +// fails when the API client is not initialized. +func Test_Plugin_getProxies_Fails_APIClient(t *testing.T) { output := capturer.CaptureOutput(func() { p := Plugin{ Logger: hclog.New(&hclog.LoggerOptions{ @@ -26,127 +27,29 @@ func Test_Plugin_getProxies_Fails_APIAddress(t *testing.T) { assert.Nil(t, proxies) }) - assert.Contains(t, output, "[ERROR] test: Failed to get a list of proxies from GatewayD: error=\"APIAddress is not set\"\n") + assert.Contains(t, output, "[ERROR] test: Failed to get a list of proxies from GatewayD: error=\"API client is not initialized\"\n") } -// Test_Plugin_getProxies_Fails_Request_Error tests that getProxies() fails when the request fails. -func Test_Plugin_getProxies_Fails_Request_Error(t *testing.T) { +// Test_Plugin_getProxies_Fails_Connection_Error tests that getProxies() +// fails when the API client fails to connect to GatewayD. +func Test_Plugin_getProxies_Fails_Connection_Error(t *testing.T) { output := capturer.CaptureOutput(func() { + conn, err := grpc.NewClient( + "localhost:18080", + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + assert.NoError(t, err) p := Plugin{ Logger: hclog.New(&hclog.LoggerOptions{ Name: "test", Level: hclog.Trace, Output: os.Stdout, }), - APIAddress: "localhost:12345", + APIClient: apiV1.NewGatewayDAdminAPIServiceClient(conn), } proxies := p.getProxies() assert.Nil(t, proxies) }) - assert.Contains(t, output, "[ERROR] test: Failed to get a list of proxies from GatewayD: error=\"Get \\\"http://localhost:12345/v1/GatewayDPluginService/GetProxies\\\": dial tcp [::1]:12345: connect: connection refused\"\n") -} - -// Test_Plugin_getProxies_Fails_Inaccessible tests that getProxies() fails -// when the API is not accessible. -func Test_Plugin_getProxies_Fails_Inaccessible(t *testing.T) { - output := capturer.CaptureOutput(func() { - p := Plugin{ - Logger: hclog.New(&hclog.LoggerOptions{ - Name: "test", - Level: hclog.Trace, - Output: os.Stdout, - }), - APIAddress: "127.0.0.1:18080", - } - proxies := p.getProxies() - assert.Nil(t, proxies) - }) - - assert.Contains(t, output, "[ERROR] test: Failed to get a list of proxies from GatewayD: error=\"Get \\\"http://127.0.0.1:18080/v1/GatewayDPluginService/GetProxies\\\": dial tcp 127.0.0.1:18080: connect: connection refused\"\n") -} - -// Test_Plugin_getProxies_Fails_Invalid_JSON tests that getProxies() fails -// when the response is not valid JSON. -func Test_Plugin_getProxies_Fails_Invalid_JSON(t *testing.T) { - output := capturer.CaptureOutput(func() { - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - if _, err := w.Write([]byte(``)); err != nil { - t.Fatal(err) - } - })) - defer testServer.Close() - - p := Plugin{ - Logger: hclog.New(&hclog.LoggerOptions{ - Name: "test", - Level: hclog.Trace, - Output: os.Stdout, - }), - APIAddress: strings.TrimPrefix(testServer.URL, "http://"), - } - - proxies := p.getProxies() - assert.Nil(t, proxies) - }) - - assert.Contains(t, output, "[ERROR] test: Failed to decode response from GatewayD: error=EOF\n") -} - -// Test_Plugin_getProxies_Fails_Empty_Response tests that getProxies() returns an empty map -// when the response is empty. -func Test_Plugin_getProxies_Fails_Empty_Response(t *testing.T) { - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - if _, err := w.Write([]byte(`{}`)); err != nil { - t.Fatal(err) - } - })) - defer testServer.Close() - - p := Plugin{ - Logger: hclog.New(&hclog.LoggerOptions{ - Name: "test", - Level: hclog.Trace, - Output: os.Stdout, - }), - APIAddress: strings.TrimPrefix(testServer.URL, "http://"), - } - - proxies := p.getProxies() - assert.NotNil(t, proxies) - assert.Equal(t, 0, len(proxies)) - assert.Equal(t, proxies, map[string]Proxy{}) -} - -// Test_Plugin_getProxies tests that getProxies() returns a map of proxies. -func Test_Plugin_getProxies(t *testing.T) { - testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - if _, err := w.Write([]byte(`{"default":{"available":["localhost:45121"],"busy":["localhost:45123"],"total":2}}`)); err != nil { - t.Fatal(err) - } - })) - defer testServer.Close() - - p := Plugin{ - Logger: hclog.New(&hclog.LoggerOptions{ - Name: "test", - Level: hclog.Trace, - Output: os.Stdout, - }), - APIAddress: strings.TrimPrefix(testServer.URL, "http://"), - } - - proxies := p.getProxies() - assert.Equal(t, 1, len(proxies)) - assert.Equal(t, 1, len(proxies["default"].Available)) - assert.Equal(t, 1, len(proxies["default"].Busy)) - assert.Equal(t, 2, proxies["default"].Total) - assert.Equal(t, "localhost:45121", proxies["default"].Available[0]) - assert.Equal(t, "localhost:45123", proxies["default"].Busy[0]) + assert.Contains(t, output, `[ERROR] test: Failed to get a list of proxies from GatewayD: error="rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing: dial tcp 127.0.0.1:18080: connect: connection refused\""`) } diff --git a/plugin/module.go b/plugin/module.go index ce0b580..c5bc48b 100644 --- a/plugin/module.go +++ b/plugin/module.go @@ -34,6 +34,7 @@ var ( "metricsUnixDomainSocket": sdkConfig.GetEnv( "METRICS_UNIX_DOMAIN_SOCKET", "/tmp/gatewayd-plugin-cache.sock"), "metricsEndpoint": sdkConfig.GetEnv("METRICS_ENDPOINT", "/metrics"), + "apiGRPCAddress": sdkConfig.GetEnv("API_GRPC_ADDRESS", "localhost:19090"), "redisURL": sdkConfig.GetEnv("REDIS_URL", "redis://localhost:6379/0"), "expiry": sdkConfig.GetEnv("EXPIRY", "1h"), "defaultDBName": sdkConfig.GetEnv("DEFAULT_DB_NAME", ""), @@ -44,7 +45,6 @@ var ( "PERIODIC_INVALIDATOR_START_DELAY", "1m"), "periodicInvalidatorInterval": sdkConfig.GetEnv( "PERIODIC_INVALIDATOR_INTERVAL", "1m"), - "apiAddress": sdkConfig.GetEnv("API_ADDRESS", "localhost:8080"), "exitOnStartupError": sdkConfig.GetEnv("EXIT_ON_STARTUP_ERROR", "false"), "cacheBufferSize": sdkConfig.GetEnv("CACHE_CHANNEL_BUFFER_SIZE", "100"), }, diff --git a/plugin/plugin.go b/plugin/plugin.go index 485ccd6..1613f4c 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -10,6 +10,7 @@ import ( "github.com/gatewayd-io/gatewayd-plugin-sdk/databases/postgres" sdkPlugin "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin" v1 "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1" + apiV1 "github.com/gatewayd-io/gatewayd/api/v1" goRedis "github.com/go-redis/redis/v8" "github.com/hashicorp/go-hclog" goplugin "github.com/hashicorp/go-plugin" @@ -23,6 +24,8 @@ type Plugin struct { Logger hclog.Logger + APIClient apiV1.GatewayDAdminAPIServiceClient + // Cache configuration. RedisClient *goRedis.Client RedisURL string @@ -37,7 +40,6 @@ type Plugin struct { PeriodicInvalidatorEnabled bool PeriodicInvalidatorStartDelay time.Duration PeriodicInvalidatorInterval time.Duration - APIAddress string } type CachePlugin struct { diff --git a/plugin/utils.go b/plugin/utils.go index cf505d2..e92eb70 100644 --- a/plugin/utils.go +++ b/plugin/utils.go @@ -73,17 +73,19 @@ func validateHostPort(hostPort string) (bool, error) { // isBusy checks if a client address exists in cache by matching the address // with the busy clients. -func isBusy(proxies map[string]Proxy, address string) bool { +func isBusy(proxies map[string]map[string]Proxy, address string) bool { if proxies == nil { // NOTE: If the API is not running, we assume that the client is busy, // so that we don't accidentally make the client and the plugin unstable. return true } - for _, name := range proxies { - for _, client := range name.Busy { - if client == address { - return true + for _, group := range proxies { + for _, block := range group { + for _, client := range block.Busy { + if client == address { + return true + } } } } diff --git a/plugin/utils_test.go b/plugin/utils_test.go index 623da4e..6f976a0 100644 --- a/plugin/utils_test.go +++ b/plugin/utils_test.go @@ -55,42 +55,39 @@ func Test_validateAddressPort_IPv4(t *testing.T) { } func Test_isBusy(t *testing.T) { - proxies := map[string]Proxy{ + proxies := map[string]map[string]Proxy{ "default": { - Busy: []string{"localhost:12345"}, + "reads": { + Busy: []string{"localhost:12345"}, + }, }, } assert.True(t, isBusy(proxies, "localhost:12345")) } func Test_isBusy_False(t *testing.T) { - proxies := map[string]Proxy{ + proxies := map[string]map[string]Proxy{ "default": { - Busy: []string{"localhost:12345"}, + "reads": { + Busy: []string{"localhost:12345"}, + }, }, } assert.False(t, isBusy(proxies, "localhost:54321")) } func Test_isBusy_False_Empty(t *testing.T) { - proxies := map[string]Proxy{ + proxies := map[string]map[string]Proxy{ "default": { - Busy: []string{}, + "reads": { + Busy: []string{}, + }, }, } assert.False(t, isBusy(proxies, "localhost:54321")) } func Test_isBusy_False_EmptyMap(t *testing.T) { - proxies := map[string]Proxy{} - assert.False(t, isBusy(proxies, "localhost:54321")) -} - -func Test_isBusy_False_EmptyMap_EmptyBusy(t *testing.T) { - proxies := map[string]Proxy{ - "default": { - Busy: []string{}, - }, - } + proxies := map[string]map[string]Proxy{} assert.False(t, isBusy(proxies, "localhost:54321")) }