Local Development
To run replay-server
locally, you can use the following comamnd which will start the server as well as the Postgres database.
Ensure you have Docker running before running this command
make dev-server
docker-compose up -d
[+] Running 1/0
✔ Container replay-server-db-1 Running
2024-01-31T15:20:40.698-0700 INFO logger/logger.go:28 running migration up
2024-01-31T15:20:40.714-0700 INFO logger/logger.go:28 done running migration up
INFO[2024-01-31T15:20:42-07:00] Attempting to load config file from: downloadedReplayConfigs/replayRunJobConfig.json
INFO[2024-01-31T15:20:42-07:00] Found replayConfig: &{FoundSource:false AllowedContentTypes:map[] BlockList:[] MappingPatternConfig:[]}
INFO[2024-01-31T15:20:42-07:00] Attempting to load config file from: downloadedReplayConfigs/replayRunJobConfig.json
INFO[2024-01-31T15:20:42-07:00] Found replayConfig: &{FoundSource:false AllowedContentTypes:map[] BlockList:[] MappingPatternConfig:[]}
INFO[2024-01-31T15:20:42-07:00] HTTP ONLY Server starting on port :8000
This will start replay-server
locally on port 8000
using config-local.yml
by default.
You can verify it is running using the following curl command:
curl http://localhost:8000/health
{"status":"ok"}
**By default make dev-server
will include the migrate-local-up
command causing migrations to run. If this is not preferred, remove this and run them manually.
To use IAM middleware locally run:
export CONFIG_IAM_CLIENTSECRET=$(gcloud secrets versions access latest --secret replay-server-iam_client_secret)
Ensure gcloud SDK is properly authenticated
gcloud auth application-default login
to ensure the proper ADC is setup
Installing Go if you don't, or have the wrong version
- If using
asdf
ensure .tools-version
version of Go is setup
- (run
asdf install golang 1.#.#
to install the appropriate Go version) (run asdf global golang 1.#.#
to set the default global Go version)
- Be aware that VSCode likely needs your GOROOT specified with the
"go.goroot"
setting
- (make sure go is in your bash/zsh/etc setup aka
echo GOPATH=$HOME/go
or whatever is appropriate)
Install Go modules
- Run
go mod download
to install the various dependencies
Install Go Gin
See their site
go install github.com/codegangsta/gin@latest
Install UPX
This helps compress the built go binaries:
brew install upx
"Localhost" setup
It is recommended that you setup your your local server in an HTTPS capacity to fully understand resource loading behaviors of a fully operational system. QM hosts a custom DNS record of loopback.quantummetric.com
that resolves to 127.0.0.1
so you can call that url like https://loopback.quantummetric.com
to hit your machine. (You will need wildcard QM certs to have full cert authority trust chains in place!)
Setup Steps:
-
Ensure you have certs added in the /certs
root directory.
-
Add to your config.yml
file :
certs:
crt: "/Users/${user}/quantum/replay-server/certs/quantummetric.com.crt"
key: "/Users/${user}/quantum/replay-server/certs/quantummetric.com.key"
Local Postgres Database
You can connect to local postgres database with the following configuration:
database:
host: localhost
port: 5432
dbname: postgres
username: postgres
ssl: disable
You can access the local Postgres database with CLI tools like psql or use an IDE such as pgAdmin
Access Staging/Production CloudSQL
Request your first resource
You should now be able to make a sample requests with something like your browser, curl, postman, etc.
Local CLI Development
- Run
go install
to install the new replay-cli
command
- In terminal you can now run
replay-cli -h
to see the available commands it supports!
- The lazy way is to run
go install; replay-cli download --session #SESSION# --sub #SUB# -o test.json
or something to build & test as you go!