-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add IPFS usage metrics / extend logging / extend supported content path formats #6058
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
Conversation
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 improvements! It would be good to address the comments about the Default
implementation and ownership of IpfsContext
before merging, but feel free to merge once that's done.
chain/substreams/src/data_source.rs
Outdated
let logger = Logger::root(Discard, o!()); | ||
let ds: DataSource = ds.resolve(&link_resolver, &logger, 0).await.unwrap(); | ||
let ds: DataSource = ds | ||
.resolve(&Default::default(), &link_resolver, &logger, 0) |
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.
I kinda dislike using Default::default
because from just reading the code, I have no idea what gets passed there. Could you write that as LinkResolverContext::default()
?
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.
Updated to DeploymentHash::default()
chain/substreams/src/data_source.rs
Outdated
let logger = Logger::root(Discard, o!()); | ||
let ds: DataSource = ds.resolve(&link_resolver, &logger, 0).await.unwrap(); | ||
let ds: DataSource = ds | ||
.resolve(&Default::default(), &link_resolver, &logger, 0) |
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.
Same comment about Default::default()
here
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.
Updated to DeploymentHash::default()
assert_eq!(path, make_path(CID_V0, None)); | ||
|
||
let path = ContentPath::new(format!("https://ipfs.com/{CID_V0}/readme.md")).unwrap(); | ||
assert_eq!(path, make_path(CID_V0, Some("readme.md"))); |
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.
Everything in this file looks great, but since we are handling user input here, are there ways to abuse this in security-relevant ways? (I think the answer is 'no', but wanted to double-check)
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.
We are not making HTTP requests to arbitrary URLs here, and CIDs are parsed and must be valid. The only part that remains unchanged is the optional path after the CID, but it does not seem to be possible to abuse that it a security-relevant way
deployment_hash: "test".into(), | ||
logger: crate::log::discard(), | ||
} | ||
} |
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.
This seems petty, but rather than implement Default
, it might be clearer to make this a method LinkResolverContext::dummy()
(only in debug builds) It's not really a default implementation, since there's not really a sensible default for this struct.
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.
Added a dedicated test()
method to create a test LinkResolverContext
pub type IpfsService = Buffer<ContentPath, BoxFuture<'static, Result<Option<Bytes>, Error>>>; | ||
pub type IpfsService = Buffer<IpfsRequest, BoxFuture<'static, Result<Option<Bytes>, Error>>>; | ||
|
||
#[derive(Clone, Debug)] |
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.
I got a little hung up on why this needs to be 'Clone'; I think it ultimately boils down to the fact that when we make the request, we want it returned back and we do that in ReturnRequest::call
; it seems we could avoid cloning if we changed what IpfsServiceInner::call_inner
returns and have it always include the request in its return value, basically moving ownership of the request through call_inner
. In this case, I am also not sure how important it is to save on cloning, though we clone on every request.
In any event, this would definitely be something for a different PR.
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.
I made the request CheapClone
by using Arc
internally in ContentPath
, and that will help a bit. Optimizing the polling monitor is a good idea and I will look into this as part of different issue / PR.
graph/src/ipfs/client.rs
Outdated
/// The timeout is not propagated to the resulting stream. | ||
async fn cat_stream( | ||
self: Arc<Self>, | ||
ctx: IpfsContext, |
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.
Does this need to take ownership? It seems that just a reference would be enough
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.
Updated this to accept &IpfsContext
graph/src/ipfs/client.rs
Outdated
/// does not return a response within the specified amount of time. | ||
async fn cat( | ||
self: Arc<Self>, | ||
ctx: IpfsContext, |
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.
Same question about ownership
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.
Updated this to accept &IpfsContext
graph/src/ipfs/client.rs
Outdated
/// does not return a response within the specified amount of time. | ||
async fn get_block( | ||
self: Arc<Self>, | ||
ctx: IpfsContext, |
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.
Same question about ownership
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.
Updated this to accept &IpfsContext
Do we still want these metrics? If not, can we close this PR? |
ea20209
to
5342293
Compare
2eccf5c
to
3f74611
Compare
This PR introduces the following improvements to IPFS:
ipfs_request_count
- shows the total number of IPFS requestsipfs_error_count
- shows the total number of failed IPFS requestsipfs_not_found_count
- shows the total number of IPFS requests that timed outipfs_request_duration
- shows the duration of successful IPFS requests<CID>[/<path>]
/ipfs/<CID>[/<path>]
ipfs://<CID>[/<path>]
http[s]://.../ipfs/<CID>[/<path>]
http[s]://.../api/v0/cat?arg=<CID>[/<path>]
http[s]://.../<CID>[/<path>]
Closes #6036