-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of CSAF ingestion #458
Changes from all commits
c440ea0
be44178
d253538
3b54024
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod perf; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![cfg(test)] | ||
|
||
use std::time::Instant; | ||
use test_context::test_context; | ||
use test_log::test; | ||
use tracing::instrument; | ||
use trustify_common::{db::test::TrustifyContext, hashing::Digests}; | ||
use trustify_module_ingestor::{graph::Graph, service::advisory::csaf::loader::CsafLoader}; | ||
|
||
#[test_context(TrustifyContext, skip_teardown)] | ||
#[test(tokio::test)] | ||
#[instrument] | ||
async fn ingest(ctx: TrustifyContext) -> anyhow::Result<()> { | ||
let db = ctx.db; | ||
let graph = Graph::new(db.clone()); | ||
|
||
let start = Instant::now(); | ||
|
||
// let data = include_bytes!("../../../etc/test-data/csaf/CVE-2023-20862.json"); | ||
let data = include_bytes!("../../../etc/test-data/csaf/cve-2023-33201.json"); | ||
|
||
let digests = Digests::digest(data); | ||
CsafLoader::new(&graph) | ||
.load((), &data[..], &digests) | ||
.await?; | ||
|
||
let ingest_time = start.elapsed(); | ||
|
||
log::info!("ingest: {}", humantime::Duration::from(ingest_time)); | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
mod csaf; | ||
mod sbom; | ||
mod stream; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
mod graph; | ||
mod reingest; | ||
mod stream; | ||
mod test; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_index( | ||
Index::create() | ||
.table(PackageStatus::Table) | ||
.name("package_status_idx") | ||
.col(PackageStatus::PackageId) | ||
.col(PackageStatus::AdvisoryId) | ||
.col(PackageStatus::StatusId) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.table(PackageStatus::Table) | ||
.name("package_status_idx") | ||
.if_exists() | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum PackageStatus { | ||
Table, | ||
AdvisoryId, | ||
StatusId, | ||
PackageId, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ pub enum Version { | |
} | ||
|
||
impl VersionInfo { | ||
fn into_active_model(self) -> version_range::ActiveModel { | ||
pub fn into_active_model(self) -> version_range::ActiveModel { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bonus points: if you can understand why implementing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That one was a bit weird, it seems to be coming from the blanket implementation of that trait in seaorm: impl<A> IntoActiveModel<A> for A
where
A: ActiveModelTrait,
{
fn into_active_model(self) -> A {
self
}
} Which basically means that you can't implement It also doesn't seem possible to implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that's not correct. Because in this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I give up on the bonus points and leave it a mystery. |
||
version_range::ActiveModel { | ||
id: Default::default(), | ||
version_scheme_id: Set(self.scheme), | ||
|
@@ -400,6 +400,7 @@ impl<'g> AdvisoryVulnerabilityContext<'g> { | |
.map(|cvss| cvss.into())) | ||
} | ||
|
||
#[instrument(skip(self, tx), err)] | ||
pub async fn ingest_cvss3_score<TX: AsRef<Transactional>>( | ||
&self, | ||
cvss3: Cvss3Base, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks!