fn icon indicating copy to clipboard operation
fn copied to clipboard

Question on /r/ URL paths that I've seen in a few places.

Open fadams opened this issue 5 years ago • 2 comments

Hello, I've a couple of (probably) related questions.

I know for example that invoking functions via cur can be achieved via http triggers as described in this tutorial https://github.com/fnproject/tutorials/blob/master/Introduction/README.md and running tutorial that helpfully emits the endpoint e.g. Trigger Endpoint: http://10.192.0.2:30090/t/goapp/gofn

Which works nicely.

A couple of things do confuse me though. Firstly if one follows the Quickstart on the main GitHub page https://github.com/fnproject/fn it's possible to invoke using fn invoke myapp hello but with that example there is no (obvious) URL path. Now I can do

fn inspect fn myapp hello
{
	"annotations": {
		"fnproject.io/fn/invokeEndpoint": "http://10.192.0.2:30090/invoke/01D85S0ERM1BT044G0A0000006"
	},
	"app_id": "01D85RZ4A81BT044G0A0000005",
	"created_at": "2019-04-11T08:42:42.836Z",
	"id": "01D85S0ERM1BT044G0A0000006",
	"idle_timeout": 30,
	"image": "docker-mint.local:5000/hello:0.0.3",
	"memory": 128,
	"name": "hello",
	"timeout": 30,
	"updated_at": "2019-04-11T08:44:29.083Z"
}

then

curl -X POST http://10.192.0.2:30090/invoke/01D85S0ERM1BT044G0A0000
006
{"message":"Hello World"}

But I believe that there is no default trigger path set up (which is fine, I'm just trying to get my head around what is going on)

That leads me to other questions.

As far as I can see the way to add a trigger is way back at the fn init stage so imagine if I'd followed the process from the Quickstart but then realised that I needed to add a trigger. Now I can obviously update the YAML and call deploy but the build and bump stuff seems overkill when I'm just needing to add a new trigger endpoint to an already deployed and invokeable function.

Is there a simple way to just add a trigger in that scenario? If so I think it'd be good to extend the Quickstart from it's current fn invoke to then show a trigger being added and an HTTP endpoint being available - I'm guessing that in practice more people are likely to be stringing together functions as REST endpoints than calling invoke (maybe I'm wrong?)

My final part to this is the /r/ path I've seen in several places, such as here https://github.com/treeder/fn-app-example (I know that it's not from the Fn tree or docs). Now skimming through that I can't see any triggers defined but it still implies an HTTP endpoint.

Now I think that the /r/ bit comes from Fn's heritage having been derived from IronFunctions as many of the Fn team moved to Oracle from Iron.io and ISTR that IronFunctions had the concept of "routes" so I'm thinking that the /r/ stuff might just be referring to something that existed in an earlier version of Fn but has since been deprecated. If so that's fine, but TBH I've found it a bit confusing at times 'cause when trying to discover more about Fn and what it can do I tend to Google around and happened upon a few different example following the /r/ form. If that's all dead now it'd be good if something could be included in the documentation somewhere.

fadams avatar Apr 11 '19 09:04 fadams

Great questions. I'll let @rdallman or @denismakogon comment on the history of the invoke annotation URL, but to answer the other questions:

Creating a trigger should be pretty straight forward. Try fn create trigger --help for the format. Think the docs are a bit incomplete here so it'll look something like: fn create trigger myapp myfunc mynewtrigger --type http --source newtriggerpath --> http://yourfnserver.com/t/myapp/myfunc/mynewtrigger

As for the /r routes, yes you got it, all existing legacy docs that need to be cleaned up or removed. Thanks for mentioning.

carimura avatar Apr 11 '19 15:04 carimura

And then there's the lazy path of creating a trigger during the init, fn init --runtime java --trigger http afunc. This post on trigger contains some historical context.

delabassee avatar Apr 11 '19 16:04 delabassee