Skip to content

Commit 625154c

Browse files
authored
Merge branch 'master' into release/0.1
2 parents 071e52a + f7eab16 commit 625154c

File tree

11 files changed

+88
-49
lines changed

11 files changed

+88
-49
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ and can be run against a local server, e.g.:
3232
$ export SYNC_DATABASE_URL=mysql://<YOUR_MYSQL_USERNAME>:<YOUR_MYSQL_PASSWORD>@localhost/syncstorage
3333
$ cargo run
3434
35+
## Logging
36+
37+
If you want to connect to the existing [Sentry project](https://sentry.prod.mozaws.net/operations/syncstorage-dev/) for local development, login to Sentry, and go to the page with [api keys](https://sentry.prod.mozaws.net/settings/operations/syncstorage-dev/keys/). Copy the `DSN` value, and `export SENTRY_DSN=DSN_VALUE_GOES_HERE` to the environment when running this project.
38+
3539
## Running the Unit tests
3640
3741
1) Run:

db-tests/Cargo.lock

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db-tests/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ edition = "2018"
66

77
[dependencies]
88
codegen = { version = "0.1.0", path = "../codegen" }
9-
env_logger = "0.6.1"
9+
env_logger = "0.7.0"
1010
futures-preview = { git = "https://github.com/rust-lang-nursery/futures-rs", rev = "744ece9", features = ["compat"] }
11-
lazy_static = "1.3.0"
12-
rand = "0.6.5"
11+
lazy_static = "1.4.0"
12+
log="0.4"
13+
rand = "0.7.2"
1314
syncstorage = { version = "0.1.0", path = "../", features = ["db_test"] }
1415

db-tests/src/batch.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use futures::compat::Future01CompatExt;
22

33
use codegen::async_test;
4+
use log::debug;
5+
46
use syncstorage::{
57
db::{error::DbErrorKind, params, util::SyncTimestamp, BATCH_LIFETIME},
68
error::ApiErrorKind,
@@ -141,7 +143,7 @@ async fn append_commit() -> Result<()> {
141143
.compat()
142144
.await?;
143145

144-
dbg!("result", &result);
146+
debug!("result: {:?}", &result);
145147
assert!(result.success.contains(&"b0".to_owned()));
146148
assert!(result.success.contains(&"b2".to_owned()));
147149

spanner-2019-10-01.ddl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1+
-- fxa_uid: a 16 byte identifier, randomly generated by the fxa server
2+
-- usually a UUID, so presuming a formatted form.
3+
-- fxa_kid: <`mono_num`>-<`client_state`>
4+
--
5+
-- - mono_num: a monotonically increasing timestamp or generation number
6+
-- in hex and padded to 13 digits, provided by the fxa server
7+
-- - client_state: the first 16 bytes of a SHA256 hash of the user's sync
8+
-- encryption key.
9+
--
10+
-- NOTE: DO NOT INCLUDE COMMENTS IF PASTING INTO CONSOLE
11+
-- ALSO, CONSOLE WANTS ONE SPACE BETWEEN DDL COMMANDS
12+
113
CREATE TABLE user_collections (
2-
fxa_uid STRING(MAX) NOT NULL,
3-
fxa_kid STRING(MAX) NOT NULL,
14+
fxa_uid STRING(36) NOT NULL,
15+
fxa_kid STRING(48) NOT NULL,
416
collection_id INT64 NOT NULL,
517
modified TIMESTAMP NOT NULL,
618
) PRIMARY KEY(fxa_uid, fxa_kid, collection_id);
719

8-
920
CREATE TABLE bso (
10-
fxa_uid STRING(MAX) NOT NULL,
11-
fxa_kid STRING(MAX) NOT NULL,
21+
fxa_uid STRING(36) NOT NULL,
22+
fxa_kid STRING(48) NOT NULL,
1223
collection_id INT64 NOT NULL,
13-
id STRING(MAX) NOT NULL,
14-
24+
id STRING(64) NOT NULL,
1525
sortindex INT64,
16-
1726
payload STRING(MAX) NOT NULL,
18-
1927
modified TIMESTAMP NOT NULL,
2028
expiry TIMESTAMP NOT NULL,
2129
) PRIMARY KEY(fxa_uid, fxa_kid, collection_id, id),
@@ -28,19 +36,17 @@ INTERLEAVE IN user_collections;
2836
CREATE INDEX BsoExpiry
2937
ON bso(expiry);
3038

31-
3239
CREATE TABLE collections (
3340
id INT64 NOT NULL,
34-
name STRING(MAX) NOT NULL,
41+
name STRING(32) NOT NULL,
3542
) PRIMARY KEY(id);
3643

3744
CREATE UNIQUE INDEX CollectionName
3845
ON collections(name);
3946

40-
4147
CREATE TABLE batches (
42-
fxa_uid STRING(MAX) NOT NULL,
43-
fxa_kid STRING(MAX) NOT NULL,
48+
fxa_uid STRING(36) NOT NULL,
49+
fxa_kid STRING(48) NOT NULL,
4450
id TIMESTAMP NOT NULL,
4551
collection_id INT64 NOT NULL,
4652
bsos STRING(MAX) NOT NULL,

src/db/spanner/models.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use futures::future;
22
use futures::lazy;
33

44
use diesel::r2d2::PooledConnection;
5+
use log::debug;
56

67
use std::cell::RefCell;
78
use std::collections::HashMap;
@@ -439,7 +440,10 @@ impl SpannerDb {
439440
&self,
440441
params: params::GetCollectionTimestamp,
441442
) -> Result<SyncTimestamp> {
442-
dbg!("!!QQQ get_collection_timestamp_sync", &params.collection);
443+
debug!(
444+
"!!QQQ get_collection_timestamp_sync {:?}",
445+
&params.collection
446+
);
443447

444448
let collection_id = self.get_collection_id(&params.collection)?;
445449
if let Some(modified) = self
@@ -1005,7 +1009,7 @@ impl SpannerDb {
10051009
}
10061010

10071011
pub fn get_bso_timestamp_sync(&self, params: params::GetBsoTimestamp) -> Result<SyncTimestamp> {
1008-
dbg!("!!QQQ get_bso_timestamp_sync", &params.collection);
1012+
debug!("!!QQQ get_bso_timestamp_sync: {:?}", &params.collection);
10091013
let collection_id = self.get_collection_id(&params.collection)?;
10101014

10111015
let result = self
@@ -1099,7 +1103,7 @@ impl SpannerDb {
10991103
}
11001104

11011105
if !inserts.is_empty() {
1102-
dbg!(&inserts);
1106+
debug!("inserts: {:?}", &inserts);
11031107
self.insert(
11041108
"bso",
11051109
&[
@@ -1116,7 +1120,7 @@ impl SpannerDb {
11161120
);
11171121
}
11181122
for (columns, values) in updates {
1119-
dbg!(&columns, &values);
1123+
debug!("columns: {:?}, values:{:?}", &columns, &values);
11201124
self.update("bso", &columns, values);
11211125
}
11221126

@@ -1266,7 +1270,10 @@ impl SpannerDb {
12661270
.map_or(i64::from(DEFAULT_BSO_TTL), |ttl| ttl.try_into().unwrap())
12671271
* 1000;
12681272
let expirystring = to_rfc3339(now_millis + ttl)?;
1269-
dbg!("!!!!! INSERT", &expirystring, timestamp, ttl);
1273+
debug!(
1274+
"!!!!! INSERT expirystring:{:?}, timestamp:{:?}, ttl:{:?}",
1275+
&expirystring, timestamp, ttl
1276+
);
12701277
sqlparams.insert("expiry".to_string(), as_value(expirystring));
12711278
sqltypes.insert("expiry".to_string(), SpannerType::Timestamp.into());
12721279

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::error::Error;
33

44
use docopt::Docopt;
5-
use log::info;
5+
use log::{debug, info};
66
use serde_derive::Deserialize;
77

88
use syncstorage::{logging, server, settings};
@@ -22,6 +22,7 @@ struct Args {
2222

2323
fn main() -> Result<(), Box<dyn Error>> {
2424
env_logger::init();
25+
debug!("Starting up...");
2526
// Set SENTRY_DSN environment variable to enable Sentry
2627
let sentry = sentry::init(sentry::ClientOptions::default());
2728
if sentry.is_enabled() {

src/server/metrics.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::net::UdpSocket;
22

33
use actix_web::{error::ErrorInternalServerError, Error, HttpRequest};
44
use cadence::{BufferedUdpMetricSink, Counted, NopMetricSink, QueuingMetricSink, StatsdClient};
5+
use log::debug;
56

67
use crate::error::ApiError;
78
use crate::server::ServerState;
@@ -18,7 +19,7 @@ impl From<&HttpRequest> for Metrics {
1819
client: match req.app_data::<ServerState>() {
1920
Some(v) => Some(*v.metrics.clone()),
2021
None => {
21-
dbg!("⚠️ metric error: No App State");
22+
debug!("⚠️ metric error: No App State");
2223
None
2324
}
2425
},
@@ -45,7 +46,7 @@ impl Metrics {
4546
match self.client.unwrap().incr(label) {
4647
Err(e) => {
4748
// eat the metric, but log the error
48-
dbg!("⚠️ Metric {} error: {:?} ", label, e);
49+
debug!("⚠️ Metric {} error: {:?} ", label, e);
4950
}
5051
Ok(_v) => {
5152
// v.as_metric_str()
@@ -79,7 +80,7 @@ pub fn metrics_from_opts(opts: &Settings) -> Result<StatsdClient, ApiError> {
7980
};
8081
Ok(builder
8182
.with_error_handler(|err| {
82-
dbg!("⚠️ Metric send error:", err);
83+
debug!("⚠️ Metric send error: {:?}", err);
8384
})
8485
.build())
8586
}

src/settings.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Application settings objects and initialization
22
33
use config::{Config, ConfigError, Environment, File};
4+
use log::debug;
45
use serde::{de::Deserializer, Deserialize, Serialize};
56
use url::Url;
67

@@ -118,11 +119,11 @@ impl Settings {
118119
"For example to set `database_url` use env var `{}_DATABASE_URL`\n",
119120
PREFIX.to_uppercase()
120121
);
121-
dbg!("⚠️ Configuration error: Value undefined", &v);
122+
debug!("⚠️ Configuration error: Value undefined {:?}", &v);
122123
return Err(ConfigError::NotFound(v));
123124
}
124125
_ => {
125-
dbg!("⚠️ Other: ", &e);
126+
debug!("⚠️ Other: {:?}", &e);
126127
return Err(e);
127128
}
128129
},

src/web/extractors.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use actix_web::{
1616
};
1717
use futures::{future, Future};
1818
use lazy_static::lazy_static;
19+
use log::debug;
1920
use regex::Regex;
2021
use serde::{
2122
de::{Deserializer, Error as SerdeError, IgnoredAny},
@@ -120,7 +121,7 @@ impl FromRequest for BsoBodies {
120121
let default = HeaderValue::from_static("");
121122
let content_type = get_trimmed_header(headers, CONTENT_TYPE, &default);
122123

123-
dbg!(&content_type);
124+
debug!("content_type: {:?}", &content_type);
124125

125126
match content_type.as_str() {
126127
"application/json" | "text/plain" | "application/newlines" | "" => (),
@@ -138,7 +139,7 @@ impl FromRequest for BsoBodies {
138139

139140
// Load the entire request into a String
140141
let fut = <String>::from_request(req, payload).map_err(|e| {
141-
dbg!("⚠️ Payload read error", e);
142+
debug!("⚠️ Payload read error: {:?}", e);
142143
ValidationErrorKind::FromDetails(
143144
"Mimetype/encoding/content-length error".to_owned(),
144145
RequestErrorLocation::Header,
@@ -165,7 +166,7 @@ impl FromRequest for BsoBodies {
165166
let state = match req.app_data::<ServerState>() {
166167
Some(s) => s,
167168
None => {
168-
dbg!("⚠️ Could not load the app state");
169+
debug!("⚠️ Could not load the app state");
169170
return Box::new(future::err(
170171
ValidationErrorKind::FromDetails(
171172
"Internal error".to_owned(),
@@ -315,7 +316,7 @@ impl FromRequest for BsoBody {
315316
let state = match req.app_data::<ServerState>() {
316317
Some(s) => s,
317318
None => {
318-
dbg!("⚠️ Could not load the app state");
319+
debug!("⚠️ Could not load the app state");
319320
return Box::new(future::err(
320321
ValidationErrorKind::FromDetails(
321322
"Internal error".to_owned(),
@@ -391,7 +392,7 @@ impl BsoParam {
391392
}
392393
if let Some(v) = elements.get(5) {
393394
let sv = String::from_str(v).map_err(|e| {
394-
dbg!("⚠️ BsoParam Error", v, e);
395+
debug!("⚠️ BsoParam Error element:{:?} error:{:?}", v, e);
395396
ValidationErrorKind::FromDetails(
396397
"Invalid BSO".to_owned(),
397398
RequestErrorLocation::Path,
@@ -615,7 +616,7 @@ impl FromRequest for CollectionPostRequest {
615616
let state = match req.app_data::<ServerState>() {
616617
Some(s) => s,
617618
None => {
618-
dbg!("⚠️ Could not load the app state");
619+
debug!("⚠️ Could not load the app state");
619620
return Box::new(future::err(
620621
ValidationErrorKind::FromDetails(
621622
"Internal error".to_owned(),
@@ -798,7 +799,7 @@ impl FromRequest for ConfigRequest {
798799
let state = match req.app_data::<ServerState>() {
799800
Some(s) => s,
800801
None => {
801-
dbg!("⚠️ Could not load the app state");
802+
debug!("⚠️ Could not load the app state");
802803
return Err(ValidationErrorKind::FromDetails(
803804
"Internal error".to_owned(),
804805
RequestErrorLocation::Unknown,
@@ -859,7 +860,7 @@ impl HawkIdentifier {
859860
let elements: Vec<&str> = uri.path().split('/').collect();
860861
if let Some(v) = elements.get(2) {
861862
u64::from_str(v).map_err(|e| {
862-
dbg!("⚠️ HawkIdentifier Error", v, e);
863+
debug!("⚠️ HawkIdentifier Error {:?} {:?}", v, e);
863864
ValidationErrorKind::FromDetails(
864865
"Invalid UID".to_owned(),
865866
RequestErrorLocation::Path,
@@ -936,7 +937,7 @@ impl FromRequest for HawkIdentifier {
936937
let state = match req.app_data::<ServerState>() {
937938
Some(s) => s,
938939
None => {
939-
dbg!("⚠️ Could not load the app state");
940+
debug!("⚠️ Could not load the app state");
940941
return Err(ValidationErrorKind::FromDetails(
941942
"Internal error".to_owned(),
942943
RequestErrorLocation::Unknown,
@@ -964,7 +965,7 @@ impl From<u32> for HawkIdentifier {
964965

965966
pub fn extrude_db(exts: &Extensions) -> Result<Box<dyn Db>, Error> {
966967
exts.get::<Box<dyn Db>>().cloned().ok_or_else(|| {
967-
dbg!("⚠️ DB Error: No db");
968+
debug!("⚠️ DB Error: No db");
968969
ErrorInternalServerError("Unexpected Db error: No DB".to_owned())
969970
})
970971
}
@@ -1074,7 +1075,7 @@ impl FromRequest for BatchRequestOpt {
10741075
let state = match req.app_data::<ServerState>() {
10751076
Some(s) => s,
10761077
None => {
1077-
dbg!("⚠️ Could not load the app state");
1078+
debug!("⚠️ Could not load the app state");
10781079
return Err(ValidationErrorKind::FromDetails(
10791080
"Internal error".to_owned(),
10801081
RequestErrorLocation::Unknown,

0 commit comments

Comments
 (0)