Skip to content

Commit a7db507

Browse files
authored
Merge pull request #535 from AmbireTech/sentry-uses-axum
Sentry - use axum framework
2 parents 38384bd + e866f4d commit a7db507

25 files changed

+2568
-3038
lines changed

Cargo.lock

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

adview-manager/src/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl Manager {
345345
.filter(|x| !(self.options.disabled_video && is_video(&x.0.unit)))
346346
.collect::<Vec<_>>();
347347

348-
units_with_price.sort_by(|b, a| match (&a.0.price).cmp(&b.0.price) {
348+
units_with_price.sort_by(|b, a| match a.0.price.cmp(&b.0.price) {
349349
Ordering::Equal => randomized_sort_pos(&a.0.unit, seed.clone())
350350
.cmp(&randomized_sort_pos(&b.0.unit, seed.clone())),
351351
ordering => ordering,

docker-compose.harness.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ services:
1313
POSTGRES_USER: 'postgres'
1414
POSTGRES_PASSWORD: 'postgres'
1515
# harness_* databases are used by the `test_harness` crate for testing
16-
# `sentry_leader` is the default database used by `sentry` for running tests
16+
# `sentry_leader` is the default database used by `sentry` for running tests and the leader
17+
# `sentry_leader` is for running the local follower when maunally testing
1718
# `primitives` is used for running tests in the `primitives` crate
18-
POSTGRES_MULTIPLE_DATABASES: harness_leader,harness_follower,sentry_leader,primitives
19+
POSTGRES_MULTIPLE_DATABASES: harness_leader,harness_follower,sentry_leader,sentry_follower,primitives
1920
networks:
2021
- adex-external
2122

primitives/examples/channel_pay_request.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use primitives::sentry::ChannelPayRequest;
22
use serde_json::json;
3-
use std::str::FromStr;
43

54
fn main() {
65
let channel_pay_json = json!({

primitives/src/analytics.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ pub mod query;
103103
#[derive(Debug, Serialize, Deserialize, Clone)]
104104
#[serde(rename_all = "camelCase")]
105105
pub struct AnalyticsQuery {
106+
/// Default: `100`
106107
#[serde(default = "default_limit")]
107108
pub limit: u32,
109+
/// Default: [`EventType::Impression`]
108110
#[serde(default = "default_event_type")]
109111
pub event_type: EventType,
112+
// Default: [`Metric::Count`]
110113
#[serde(default = "default_metric")]
111114
pub metric: Metric,
112115
pub segment_by: Option<AllowedKey>,
@@ -125,6 +128,28 @@ pub struct AnalyticsQuery {
125128
pub chains: Vec<ChainId>,
126129
}
127130

131+
impl Default for AnalyticsQuery {
132+
fn default() -> Self {
133+
Self {
134+
limit: default_limit(),
135+
event_type: default_event_type(),
136+
metric: default_metric(),
137+
segment_by: None,
138+
time: Time::default(),
139+
campaign_id: None,
140+
ad_unit: None,
141+
ad_slot: None,
142+
ad_slot_type: None,
143+
advertiser: None,
144+
publisher: None,
145+
hostname: None,
146+
country: None,
147+
os_name: None,
148+
chains: Vec::new(),
149+
}
150+
}
151+
}
152+
128153
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Display, Hash, Eq)]
129154
#[serde(untagged, into = "String", from = "String")]
130155
pub enum OperatingSystem {

primitives/src/analytics/query.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ pub struct Time {
107107
// #[serde(default = "default_timezone_utc")]
108108
// pub timezone: Tz,//: chrono::TimeZone,
109109
}
110+
111+
impl Default for Time {
112+
fn default() -> Self {
113+
let timeframe = Timeframe::Day;
114+
let start = DateHour::now() - &timeframe;
115+
116+
Self {
117+
timeframe,
118+
start,
119+
end: None,
120+
}
121+
}
122+
}
123+
110124
mod de {
111125
use crate::{analytics::Timeframe, sentry::DateHour};
112126

@@ -211,6 +225,12 @@ mod test {
211225
let empty = json!({});
212226

213227
let time = from_value::<Time>(empty).expect("Should use defaults on empty JSON");
228+
let default = Time::default();
229+
pretty_assertions::assert_eq!(
230+
time,
231+
default,
232+
"Default should generate the same as the default deserialization values!"
233+
);
214234
pretty_assertions::assert_eq!(
215235
time,
216236
Time {

primitives/src/sentry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub use event::{Event, EventType, CLICK, IMPRESSION};
2424
#[serde(rename_all = "camelCase")]
2525
/// Channel Accounting response
2626
///
27-
/// A collection of all `Accounting`s for a specific [`Channel`](`crate::Channel`)
27+
/// A collection of all `Accounting`s for a specific [`Channel`](crate::Channel)
2828
///
2929
/// # Examples
3030
///
@@ -669,14 +669,14 @@ pub struct AllSpendersQuery {
669669
pub page: u64,
670670
}
671671

672-
/// Payouts to be performed for the given [`Channel`](`crate::Channel`).
672+
/// Payouts to be performed for the given [`Channel`](crate::Channel).
673673
///
674674
/// # Examples
675675
///
676676
/// ```
677677
#[doc = include_str!("../examples/channel_pay_request.rs")]
678678
/// ```
679-
#[derive(Debug, Serialize, Deserialize)]
679+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
680680
pub struct ChannelPayRequest {
681681
pub payouts: UnifiedMap,
682682
}

primitives/src/targeting/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub type Map = serde_json::Map<String, serde_json::Value>;
1414

1515
pub mod field;
1616

17-
#[derive(Debug, Clone, Deserialize, PartialEq)]
17+
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
1818
#[serde(untagged)]
1919
pub enum Get<G, V> {
2020
#[serde(skip_deserializing)]

primitives/src/util/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858
self.decorator.with_record(record, values, |decorator| {
5959
let indent = {
6060
let mut history_ref = self.history.borrow_mut();
61-
let mut serializer = CompactFormatSerializer::new(decorator, &mut *history_ref);
61+
let mut serializer = CompactFormatSerializer::new(decorator, &mut history_ref);
6262

6363
values.serialize(record, &mut serializer)?;
6464

sentry/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ hex = "0.4"
4141
# CLI
4242
clap = { version = "3", features = ["cargo"] }
4343
# Server
44+
axum = { version = "0.5", features = ["http1", "http2", "headers"] }
45+
axum-server = { version = "0.4", features = ["tls-rustls"] }
46+
tower = "0.4"
47+
tower-http = { version = "0.3", features = ["cors"] }
4448
tokio = { version = "1", features = ["macros", "time", "rt-multi-thread", "signal"] }
45-
hyper = { version = "0.14", features = ["stream", "runtime", "http1", "http2", "server"] }
46-
simple-hyper-server-tls = { version = "0.3", features = ["tls-rustls"] }
47-
regex = "1"
49+
4850
# Database
4951
redis = { version = "0.21", features = ["aio", "tokio-comp"] }
5052
deadpool = "0.9"
@@ -81,3 +83,6 @@ pretty_assertions = "1"
8183

8284
primitives = { path = "../primitives", features = ["postgres", "test-util"] }
8385
adapter = { version = "0.2", path = "../adapter", features = ["test-util"] }
86+
87+
# we only require `hyper` for `hyper::body::to_bytes` function
88+
hyper = { version = "0.14", default-features = false }

0 commit comments

Comments
 (0)