JMAP Registry API implementation - part 4

This commit is contained in:
mdecimus
2026-02-26 18:11:41 +01:00
parent f16e737221
commit e24b595a16
44 changed files with 1562 additions and 1718 deletions

View File

@@ -628,11 +628,9 @@ pub fn spawn_housekeeper(inner: Arc<Inner>, mut rx: mpsc::Receiver<HousekeeperEv
let metrics_store = server.core.storage.metrics.clone();
let metrics_history = metrics_history.clone();
let core = server.core.clone();
tokio::spawn(async move {
if let Err(err) = metrics_store
.write_metrics(core, now(), metrics_history)
.await
if let Err(err) =
metrics_store.write_metrics(None, metrics_history).await
{
trc::error!(err.details("Failed to write metrics"));
}

View File

@@ -393,9 +393,21 @@ impl ReindexIndexTask for Server {
}
}
SearchIndex::Tracing => {
// SPDX-SnippetBegin
// SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
// SPDX-License-Identifier: LicenseRef-SEL
let mut spans = Vec::new();
self.store()
.iterate(
IterateParams::new(
ValueKey::from(ValueClass::Telemetry(TelemetryClass::Span(0))),
ValueKey::from(ValueClass::Telemetry(TelemetryClass::Span(u64::MAX))),
)
.no_values(),
|key, _| {
spans.push(key.deserialize_be_u64(0)?);
Ok(true)
},
)
.await
.caused_by(trc::location!())?;
let mut batch = BatchBuilder::new();
for span_id in spans {
@@ -542,24 +554,17 @@ async fn build_tracing_span_document(
server: &Server,
span_id: u64,
) -> trc::Result<Option<IndexDocument>> {
use common::telemetry::tracers::store::{TracingStore, build_span_document};
use common::telemetry::tracers::store::build_span_document;
use registry::schema::structs::Trace;
let Some(index_fields) = server.core.email.index_fields.get(&SearchIndex::Tracing) else {
return Ok(None);
};
let Some(store) = server
.core
.enterprise
.as_ref()
.and_then(|e| e.trace_store.as_ref())
else {
return Ok(None);
};
let span = server.tracing_store().get_span(span_id).await?;
if !span.is_empty() {
Ok(Some(build_span_document(span_id, span, index_fields)))
if let Some(index_fields) = server.core.email.index_fields.get(&SearchIndex::Tracing) {
server
.tracing_store()
.get_value::<Trace>(ValueKey::from(ValueClass::Telemetry(TelemetryClass::Span(
span_id,
))))
.await
.map(|trace| trace.map(|trace| build_span_document(span_id, trace, index_fields)))
} else {
Ok(None)
}

View File

@@ -8,6 +8,7 @@ use crate::task_manager::imip::SendImipTask;
use crate::task_manager::index::SearchIndexTask;
use crate::task_manager::lock::TaskLockManager;
use crate::task_manager::merge_threads::MergeThreadsTask;
use crate::task_manager::report::SubmitReportTask;
use alarm::SendAlarmTask;
use common::config::server::ServerProtocol;
use common::network::limiter::ConcurrencyLimiter;
@@ -43,6 +44,7 @@ pub mod imip;
pub mod index;
pub mod lock;
pub mod merge_threads;
pub mod report;
const QUEUE_REFRESH_INTERVAL: u64 = 60 * 5; // 5 minutes
const DEFAULT_LOCK_EXPIRY: u64 = 60 * 5; // 5 minutes
@@ -207,6 +209,16 @@ pub fn spawn_task_manager(inner: Arc<Inner>) {
server.send_imip(task, server_instance.clone()).await
}
Task::MergeThreads(task) => server.merge_threads(task).await,
Task::DmarcReport(task) => {
server
.submit_report(report::ReportId::Dmarc(task.report_id.id()))
.await
}
Task::TlsReport(task) => {
server
.submit_report(report::ReportId::Tls(task.report_id.id()))
.await
}
Task::IndexDocument(_)
| Task::UnindexDocument(_)
| Task::IndexTrace(_) => unreachable!(),
@@ -385,6 +397,7 @@ impl TaskQueueManager for Server {
TaskType::MergeThreads => roles
.merge_threads
.is_enabled_for_integer(task_job.id as u32),
TaskType::DmarcReport | TaskType::TlsReport => true,
};
if enabled {
@@ -569,6 +582,8 @@ impl TaskInfo for Task {
Task::CalendarAlarmNotification(_) => "CalendarAlarmNotification",
Task::CalendarItipMessage(_) => "CalendarItipMessage",
Task::MergeThreads(_) => "MergeThreads",
Task::DmarcReport(_) => "DmarcReport",
Task::TlsReport(_) => "TlsReport",
}
}
}

View File

@@ -0,0 +1,44 @@
/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use crate::task_manager::TaskResult;
use common::Server;
use smtp::reporting::{dmarc::DmarcReporting, tls::TlsReporting};
pub enum ReportId {
Dmarc(u64),
Tls(u64),
}
pub(crate) trait SubmitReportTask: Sync + Send {
fn submit_report(&self, report_id: ReportId) -> impl Future<Output = TaskResult> + Send;
}
impl SubmitReportTask for Server {
async fn submit_report(&self, report_id: ReportId) -> TaskResult {
match submit_report(self, report_id).await {
Ok(result) => result,
Err(err) => {
let result = TaskResult::temporary(err.to_string());
trc::error!(err.details("Failed to submit report"));
result
}
}
}
}
async fn submit_report(server: &Server, report_id: ReportId) -> trc::Result<TaskResult> {
match report_id {
ReportId::Dmarc(item_id) => server
.send_dmarc_aggregate_report(item_id)
.await
.map(|_| TaskResult::Success),
ReportId::Tls(item_id) => server
.send_tls_aggregate_report(item_id)
.await
.map(|_| TaskResult::Success),
}
}