capactio / capact

Simple way to manage applications and infrastructure.
https://capact.io
Apache License 2.0
80 stars 19 forks source link

Add support for external storages on lock, unlock, update, get, and delete #654

Closed mszostok closed 2 years ago

mszostok commented 2 years ago

Description

Changes proposed in this pull request:

New scope:

Testing

The test that I wrote, proves that it works e2e (Go client -> GraphQL -> Local Hub -> External Storage).

  1. Run neo4j:

    docker run -d \
      -p 7687:7687 -p 7474:7474 \
      -e "NEO4J_AUTH=neo4j/okon" \
      -e "NEO4JLABS_PLUGINS=[\"apoc\"]" \
      --name hub-neo4j-instance \
      ghcr.io/capactio/neo4j:4.2.13-apoc
  2. Run modified storage server:

    APP_LOGGER_LEVEL="debug" APP_LOGGER_DEV_MODE=true APP_SUPPORTED_PROVIDERS="dotenv" go run ./cmd/secret-storage-backend/main.go
  3. Run Local Hub:

    cd hub-js; APP_NEO4J_ENDPOINT=bolt://localhost:7687 APP_NEO4J_PASSWORD=okon APP_HUB_MODE=local npm run dev; cd ..
  4. Check that no data is stored: ls /tmp/capact

  5. Run test:

    GRPC_SECRET_STORAGE_BACKEND_ADDR="0.0.0.0:50051" go test ./pkg/hub/client/local/ -v -count 1

    You should output that describe Local Hub state after each operation.

  6. Check that no data is stored: ls /tmp/capactas the above test also cleans up all created TypeInstances and gRPC call is also executed against external backends.

Related issue(s)

Notes

Sometimes I got unpredictable result from dotenv:

  #1: graphql: /storage_backend.StorageBackend/GetValue NOT_FOUND: TypeInstance "85e25a0e-76ef-4c26-a4ea-110873aea215" in revision 1 was not found

and in file:

  $ /bin/cat /tmp/capact/85e25a0e-76ef-4c26-a4ea-110873aea215
  2="{\"updated-value\":\"context 0\"}"
  locked_by="demo/testing"%

I'm not sure how this can happen, as it's not possible via exposed API. Probably there is some "race" directly in used library with Put implementation. However, we decided that backends don't need to be thread safe. To resolve that issue I used the mutex lib to prevent concurrent execution of value field resolver.