Mock Server¶
Set up¶
Download assets from S3
python3 coreruntime/tests/utils/download_from_s3.py \ --default_bucket deliteai \ --prefix build-dependencies/llama-3.2-1B/onnx \ --output mockserver/mockserver_assets/llama-3 \ --archive_output True
Start services using docker compose:
cd mockserver docker compose up --build -d
To stop the mockserver:
docker compose down -v
Points to note¶
The above command runs an instance of Postgres, Mock Model Distribution Service (MDS), Mock Dashboard Management Services (DMS), Ingestion service and mock proxy server.
Mock server runs on
http://localhost:8080/
by default.Ingestion service runs on
http://localhost:8081/
by default. Update the API_KEY environment variable in docker-compose file to change the authentication key for ingestion service.Logger service runs on
http://localhost:8082/
by default. Update the API_KEY environment variable in docker-compose file to change the authentication key for logger service.By default some sample data is populated in
testclient
forDEFAULT-TAG
.All data is managed locally in the containers. No data is persisted across runs.
Always use
--build
flag to avoid using cached version of mock server.Using
-d
makes the services run in detached mode in the background.
Monitoring¶
To view state of pods run
docker compose ps
.To tail container logs use
docker compose logs -f service
. Here service can bemock_server
,mds
,dms
orpostgres
.Cloud config for testclient is configured to push logs and metrics to the logger service. They can be viewed at
sdk_logs/metrics.log
andsdk_logs/logs.log
. Unauthenticated and dropped events can be viewed insdk_logs/unauthenticated.log
andsdk_logs/dropped.log
.Ingestion service writes the events to
ingestion_events/vector.log
file.For testing with android simulator set
LOGGER_URL
indocker-compose.yaml
tohttp://10.0.2.2:8082/v2
.
Mock Server Standalone¶
Mock server can be run in standalone mode to point to an existing backend as proxy
Update
REMOTE_MDS_URL
andREMOTE_DMS_URL
indocker-compose-standalone.yaml
.Start/stop service using docker compose:
cd mockserver docker compose -f docker-compose-standalone.yaml up --build -d docker compose -f docker-compose-standalone.yaml down -v
Mock Server configuration¶
Create a mock response
POST /mocker/expectation Body: { "path": "/abc/test", # required "response_delay": 2000, # in ms "status_code": 404, # if not provided, will just add response_delay to the proxied request "body": {}, "headers": {}, "repeat_count": 4 # mock this response for 4 times and then forget the mock and start forwarding }
Delete a mock response
DELETE /mocker/expectation Body: { "path": "/abc/test" # required }
List mock responses
GET /mocker/expectations
Delete all mock responses
POST /mocker/reset