Skip to content

Commit 2837c58

Browse files
committed
merge master
2 parents 6abde91 + c01021b commit 2837c58

File tree

16 files changed

+159
-113
lines changed

16 files changed

+159
-113
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ regex = "1.4"
6565
reqwest = { version = "0.12", default-features = false, features = [
6666
"rustls-tls",
6767
] }
68-
# rev 1b65b5c includes https://github.com/getsentry/sentry-rust/pull/701
69-
# TODO: bump to 0.35 as soon as it's available
70-
sentry = { version = "0.34", git = "https://github.com/getsentry/sentry-rust", rev = "1b65b5c", default-features = false, features = [
68+
sentry = { version = "0.35", default-features = false, features = [
7169
"curl",
7270
"backtrace",
7371
"contexts",
7472
"debug-images",
7573
] }
76-
sentry-backtrace = { version = "0.34", git = "https://github.com/getsentry/sentry-rust", rev = "1b65b5c" }
74+
sentry-backtrace = "0.35"
7775
serde = "1.0"
7876
serde_derive = "1.0"
7977
serde_json = { version = "1.0", features = ["arbitrary_precision"] }

syncserver-db-common/src/error.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use http::StatusCode;
55
use syncserver_common::{from_error, impl_fmt_display, ReportableError};
66
use thiserror::Error;
77

8-
/// Error specific to any MySQL database backend. These errors are not related to the syncstorage
8+
/// Error specific to any SQL database backend. These errors are not related to the syncstorage
99
/// or tokenserver application logic; rather, they are lower-level errors arising from diesel.
1010
#[derive(Debug)]
11-
pub struct MysqlError {
12-
kind: MysqlErrorKind,
11+
pub struct SqlError {
12+
kind: SqlErrorKind,
1313
pub status: StatusCode,
1414
pub backtrace: Backtrace,
1515
}
1616

1717
#[derive(Debug, Error)]
18-
enum MysqlErrorKind {
18+
enum SqlErrorKind {
1919
#[error("A database error occurred: {}", _0)]
2020
DieselQuery(#[from] diesel::result::Error),
2121

@@ -29,8 +29,8 @@ enum MysqlErrorKind {
2929
Migration(diesel_migrations::RunMigrationsError),
3030
}
3131

32-
impl From<MysqlErrorKind> for MysqlError {
33-
fn from(kind: MysqlErrorKind) -> Self {
32+
impl From<SqlErrorKind> for SqlError {
33+
fn from(kind: SqlErrorKind) -> Self {
3434
Self {
3535
kind,
3636
status: StatusCode::INTERNAL_SERVER_ERROR,
@@ -39,22 +39,22 @@ impl From<MysqlErrorKind> for MysqlError {
3939
}
4040
}
4141

42-
impl ReportableError for MysqlError {
42+
impl ReportableError for SqlError {
4343
fn is_sentry_event(&self) -> bool {
4444
#[allow(clippy::match_like_matches_macro)]
4545
match &self.kind {
46-
MysqlErrorKind::Pool(_) => false,
46+
SqlErrorKind::Pool(_) => false,
4747
_ => true,
4848
}
4949
}
5050

5151
fn metric_label(&self) -> Option<String> {
5252
Some(
5353
match self.kind {
54-
MysqlErrorKind::DieselQuery(_) => "storage.mysql.error.diesel_query",
55-
MysqlErrorKind::DieselConnection(_) => "storage.mysql.error.diesel_connection",
56-
MysqlErrorKind::Pool(_) => "storage.mysql.error.pool",
57-
MysqlErrorKind::Migration(_) => "storage.mysql.error.migration",
54+
SqlErrorKind::DieselQuery(_) => "storage.sql.error.diesel_query",
55+
SqlErrorKind::DieselConnection(_) => "storage.sql.error.diesel_connection",
56+
SqlErrorKind::Pool(_) => "storage.sql.error.pool",
57+
SqlErrorKind::Migration(_) => "storage.sql.error.migration",
5858
}
5959
.to_string(),
6060
)
@@ -65,21 +65,17 @@ impl ReportableError for MysqlError {
6565
}
6666
}
6767

68-
impl_fmt_display!(MysqlError, MysqlErrorKind);
68+
impl_fmt_display!(SqlError, SqlErrorKind);
6969

70-
from_error!(
71-
diesel::result::Error,
72-
MysqlError,
73-
MysqlErrorKind::DieselQuery
74-
);
70+
from_error!(diesel::result::Error, SqlError, SqlErrorKind::DieselQuery);
7571
from_error!(
7672
diesel::result::ConnectionError,
77-
MysqlError,
78-
MysqlErrorKind::DieselConnection
73+
SqlError,
74+
SqlErrorKind::DieselConnection
7975
);
80-
from_error!(diesel::r2d2::PoolError, MysqlError, MysqlErrorKind::Pool);
76+
from_error!(diesel::r2d2::PoolError, SqlError, SqlErrorKind::Pool);
8177
from_error!(
8278
diesel_migrations::RunMigrationsError,
83-
MysqlError,
84-
MysqlErrorKind::Migration
79+
SqlError,
80+
SqlErrorKind::Migration
8581
);

syncserver/src/server/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ impl Server {
273273
&Metrics::from(&metrics),
274274
blocking_threadpool.clone(),
275275
)?;
276+
// Spawns sweeper that calls Deadpool `retain` method, clearing unused connections.
277+
db_pool.spawn_sweeper(Duration::from_secs(
278+
settings
279+
.syncstorage
280+
.database_pool_sweeper_task_interval
281+
.into(),
282+
));
276283
let glean_logger = Arc::new(GleanEventsLogger {
277284
// app_id corresponds to probe-scraper entry.
278285
// https://github.com/mozilla/probe-scraper/blob/main/repositories.yaml

syncserver/src/web/handlers.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,33 @@ pub async fn get_collections(
4040
request: HttpRequest,
4141
state: Data<ServerState>,
4242
) -> Result<HttpResponse, ApiError> {
43-
if state.glean_enabled {
44-
// Values below are be passed to the Glean logic to emit metrics.
45-
// This is used to measure DAU (Daily Active Use) of Sync.
46-
let user_agent = request
47-
.headers()
48-
.get(header::USER_AGENT)
49-
.and_then(|header| header.to_str().ok())
50-
.unwrap_or("");
51-
let device_info: DeviceInfo = get_device_info(user_agent);
52-
53-
state.glean_logger.record_events_ping(
54-
&RequestInfo {
55-
user_agent: user_agent.to_owned(),
56-
ip_address: "".to_owned(),
57-
},
58-
&EventsPing {
59-
syncstorage_device_family: device_info.device_family.to_string(),
60-
syncstorage_hashed_device_id: meta.user_id.hashed_device_id.clone(),
61-
syncstorage_hashed_fxa_uid: meta.user_id.hashed_fxa_uid.clone(),
62-
syncstorage_platform: device_info.platform.to_string(),
63-
event: Some(Box::new(SyncstorageGetCollectionsEvent {})),
64-
},
65-
);
66-
}
67-
6843
db_pool
69-
.transaction_http(request, |db| async move {
44+
.transaction_http(request.clone(), |db| async move {
7045
meta.emit_api_metric("request.get_collections");
46+
if state.glean_enabled {
47+
// Values below are be passed to the Glean logic to emit metrics.
48+
// This is used to measure DAU (Daily Active Use) of Sync.
49+
let user_agent = request
50+
.headers()
51+
.get(header::USER_AGENT)
52+
.and_then(|header| header.to_str().ok())
53+
.unwrap_or("");
54+
let device_info: DeviceInfo = get_device_info(user_agent);
55+
56+
state.glean_logger.record_events_ping(
57+
&RequestInfo {
58+
user_agent: user_agent.to_owned(),
59+
ip_address: "".to_owned(),
60+
},
61+
&EventsPing {
62+
syncstorage_device_family: device_info.device_family.to_string(),
63+
syncstorage_hashed_device_id: meta.user_id.hashed_device_id.clone(),
64+
syncstorage_hashed_fxa_uid: meta.user_id.hashed_fxa_uid.clone(),
65+
syncstorage_platform: device_info.platform.to_string(),
66+
event: Some(Box::new(SyncstorageGetCollectionsEvent {})),
67+
},
68+
);
69+
}
7170
let result = db.get_collection_timestamps(meta.user_id).await?;
7271

7372
Ok(HttpResponse::build(StatusCode::OK)

syncstorage-db-common/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{convert::TryInto, u64};
1+
use std::convert::TryInto;
22

33
use chrono::{
44
offset::{FixedOffset, TimeZone, Utc},

0 commit comments

Comments
 (0)