-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(middleware): create a generic middleware to collect method metri…
…cs. (#804)
- Loading branch information
Showing
16 changed files
with
308 additions
and
170 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// This file is part of Rundler. | ||
// | ||
// Rundler is free software: you can redistribute it and/or modify it under the | ||
// terms of the GNU Lesser General Public License as published by the Free Software | ||
// Foundation, either version 3 of the License, or (at your option) any later version. | ||
// | ||
// Rundler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with Rundler. | ||
// If not, see https://www.gnu.org/licenses/. | ||
|
||
/// Method extractor | ||
use rundler_types::task::traits::RequestExtractor; | ||
use alloy_json_rpc::RequestPacket; | ||
|
||
#[derive(Clone, Copy)] | ||
struct AlloyMethodExtractor; | ||
|
||
impl RequestExtractor<RequestPacket> for RPCMethodExtractor { | ||
fn get_method_name(req: &RequestPacket) -> String { | ||
match req { | ||
RequestPacket::Single(request) => { | ||
request.method().to_string() | ||
} | ||
_ => { | ||
// can't extract method name for batch. | ||
"batch".to_string() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This file is part of Rundler. | ||
// | ||
// Rundler is free software: you can redistribute it and/or modify it under the | ||
// terms of the GNU Lesser General Public License as published by the Free Software | ||
// Foundation, either version 3 of the License, or (at your option) any later version. | ||
// | ||
// Rundler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with Rundler. | ||
// If not, see https://www.gnu.org/licenses/. | ||
|
||
use jsonrpsee::types::Request; | ||
use rundler_types::task::traits::RequestExtractor; | ||
|
||
#[derive(Copy, Clone)] | ||
struct RPCMethodExtractor; | ||
|
||
impl RequestExtractor<Request<'static>> for RPCMethodExtractor { | ||
fn get_method_name(req: & Request<'static>) -> String { | ||
req.method_name().to_string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// This file is part of Rundler. | ||
// | ||
// Rundler is free software: you can redistribute it and/or modify it under the | ||
// terms of the GNU Lesser General Public License as published by the Free Software | ||
// Foundation, either version 3 of the License, or (at your option) any later version. | ||
// | ||
// Rundler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
// See the GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with Rundler. | ||
// If not, see https://www.gnu.org/licenses/. | ||
|
||
use rundler_types::task::traits::RequestExtractor; | ||
use tonic::codegen::http; | ||
|
||
/// http request method extractor. | ||
#[derive(Copy, Clone)] | ||
struct HttpMethodExtractor; | ||
|
||
impl<Body> RequestExtractor<http::Request<Body>> for HttpMethodExtractor { | ||
fn get_method_name(req: &http::Request<Body>) -> String { | ||
let method_name = req.uri().path().split('/').last().unwrap_or("unknown"); | ||
method_name.to_string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
pub mod block_watcher; | ||
pub mod grpc; | ||
pub mod metrics; | ||
pub mod server; | ||
|
||
mod task; | ||
|
Oops, something went wrong.