Skip to content
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

feat: endpoint reachability plugin #720

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

5war00p
Copy link

@5war00p 5war00p commented Oct 31, 2024

Endpoint Reachability Plugin

  • Brief Description of Changes
    Added new plugin that checks and validates whether an endpoint (url) is reachable or unreachable.

Motivation: (optional)

  • Why this change is necessary or beneficial
    Its a preventive check to not do unnecessary actions without a proper input

Related Issues: (optional)

@roh26it
Copy link
Collaborator

roh26it commented Nov 8, 2024

Thanks for the PR @5war00p!

Does this only check the entire content of the request to assume that it contains a URL?

We also have another plugin - https://github.com/Portkey-AI/gateway/blob/main/plugins/default/validUrls.ts

Is that conflicting?

@5war00p
Copy link
Author

5war00p commented Nov 8, 2024

This just does almost same, but instead of GET request I'm using HEAD request also we as we need to validate endpoint is reaching or not just header is fine no need validate dns separately.

Copy link
Collaborator

@narengogi narengogi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just that this assumes that the response only contains a URL. in comparison,
https://github.com/Portkey-AI/gateway/blob/main/plugins/default/validUrls.ts feels more complete, I think it's a good idea to make a HEAD request to check the validity of a URL, you can perhaps add it as a fallback in the code of the existing plugin. That would be a 2 line change and more robust

@5war00p
Copy link
Author

5war00p commented Nov 11, 2024

To your point, validUrl ideally should be a regexp check thats what name speaks about. Where as endpointReachability make sure it reaches. If we really don't need 2 separate then we can merge, but validUrl can be used to validate a url input but if we make sure its a reachable one then merging both will be good idea.

let data = null;

try {
let text = getText(context, eventType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion here is use regex to get all the URLs available from text and validate them using URL or some other way.

With this we can have config weather to run plugin for all the endpoints or first endpoint found within the text.

What do you think? @5war00p

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense if text might contain >1 url, however this issue is to build a plugin for endpoint reachability right? and we should use this util func in another which extracts urls and check each url using this plugin. Correct me if I went off.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your thought makes sense, but this PR is a plugin PR which I think doesn't make sense to use it as utility function. I think we should focus on keep this as individual plugin. keeping that I prefer we should go for regex match.

As an enhancement I think we shouldn't just blindly hit the URL, we should ask user which type of method they're thinking of ex: GET and POST and let plugin do OPTIONS request and make sure the endpoint(s) support the user requested methods.

let me know if this makes sense to you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if thats the case we should make it as a new separate plugin.

@narengogi
Copy link
Collaborator

To your point, validUrl ideally should be a regexp check thats what name speaks about. Where as endpointReachability make sure it reaches. If we really don't need 2 separate then we can merge, but validUrl can be used to validate a url input but if we make sure its a reachable one then merging both will be good idea.

sorry for the late reply @5war00p , as you might have noticed during your testing, the plugins act on the request and response body, so your plugin assumes it recieves only the URL in the body. Hence the plugin is not of much use.

But it's a cool implementation like I said, but for now this cannot be merged

@5war00p
Copy link
Author

5war00p commented Nov 22, 2024

@narengogi In that case we can do as @b4s36t4 suggested, extract links and verify endpoint reachability, but question is do we need to do that for all links in found in entire text and how we do we determine that?

@narengogi
Copy link
Collaborator

@5war00p you can use regex to extract the URLs

@VisargD
Copy link
Collaborator

VisargD commented Dec 16, 2024

Hey folks! Are we moving forward with this implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants