Skip to content

Commit 45bc180

Browse files
committed
progress
1 parent 4faf74d commit 45bc180

File tree

14 files changed

+510
-70
lines changed

14 files changed

+510
-70
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/gradle
2+
/.jj
3+
/.git
4+
/target
5+
/benchmark
6+
/crates/rust-sample-wallet/dist
7+
/crates/rust-sample-wallet/node_modules
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Deploy Sign Sample to Github Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- push-tlltnpmvwzwm
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write # for committing to gh-pages branch.
12+
pages: write
13+
id-token: write
14+
15+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
16+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
17+
concurrency:
18+
group: "pages"
19+
cancel-in-progress: false
20+
21+
jobs:
22+
Github-Pages-Release:
23+
24+
timeout-minutes: 10
25+
26+
environment:
27+
name: github-pages
28+
url: ${{ steps.deployment.outputs.page_url }}
29+
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- uses: actions/checkout@v4 # repo checkout
34+
35+
# Install Rust Nightly Toolchain, with Clippy & Rustfmt
36+
- name: Install nightly Rust
37+
uses: dtolnay/rust-toolchain@nightly
38+
with:
39+
components: clippy, rustfmt
40+
41+
- name: Add WASM target
42+
run: rustup target add wasm32-unknown-unknown
43+
44+
- name: Download and install Trunk binary
45+
run: wget -qO- https://github.com/trunk-rs/trunk/releases/download/v0.18.4/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf-
46+
47+
- name: Build with Trunk
48+
# "${GITHUB_REPOSITORY#*/}" evaluates into the name of the repository
49+
# using --public-url something will allow trunk to modify all the href paths like from favicon.ico to repo_name/favicon.ico .
50+
# this is necessary for github pages where the site is deployed to username.github.io/repo_name and all files must be requested
51+
# relatively as favicon.ico. if we skip public-url option, the href paths will instead request username.github.io/favicon.ico which
52+
# will obviously return error 404 not found.
53+
run: ../../trunk build --release --public-url "${GITHUB_REPOSITORY#*/}"
54+
working-directory: crates/rust-sample-wallet
55+
56+
57+
# Deploy to gh-pages branch
58+
# - name: Deploy 🚀
59+
# uses: JamesIves/github-pages-deploy-action@v4
60+
# with:
61+
# folder: dist
62+
63+
64+
# Deploy with Github Static Pages
65+
66+
- name: Setup Pages
67+
uses: actions/configure-pages@v4
68+
with:
69+
enablement: true
70+
# token:
71+
72+
- name: Upload artifact
73+
uses: actions/upload-pages-artifact@v2
74+
with:
75+
# Upload dist dir
76+
path: './crates/rust-sample-wallet/dist'
77+
78+
- name: Deploy to GitHub Pages 🚀
79+
id: deployment
80+
uses: actions/deploy-pages@v3
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: publish_sign_canary
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
- push-yruotstkupns
8+
9+
concurrency: ${{ github.workflow }}
10+
11+
env:
12+
TERM: linux
13+
14+
jobs:
15+
push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
id-token: write
19+
steps:
20+
- name: Configure AWS Credentials
21+
uses: aws-actions/configure-aws-credentials@v4
22+
with:
23+
aws-access-key-id: ${{ secrets.AWS_ECR_PUBLISHER_ACCESS_KEY_ID }}
24+
aws-secret-access-key: ${{ secrets.AWS_ECR_PUBLISHER_SECRET_ACCESS_KEY }}
25+
aws-region: eu-central-1
26+
27+
- name: Login to Amazon ECR
28+
id: login-ecr
29+
uses: aws-actions/amazon-ecr-login@v2
30+
with:
31+
mask-password: 'true'
32+
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v3
38+
39+
- name: Cache Docker layers
40+
uses: actions/cache@v4
41+
with:
42+
path: /tmp/.buildx-cache
43+
key: ${{ runner.os }}-buildx-${{ github.sha }}
44+
restore-keys: |
45+
${{ runner.os }}-buildx-
46+
47+
- name: Build, tag, and push image to Amazon ECR
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
file: canary/Dockerfile
52+
push: true
53+
tags: ${{ steps.login-ecr.outputs.registry }}/rust-sign-client:${{ github.sha }},${{ steps.login-ecr.outputs.registry }}/rust-sign-client:main
54+
cache-from: type=local,src=/tmp/.buildx-cache
55+
cache-to: type=local,dest=/tmp/.buildx-cache-new
56+
57+
# Temp fix
58+
# https://github.com/docker/build-push-action/issues/252
59+
# https://github.com/moby/buildkit/issues/1896
60+
- name: Move cache
61+
run: |
62+
rm -rf /tmp/.buildx-cache
63+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

canary/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM rust:1 AS chef
2+
# We only pay the installation cost once,
3+
# it will be cached from the second build onwards
4+
RUN cargo install cargo-chef
5+
WORKDIR app
6+
7+
FROM chef AS planner
8+
COPY . .
9+
RUN cargo chef prepare --recipe-path recipe.json
10+
11+
FROM chef AS builder
12+
COPY --from=planner /app/recipe.json recipe.json
13+
# Build dependencies - this is the caching Docker layer!
14+
RUN cargo chef cook --release --recipe-path recipe.json
15+
# Build application
16+
COPY . .
17+
RUN cargo build --release --bin sign-canary --features=sign_canary
18+
19+
# We do not need the Rust toolchain to run the binary!
20+
FROM debian:bookworm-slim AS runtime
21+
WORKDIR app
22+
COPY --from=builder /app/target/release/sign-canary /usr/local/bin
23+
ENTRYPOINT ["/usr/local/bin/sign-canary"]

crates/yttrium/Cargo.toml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ name = "uniffi-bindgen"
1313
path = "uniffi-bindgen.rs"
1414
required-features = ["uniffi"]
1515

16+
[[bin]]
17+
name = "sign-canary"
18+
path = "src/bin/sign_canary.rs"
19+
required-features = ["sign_canary"]
20+
1621
[features]
1722
default = ["eip155", "erc6492_client", "chain_abstraction_client"]
1823
full = ["all_platforms", "all_clients", "all_namespaces"]
@@ -96,6 +101,12 @@ sign_client = [
96101
"dep:tokio-util",
97102
]
98103

104+
sign_canary = [
105+
"sign_client",
106+
"dep:aws-config",
107+
"dep:aws-sdk-cloudwatch",
108+
]
109+
99110
# Features enabling test coverage
100111
test_full = [
101112
"test_pimlico_api",
@@ -236,6 +247,9 @@ x25519-dalek = { version = "3.0.0-pre.0", features = [
236247
hkdf = { version = "0.13.0-rc.0", optional = true }
237248
sha2 = { version = "0.11.0-rc.0", optional = true }
238249

250+
aws-config = { version = "1.1.7", features = ["behavior-version-latest"], optional = true }
251+
aws-sdk-cloudwatch = { version = "1.91.0", optional = true }
252+
239253
[dev-dependencies]
240254
# mocking
241255
wiremock = { version = "0.6.0", default-features = false }
@@ -250,8 +264,5 @@ serial_test.workspace = true
250264
chacha20poly1305 = { workspace = true, features = ["alloc", "os_rng"] }
251265
data-encoding = { workspace = true }
252266

253-
aws-config = { version = "1.1.7", features = ["behavior-version-latest"] }
254-
aws-sdk-cloudwatch = { version = "1.91.0" }
255-
256267
[package.metadata.wasm-pack.profile.release]
257268
wasm-opt = ['-Oz']
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
use {
2+
aws_sdk_cloudwatch::{
3+
primitives::DateTime,
4+
types::{Dimension, MetricDatum, StandardUnit},
5+
},
6+
std::time::SystemTime,
7+
tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt},
8+
yttrium::sign::test_helpers::{probe_layer, test_sign_impl},
9+
};
10+
11+
#[tokio::main]
12+
pub async fn main() {
13+
let probe_layer = probe_layer::ProbeLayer::new();
14+
tracing_subscriber::fmt()
15+
.with_max_level(tracing::Level::DEBUG)
16+
.finish()
17+
.with(probe_layer.clone())
18+
.try_init()
19+
.unwrap();
20+
21+
// let start = Instant::now();
22+
let result = test_sign_impl().await;
23+
tracing::debug!(probe = "e2e");
24+
// let e2e_latency = start.elapsed();
25+
26+
let config = aws_config::load_from_env().await;
27+
let cloudwatch_client = aws_sdk_cloudwatch::Client::new(&config);
28+
let region = config.region().unwrap().to_string();
29+
let region_dimension = Dimension::builder()
30+
.name("Region".to_string())
31+
.value(region.clone())
32+
.build();
33+
34+
// TODO measure crypto operation latency
35+
// TODO measure storage operation latency
36+
// TODO measure client request latency
37+
38+
println!("probe_layer: {:?}", probe_layer.accumulator());
39+
// panic!();
40+
41+
let now = DateTime::from(SystemTime::now());
42+
let metrics = probe_layer
43+
.accumulator()
44+
.iter()
45+
.map(|p| {
46+
let probe_dimension = Dimension::builder()
47+
.name("Probe".to_string())
48+
.value(p.probe.clone())
49+
.build();
50+
let group_dimension = p.group.clone().map(|g| {
51+
Dimension::builder().name("Group".to_string()).value(g).build()
52+
});
53+
vec![
54+
{
55+
let mut metric = MetricDatum::builder()
56+
.metric_name(format!("probe_hit"))
57+
// .metric_name(format!("probe_{}_hit", p.probe.clone()))
58+
.dimensions(probe_dimension.clone());
59+
if let Some(group_dimension) = group_dimension.clone() {
60+
metric = metric.dimensions(group_dimension);
61+
}
62+
metric
63+
.dimensions(region_dimension.clone())
64+
.value(1.)
65+
.unit(StandardUnit::Count)
66+
.timestamp(now)
67+
.build()
68+
},
69+
{
70+
let mut metric = MetricDatum::builder()
71+
.metric_name(format!(
72+
"probe_latency_seconds",
73+
// "probe_{}_latency_seconds",
74+
// p.probe.clone()
75+
))
76+
.dimensions(probe_dimension.clone());
77+
if let Some(group_dimension) = group_dimension.clone() {
78+
metric = metric.dimensions(group_dimension);
79+
}
80+
metric
81+
.dimensions(region_dimension.clone())
82+
.value(p.elapsed_s)
83+
.unit(StandardUnit::Seconds)
84+
.timestamp(now)
85+
.build()
86+
},
87+
]
88+
})
89+
.flatten()
90+
.collect::<Vec<_>>();
91+
92+
cloudwatch_client
93+
.put_metric_data()
94+
.namespace("dev2_Canary_RustSignClient")
95+
.set_metric_data(Some(metrics))
96+
// .metric_data(
97+
// MetricDatum::builder()
98+
// .metric_name("e2e.success".to_string())
99+
// .dimensions(dimensions.clone())
100+
// .value(if result.is_ok() { 1. } else { 0. })
101+
// .unit(StandardUnit::Count)
102+
// .timestamp(DateTime::from(SystemTime::now()))
103+
// .build(),
104+
// )
105+
// .metric_data(
106+
// MetricDatum::builder()
107+
// .metric_name("e2e.latency".to_string())
108+
// .dimensions(dimensions.clone())
109+
// .value(e2e_latency.as_millis() as f64)
110+
// .unit(StandardUnit::Milliseconds)
111+
// .timestamp(DateTime::from(SystemTime::now()))
112+
// .build(),
113+
// )
114+
.send()
115+
.await
116+
.unwrap();
117+
118+
if let Err(e) = result {
119+
panic!("Test failed: {e}");
120+
}
121+
}

0 commit comments

Comments
 (0)