Registry testing - part 11

This commit is contained in:
Maurus Decimus
2026-03-21 19:51:25 +01:00
parent 9b118bceef
commit 21c541e505
22 changed files with 519 additions and 464 deletions

View File

@@ -80,6 +80,7 @@ impl Data {
blocked_ips: RwLock::new(blocked_ips),
jmap_id_gen: id_generator.clone(),
queue_id_gen: id_generator.clone(),
registry_id_gen: id_generator.clone(),
span_id_gen: id_generator,
queue_status: true.into(),
applications: Default::default(),
@@ -220,6 +221,7 @@ impl Default for Data {
jmap_id_gen: Default::default(),
queue_id_gen: Default::default(),
span_id_gen: Default::default(),
registry_id_gen: Default::default(),
queue_status: true.into(),
applications: Default::default(),
logos: Default::default(),

View File

@@ -135,6 +135,10 @@ impl Scripting {
// Parse trusted scripts
let mut trusted_scripts = AHashMap::new();
for script in bp.list_infallible::<SieveSystemScript>().await {
if !script.object.is_active {
continue;
}
match trusted_compiler.compile(script.object.contents.as_bytes()) {
Ok(compiled) => {
trusted_scripts.insert(script.object.name, compiled.into());
@@ -151,6 +155,10 @@ impl Scripting {
// Parse untrusted scripts
let mut untrusted_scripts = AHashMap::new();
for script in bp.list_infallible::<SieveUserScript>().await {
if !script.object.is_active {
continue;
}
match untrusted_compiler.compile(script.object.contents.as_bytes()) {
Ok(compiled) => {
untrusted_scripts.insert(script.object.name, compiled.into());

View File

@@ -179,7 +179,7 @@ pub struct QueueQuota {
#[derive(Clone, Hash, PartialEq, Eq)]
pub struct RelayConfig {
pub address: HostOrIp<String>,
pub address: HostOrIp<Box<str>, IpStr>,
pub port: u16,
pub protocol: ServerProtocol,
pub auth: Option<Credentials<String>>,
@@ -188,9 +188,15 @@ pub struct RelayConfig {
}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum HostOrIp<T> {
Host(T),
Ip { ip: IpAddr, ip_str: String },
pub enum HostOrIp<N, I> {
Host(N),
Ip(I),
}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct IpStr {
pub ip: IpAddr,
pub ip_str: Box<str>,
}
#[derive(Debug, Clone, Copy, Default)]
@@ -375,12 +381,12 @@ impl QueueConfig {
route.name,
RoutingStrategy::Relay(RelayConfig {
address: if let Ok(ip) = route.address.parse() {
HostOrIp::Ip {
HostOrIp::Ip(IpStr {
ip,
ip_str: route.address,
}
ip_str: route.address.into(),
})
} else {
HostOrIp::Host(route.address)
HostOrIp::Host(route.address.into())
},
port: route.port as u16,
protocol: match route.protocol {

View File

@@ -154,6 +154,7 @@ pub struct Data {
pub jmap_id_gen: SnowflakeIdGenerator,
pub queue_id_gen: SnowflakeIdGenerator,
pub span_id_gen: SnowflakeIdGenerator,
pub registry_id_gen: SnowflakeIdGenerator,
pub queue_status: AtomicBool,
pub applications: WebApplicationManager,

View File

@@ -469,10 +469,7 @@ fn build_index(
let object_account_id = batch.last_account_id().unwrap_or_default();
let object_type = batch.last_collection().unwrap_or(Collection::None);
let object_id = batch.last_document_id().unwrap_or_default();
let notification_id = SnowflakeIdGenerator::from_sequence_id(
object_type as u64 ^ object_account_id as u64,
)
.unwrap_or_default();
let notification_id = SnowflakeIdGenerator::global_id().unwrap_or_default();
for item in value.as_ref() {
if set {
@@ -630,10 +627,7 @@ fn merge_index(
let object_account_id = batch.last_account_id().unwrap_or_default();
let object_type = batch.last_collection().unwrap_or(Collection::None);
let object_id = batch.last_document_id().unwrap_or_default();
let notification_id = SnowflakeIdGenerator::from_sequence_id(
object_type as u64 ^ object_account_id as u64,
)
.unwrap_or_default();
let notification_id = SnowflakeIdGenerator::global_id().unwrap_or_default();
match (has_old_acl, has_new_acl) {
(true, true) => {

View File

@@ -35,6 +35,7 @@ pub trait MetricsStore: Sync + Send {
pub struct MetricsHistory {
events: AHashMap<MetricType, u32>,
histograms: AHashMap<MetricType, HistogramHistory>,
id_generator: SnowflakeIdGenerator,
}
#[derive(Default)]
@@ -53,7 +54,7 @@ impl MetricsStore for Store {
) -> trc::Result<()> {
let mut batch = BatchBuilder::new();
{
let mut history = history_.lock();
let mut history_guard = history_.lock();
for event in [
MetricType::SmtpConnectionStart,
MetricType::ImapConnectionStart,
@@ -80,27 +81,20 @@ impl MetricsStore for Store {
] {
let reading = Collector::read_metric_counter(event.event_id());
if reading > 0 {
let history = history.events.entry(event).or_insert(0);
let history = history_guard.events.entry(event).or_insert(0);
let diff = reading - *history;
*history = reading;
if diff > 0 {
#[cfg(not(feature = "test_mode"))]
let metric_id =
SnowflakeIdGenerator::from_sequence_id(event.to_id() as u64)
.unwrap_or_default();
let metric_id = history_guard.id_generator.generate();
#[cfg(feature = "test_mode")]
let metric_id = _timestamp
.map(|timestamp| {
SnowflakeIdGenerator::from_timestamp_and_sequence_id(
timestamp,
event.to_id() as u64,
)
SnowflakeIdGenerator::global_id_from_timestamp(timestamp).unwrap()
})
.unwrap_or_else(|| {
SnowflakeIdGenerator::from_sequence_id(event.to_id() as u64)
})
.unwrap_or_default();
.unwrap_or_else(|| history_guard.id_generator.generate());
batch.set(
ValueClass::Telemetry(TelemetryClass::Metric(metric_id)),
@@ -111,7 +105,6 @@ impl MetricsStore for Store {
.to_pickled_vec(),
);
}
*history = reading;
}
}
@@ -121,22 +114,14 @@ impl MetricsStore for Store {
let value = gauge.get();
if value > 0 {
#[cfg(not(feature = "test_mode"))]
let metric_id =
SnowflakeIdGenerator::from_sequence_id(metric.to_id() as u64)
.unwrap_or_default();
let metric_id = history_guard.id_generator.generate();
#[cfg(feature = "test_mode")]
let metric_id = _timestamp
.map(|timestamp| {
SnowflakeIdGenerator::from_timestamp_and_sequence_id(
timestamp,
metric.to_id() as u64,
)
SnowflakeIdGenerator::global_id_from_timestamp(timestamp).unwrap()
})
.unwrap_or_else(|| {
SnowflakeIdGenerator::from_sequence_id(metric.to_id() as u64)
})
.unwrap_or_default();
.unwrap_or_else(|| history_guard.id_generator.generate());
batch.set(
ValueClass::Telemetry(TelemetryClass::Metric(metric_id)),
@@ -160,37 +145,29 @@ impl MetricsStore for Store {
| MetricType::DeliveryAttemptTime
| MetricType::DnsLookupTime
) {
let history = history.histograms.entry(metric).or_default();
let history = history_guard.histograms.entry(metric).or_default();
let sum = histogram.sum();
let count = histogram.count();
let diff_sum = sum - history.sum;
let diff_count = count - history.count;
history.sum = sum;
history.count = count;
if diff_sum > 0 || diff_count > 0 {
#[cfg(not(feature = "test_mode"))]
let metric_id =
SnowflakeIdGenerator::from_sequence_id(metric.to_id() as u64)
.unwrap_or_default();
let metric_id = history_guard.id_generator.generate();
#[cfg(feature = "test_mode")]
let metric_id = _timestamp
.map(|timestamp| {
SnowflakeIdGenerator::from_timestamp_and_sequence_id(
timestamp,
metric.to_id() as u64,
)
SnowflakeIdGenerator::global_id_from_timestamp(timestamp).unwrap()
})
.unwrap_or_else(|| {
SnowflakeIdGenerator::from_sequence_id(metric.to_id() as u64)
})
.unwrap_or_default();
.unwrap_or_else(|| history_guard.id_generator.generate());
batch.set(
ValueClass::Telemetry(TelemetryClass::Metric(metric_id)),
Metric::Histogram(MetricSum { count, metric, sum }).to_pickled_vec(),
);
}
history.sum = sum;
history.count = count;
}
}
}