diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 48cec8bc0a..5233a28db9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -16,9 +16,72 @@ env: CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse jobs: + manual-build-image: + if: github.event_name == 'workflow_dispatch' + runs-on: blacksmith-8vcpu-ubuntu-2204 + env: + BLACKSMITH_DOCKER_CACHE_KEY: ${{ github.repository }}-docker-pathfinder + steps: + - name: Checkout sources + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Generate version + id: generate_version + run: | + git fetch --force --tags https://github.com/eqlabs/pathfinder.git 'refs/tags/v*:refs/tags/v*' + echo -n "pathfinder_version=" >> "$GITHUB_OUTPUT" + git describe --tags --dirty --always >> "$GITHUB_OUTPUT" + + - name: Tags + id: tag + run: | + IMAGE="ghcr.io/${{ github.repository_owner }}/pathfinder" + SHA=$(git rev-parse --short=7 "$GITHUB_SHA") + MANUAL_SHA="$IMAGE:manual-$SHA" + TAGS="$MANUAL_SHA" + + echo "manual-sha=$MANUAL_SHA" >> "$GITHUB_OUTPUT" + + if [[ "${{ github.ref_name }}" == "main" ]]; then + MANUAL_LATEST="$IMAGE:manual-latest" + echo "manual-latest=$MANUAL_LATEST" >> "$GITHUB_OUTPUT" + TAGS="$TAGS"$'\n'"$MANUAL_LATEST" + fi + + echo "tags<> "$GITHUB_OUTPUT" + echo "$TAGS" >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: useblacksmith/setup-docker-builder@v1 + env: + GITHUB_REPO_NAME: ${{ env.BLACKSMITH_DOCKER_CACHE_KEY }} + + - name: Build Docker Image and Publish + uses: useblacksmith/build-push-action@v2 + env: + GITHUB_REPO_NAME: ${{ env.BLACKSMITH_DOCKER_CACHE_KEY }} + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + push: true + build-args: | + PATHFINDER_FORCE_VERSION=${{ steps.generate_version.outputs.pathfinder_version }} + tags: ${{ steps.tag.outputs.tags }} + # Build a docker image unless this was triggered by a release. build-image: - if: github.event_name != 'release' + if: github.event_name == 'push' runs-on: pathfinder-large-ubuntu steps: - name: Determine Docker image metadata diff --git a/crates/rpc/src/jsonrpc/router.rs b/crates/rpc/src/jsonrpc/router.rs index 0d843f0f1a..ed9d33ec75 100644 --- a/crates/rpc/src/jsonrpc/router.rs +++ b/crates/rpc/src/jsonrpc/router.rs @@ -23,6 +23,20 @@ mod subscription; pub use method::handle_json_rpc_body; +const SNOS_RPC_METHOD_DURATION_SECONDS: &str = "pathfinder_snos_rpc_method_duration_seconds"; +const SNOS_RPC_METHODS: &[&str] = &[ + "starknet_chainId", + "starknet_getBlockWithReceipts", + "starknet_getBlockWithTxHashes", + "starknet_getBlockWithTxs", + "starknet_getClass", + "starknet_getClassHashAt", + "starknet_getNonce", + "starknet_getStateUpdate", + "starknet_getStorageAt", + "starknet_getStorageProof", +]; + #[derive(Clone)] pub struct RpcRouter { pub context: RpcContext, @@ -134,6 +148,7 @@ impl RpcRouter { let result = std::panic::AssertUnwindSafe(method).catch_unwind().await; let duration = start.elapsed(); + record_snos_rpc_method_duration(method_name, duration); metrics::histogram!("rpc_method_calls_duration_milliseconds", "method" => method_name, "version" => self.version.to_str()).record(duration.as_millis() as f64); let output = match result { @@ -158,6 +173,15 @@ impl RpcRouter { } } +fn record_snos_rpc_method_duration(method_name: &'static str, duration: std::time::Duration) { + if !SNOS_RPC_METHODS.contains(&method_name) { + return; + } + + metrics::histogram!(SNOS_RPC_METHOD_DURATION_SECONDS, "method" => method_name) + .record(duration.as_secs_f64()); +} + // A slight variation on the axum json extractor. fn is_utf8_encoded_json(headers: http::HeaderMap) -> bool { let Some(content_type) = headers.get(http::header::CONTENT_TYPE) else {