Sync Storage server in Rust
Go to file
2019-11-21 16:32:29 -05:00
.circleci chore: point to mozilla-services/mozilla-rust-sdk 2019-11-14 15:10:25 -08:00
codegen test: convert the db_tests to async/await 2019-06-27 12:40:40 -07:00
config docs: adjust PR template, finish combining READMEs 2019-11-21 16:20:57 -05:00
db-tests Merge branch 'master' of github.com:mozilla-services/syncstorage-rs into feat/329 2019-11-14 16:38:10 -08:00
docs docs: combining setup instructions into one main doc 2019-11-19 16:43:26 -05:00
migrations fix: get the session timestamp from Spanner 2019-09-26 13:28:51 -07:00
scripts fix: use single = for equality test in docs script 2018-10-16 18:19:58 +01:00
src fix: correct max_total_records 2019-11-15 16:21:14 -08:00
tools f r's 2019-11-11 15:37:57 -08:00
.clog.toml chore: tag 0.1.0 2019-10-04 16:32:16 -07:00
.gitignore docs: combining setup instructions into one main doc 2019-11-19 16:43:26 -05:00
.travis.yml Feat/126 (#185) 2019-08-06 16:26:53 -07:00
Cargo.lock chore: tag 0.1.7 2019-11-15 17:18:06 -08:00
Cargo.toml chore: tag 0.1.7 2019-11-15 17:18:06 -08:00
CHANGELOG.md chore: tag 0.1.7 2019-11-15 17:18:06 -08:00
CODE_OF_CONDUCT.md Add Mozilla Code of Conduct file 2019-03-27 19:32:50 -07:00
CONTRIBUTING.md docs: adjust PR template, finish combining READMEs 2019-11-21 16:20:57 -05:00
docker-compose.e2e.yaml Feat/126 (#185) 2019-08-06 16:26:53 -07:00
docker-compose.yaml test: run unit & e2e tests on circleci 2019-06-11 14:07:26 -07:00
Dockerfile chore: Update dockerfile to rust 1.39 2019-11-11 08:21:50 -08:00
LICENSE chore: initial files 2018-07-20 15:28:46 -07:00
Makefile chore: fix syntax and make one small formatting change to PR template 2019-11-21 16:32:29 -05:00
PULL_REQUEST_TEMPLATE.md chore: fix syntax and make one small formatting change to PR template 2019-11-21 16:32:29 -05:00
README.md docs: adjust PR template, finish combining READMEs 2019-11-21 16:20:57 -05:00
spanner_config.ini fix: correct max_total_records 2019-11-15 16:21:14 -08:00
spanner-2019-10-01.ddl fix: correct max_total_records 2019-11-15 16:21:14 -08:00
version.json feat: Add docker config (#140) 2019-06-04 10:06:13 -07:00

License: MPL 2.0 Test Status Build Status

Syncstorage-rs

Mozilla Sync Storage built with Rust.

System Requirements

  • Rust stable
  • MySQL 5.7 (or compatible) -* libmysqlclient (brew install mysql on macOS, apt-get install libmysqlclient-dev on Ubuntu)
  • Go

Depending on your OS, you may also need to install libgrpcdev, and protobuf-compiler-grpc.

Local Setup

  1. Follow the instructions below to use either MySQL or Spanner as your DB.
  2. Now cp config/local.example.toml config/local.toml. Open config/local.toml and make sure you have the desired settings configured. For a complete list of available configuration options, check out docs/config.md.
  3. make run-local starts the server in debug mode, using your new local.toml file for config options. Or, simply cargo run with your own config options provided as env vars.
  4. Visit http://localhost:8000/__heartbeat__ to make sure the server is running.

MySQL

Durable sync needs only a valid mysql DSN in order to set up connections to a MySQL database. The database can be local and is usually specified with a DSN like:

mysql://_user_:_password_@_host_/_database_

To setup a fresh MySQL DB and user: (mysql -u root):

```
CREATE USER "sample_user"@"localhost" IDENTIFIED BY "sample_password";
CREATE DATABASE syncstorage_rs;

GRANT ALL PRIVILEGES on syncstorage_rs.* to sample_user@localhost;
```

Spanner

Spanner requires a key in order to access the database. It's important that you know which keys have access to the spanner database. Contact your administrator to find out. One you know the key, log into the Google Cloud Console Service Accounts page. Be sure to select the correct project.

  • Locate the email identifier of the access key and pick the vertical dot menu at the far right of the row.
  • Select "Create Key" from the pop-up menu.
  • Select "JSON" from the Dialog Box.

A proper Key file will be downloaded to your local directory. It's important to safeguard that key file. For this example, we're going to name the file sync-spanner.json and store it in a subdirectory called ./keys

The proper key file is in JSON format. An example file is provided below, with private information replaced by "..."

{
  "type": "service_account",
  "project_id": "...",
  "private_key_id": "...",
  "private_key": "...",
  "client_email": "...",
  "client_id": "...",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "..."
}

You can then specify the path to the key file using the environment variable GOOGLE_APPLICATION_CREDENTIALS when running the application.

e.g.

RUST_LOG=warn GOOGLE_APPLICATION_CREDENTIALS=`pwd`/keys/sync-spanner.json` cargo run -- --config sync.ini

Note, that unlike MySQL, there is no automatic migrations facility. Currently Spanner schema must be hand edited and modified.

Logging

  • If you want to connect to the existing Sentry project for local development, login to Sentry, and go to the page with api keys. Copy the DSN value, and export SENTRY_DSN=DSN_VALUE_GOES_HERE to the environment when running this project.
  • Using env_logger: set the RUST_LOG env var.

Tests

Unit tests

  1. cd db-tests.
  2. Pass along your SYNC_DATABASE_URL to the test runner. Ie:
SYNC_DATABASE_URL="mysql://sample_user:sample_password@localhost/syncstorage_rs" && /
RUST_TEST_THREADS=1 && /
cargo test

End-to-End tests

Functional tests live in server-syncstorage and can be run against a local server, e.g.:

  1. If you haven't already followed the instructions here to get all the dependencies for the server-syncstorage repo, you should start there.

  2. Install (Python) server-syncstorage:

     $ git clone https://github.com/mozilla-services/server-syncstorage/
     $ cd server-syncstorage
     $ make build
    
  3. Run an instance of syncstorage-rs (cargo run in this repo).

  4. To run all tests:

     $ ./local/bin/python syncstorage/tests/functional/test_storage.py http://localhost:8000#<SOMESECRET>
    
  5. Individual tests can be specified via the SYNC_TEST_PREFIX env var:

    $ SYNC_TEST_PREFIX=test_get_collection \
        ./local/bin/python syncstorage/tests/functional/test_storage.py http://localhost:8000#<SOMESECRET>
    

Troubleshooting

  • rm Cargo.lock; cargo clean; - Try this if you're having problems compiling.