Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions bottlecap/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bottlecap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,16 @@ rmp-serde = { version = "1.3.1", default-features = false }
flate2 = { version = "1.1", default-features = false, features = ["rust_backend"] }
# fault-intake test harness: decode the `datadog-protos` metrics payloads
protobuf = { version = "3.7", default-features = false }
# T14 micro benchmark for the JULIO-12 prototype (do not merge)
criterion = { version = "0.5", default-features = false }

[build-dependencies]
# No external dependencies needed for the build script

[[bench]]
name = "appsec_access_key_id"
harness = false

[[bin]]
name = "bottlecap"

Expand Down
68 changes: 68 additions & 0 deletions bottlecap/benches/appsec_access_key_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! T14 (JULIO-12 LLD): cost of `DD_APPSEC_AWS_ACCESS_KEY_ID_TAG_ENABLED` on one
//! monitored invocation (request, response, `aws.lambda` span), key on against off.

use std::collections::HashMap;
use std::hint::black_box;

use bottlecap::appsec::processor::Processor;
use bottlecap::config::Config;
use bottlecap::lifecycle::invocation::triggers::IdentifiedTrigger;
use bytes::Bytes;
use criterion::{Criterion, criterion_group, criterion_main};
use libdd_trace_protobuf::pb::Span;

fn processor(tag_enabled: bool) -> Processor {
Processor::new(&Config {
ext: bottlecap::config::LambdaConfig {
serverless_appsec_enabled: true,
appsec_aws_access_key_id_tag_enabled: tag_enabled,
..Default::default()
},
..Config::default()
})
.expect("failed to create Processor")
}

fn bench(c: &mut Criterion) {
// SAFETY: set once, before any other thread starts.
unsafe { std::env::set_var("AWS_ACCESS_KEY_ID", "ASIAEXAMPLE000000001") };

let trigger = IdentifiedTrigger::LambdaFunctionUrlEvent(
serde_json::from_slice(include_bytes!(
"../tests/payloads/lambda_function_url_event.json"
))
.expect("failed to parse payload"),
);
let response = Bytes::from_static(br#"{"statusCode":200}"#);
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.expect("runtime");

let mut group = c.benchmark_group("appsec_monitored_invocation");
for (name, tag_enabled) in [("key_off", false), ("key_on", true)] {
let mut processor = processor(tag_enabled);
group.bench_function(name, |b| {
b.iter(|| {
rt.block_on(async {
processor.process_invocation_next("rid", &trigger).await;
processor.process_invocation_result("rid", &response).await;
});
let mut span = Span {
name: "aws.lambda".into(),
meta: HashMap::from([("request_id".to_string(), "rid".to_string())]),
..Default::default()
};
processor.process_span(&mut span);
black_box(span)
});
});
}
group.finish();
}

criterion_group! {
name = benches;
config = Criterion::default().sample_size(200).measurement_time(std::time::Duration::from_secs(20));
targets = bench
}
criterion_main!(benches);
Loading
Loading