Git Product home page Git Product logo

apache / openwhisk-runtime-go Goto Github PK

View Code? Open in Web Editor NEW
44.0 25.0 50.0 4.06 MB

Apache OpenWhisk Runtime Go supports Apache OpenWhisk functions written in Go

Home Page: https://openwhisk.apache.org/

License: Apache License 2.0

Go 55.07% Shell 7.16% Dockerfile 3.96% Scala 18.14% Python 13.23% Makefile 2.44%
openwhisk apache serverless faas functions-as-a-service cloud serverless-architectures serverless-functions docker functions

openwhisk-runtime-go's Introduction

Apache OpenWhisk Runtimes for Go

License Continuous Integration Join Slack

This repository contains both the OpenWhisk runtime for Golang Actions, as well as a runtime for Generic executables.

  • If you are in a hurry, check the examples
  • Writing Actions for the runtime in Golang
  • How to deploy your Golang sources
  • Precompiling Golang actions
  • How to use VSCode to write Golang actions
  • How to Build the runtime, with development notes

Actionloop runtime

Using the Go runtime for Generic executables

  • Writing Generic actions, in bash or as a generic linux binary
  • Deployment for Generic actions
  • The ActionLoop protocol for generic actions
  • Environment Variables to configure the proxy

Change Log

CHANGES.md

License

Apache 2.0

openwhisk-runtime-go's People

Contributors

agilob avatar chetanmeh avatar csantanapr avatar ddragosd avatar dengliming avatar dgrove-oss avatar elanhasson avatar falkzoll avatar jbampton avatar jiangpengcheng avatar lolgab avatar luke-roy-ibm avatar markusthoemmes avatar mdeuser avatar mhenke1 avatar mpmunasinghe avatar mrutkows avatar ningyougang avatar rabbah avatar sciabarracom avatar skywalkeretw avatar tpei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openwhisk-runtime-go's Issues

missing license text for Filetype

from the IPMC release vote

  • the text of the license for Filetype 1.0.5 is not included (as required by it's license). The pointer to the licenses should point to a copy of the license in distribution as licenses and URLs can change over time.

Panic with zip file

When uploading a zip file to the new PHP7.3 runtime which uses the action proxy I get a panic.

The contents of the zip file are:

<?php
function niam(array $args) {
    return [result => "it works"];
}

I'm uploading it using:

$ $OPENWHISK_HOME/tools/actionProxy/invoke.py init niam niam.zip
('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

I'm running the proxy using: /bin/proxy -debug and the output is:

root@e36df89dee22:/phpAction# /bin/proxy -debug
2018/12/01 22:04:20 OpenWhisk Go Proxy: starting
2018/12/01 22:04:25 compiler: /bin/compile
2018/12/01 22:04:25 init: decoding {"value": {"code": "UEsDBAoAAAAAAIGwgU0t9qVmSAAAAEgAAAAJABwAaW5kZXgucGhwVVQJAANRBQNcVAUDXHV4CwABBPUBAAAEFAAAADw/cGhwCmZ1bmN0aW9uIG5pYW0oYXJyYXkgJGFyZ3MpIHsKICAgIHJldHVybiBbcmVzdWx0ID0+ICJpdCB3b3JrcyJdOwp9ClBLAQIeAwoAAAAAAIGwgU0t9qVmSAAAAEgAAAAJABgAAAAAAAEAAAC0gQAAAABpbmRleC5waHBVVAUAA1EFA1x1eAsAAQT1AQAABBQAAABQSwUGAAAAAAEAAQBPAAAAiwAAAAAA", "binary": true, "main": "niam"}}
2018/12/01 22:04:25 it is binary code
2018/12/01 22:04:25 http: panic serving 172.17.0.1:42600: runtime error: slice bounds out of range
goroutine 19 [running]:
net/http.(*conn).serve.func1(0xc0000ae8c0)
	/home/travis/.gimme/versions/go1.11.2.linux.amd64/src/net/http/server.go:1746 +0xd0
panic(0x6aee00, 0x9324f0)
	/home/travis/.gimme/versions/go1.11.2.linux.amd64/src/runtime/panic.go:513 +0x1b9
github.com/apache/incubator-openwhisk-runtime-go/vendor/gopkg.in/h2non/filetype.v1/matchers.Xlsx(0xc00016c000, 0xf0, 0xf0, 0x671ef0)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/vendor/gopkg.in/h2non/filetype.v1/matchers/document.go:50 +0xd4
github.com/apache/incubator-openwhisk-runtime-go/vendor/gopkg.in/h2non/filetype.v1/matchers.NewMatcher.func1(0xc00016c000, 0xf0, 0xf0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/vendor/gopkg.in/h2non/filetype.v1/matchers/matchers.go:23 +0x69
github.com/apache/incubator-openwhisk-runtime-go/vendor/gopkg.in/h2non/filetype%2ev1.Match(0xc00016c000, 0xf0, 0xf0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/vendor/gopkg.in/h2non/filetype.v1/match.go:25 +0x106
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*ActionProxy).ExtractAction(0xc0000ad450, 0xc0000a1cf0, 0x705368, 0x3, 0x140, 0x140, 0x3, 0x0)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/extractor.go:113 +0x23c
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*ActionProxy).ExtractAndCompile(0xc0000ad450, 0xc0000a1cf0, 0xc0001380b8, 0x4, 0xf0, 0xf0, 0x0, 0x0)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/initHandler.go:137 +0x75
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*ActionProxy).initHandler(0xc0000ad450, 0x754a80, 0xc000148000, 0xc00012e000)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/initHandler.go:112 +0x405
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*ActionProxy).ServeHTTP(0xc0000ad450, 0x754a80, 0xc000148000, 0xc00012e000)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/actionProxy.go:110 +0x85
net/http.serverHandler.ServeHTTP(0xc00008b040, 0x754a80, 0xc000148000, 0xc00012e000)
	/home/travis/.gimme/versions/go1.11.2.linux.amd64/src/net/http/server.go:2741 +0xab
net/http.(*conn).serve(0xc0000ae8c0, 0x754cc0, 0xc0000982c0)
	/home/travis/.gimme/versions/go1.11.2.linux.amd64/src/net/http/server.go:1847 +0x646
created by net/http.(*Server).Serve
	/home/travis/.gimme/versions/go1.11.2.linux.amd64/src/net/http/server.go:2851 +0x2f5

Zip file attached.
niam.zip

compiler should generate zip

currently the compiler outputs the binary file, and users need to follow the extra steps to name it main and put in the root of zip.

The compiler can just generate a ready zip

split distDokcer, build and tests in separate tasks

Today distDocker depends go build, and go build depends on go test

We should split them in seperate tasks, then in Travis run them in different steps.

Also to speed dev, and since tests don't run on OSX they will fail.

Compile/Build go code

./gradlew build

Run go tests

./gradlew tests

Build docker image

./gradlew distDocker

Mark readme as WIP

This will indicate to visitors, that we are still working and the repo/mage is not stable for general use.

Update to go 1.11.3

New minor version was released a few hours ago, we should update the runtime to this version.

Travis Test failing timeout TestStartLatestAction

This Travis build failed today
https://travis-ci.org/apache/incubator-openwhisk-runtime-go/jobs/381072767#L1150

Test TestStartLatestAction It doesn't return

=== RUN   TestStartLatestAction
2018/05/19 13:41:00 starting ./action/1/main
2018/05/19 13:41:00 run: start
2018/05/19 13:41:00 run: end
2018/05/19 13:41:00 removing the failed action in ./action/1/
2018/05/19 13:41:00 starting ./action/2/main
2018/05/19 13:41:00 run: start
2018/05/19 13:41:00 logger: start
2018/05/19 13:41:00 service: start
2018/05/19 13:41:00 >>>x
2018/05/19 13:41:00 <<<1
2018/05/19 13:41:00 starting ./action/3/main
2018/05/19 13:41:00 run: start
2018/05/19 13:41:00 stopping old executor
2018/05/19 13:41:00 stopping
2018/05/19 13:41:00 terminated upon request
2018/05/19 13:41:00 service: end
2018/05/19 13:41:00 service: start
2018/05/19 13:41:00 >>>y
2018/05/19 13:41:00 logger: start
2018/05/19 13:41:00 logger: end
2018/05/19 13:41:00 run: end
SIGQUIT: quit
PC=0x45c131 m=0 sigcode=0
goroutine 0 [idle]:
runtime.futex(0x92b248, 0x0, 0x0, 0x0, 0x0, 0xc420030000, 0x0, 0x0, 0x7fffab085338, 0x41083b, ...)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/runtime/sys_linux_amd64.s:530 +0x21
runtime.futexsleep(0x92b248, 0x7fff00000000, 0xffffffffffffffff)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/runtime/os_linux.go:45 +0x4b
runtime.notesleep(0x92b248)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/runtime/lock_futex.go:151 +0x9b
runtime.stopm()
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/runtime/proc.go:1952 +0xe5
runtime.exitsyscall0(0xc420080480)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/runtime/proc.go:3129 +0x109
runtime.mcall(0x0)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/runtime/asm_amd64.s:351 +0x5b
goroutine 1 [chan receive]:
testing.(*T).Run(0xc4201900f0, 0x765970, 0x15, 0x7781f8, 0x486ee6)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/testing/testing.go:825 +0x301
testing.runTests.func1(0xc420190000)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/testing/testing.go:1063 +0x64
testing.tRunner(0xc420190000, 0xc420065d58)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/testing/testing.go:777 +0xd0
testing.runTests(0xc42000c100, 0x923180, 0x6, 0x6, 0x0)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/testing/testing.go:1061 +0x2c4
testing.(*M).Run(0xc420164000, 0x0)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/testing/testing.go:978 +0x171
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.TestMain(0xc420164000)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/util_test.go:168 +0x83
main.main()
	_testmain.go:154 +0x208
goroutine 5 [chan receive]:
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.TestStartLatestAction(0xc4201900f0)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/actionProxy_linux_test.go:61 +0x3ad
testing.tRunner(0xc4201900f0, 0x7781f8)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/testing/testing.go:777 +0xd0
created by testing.(*T).Run
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/testing/testing.go:824 +0x2e0
goroutine 26 [chan send]:
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*Executor).run(0xc4200a1e50)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/executor.go:107 +0x18b
created by github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*Executor).Start
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/executor.go:178 +0x5e
goroutine 8 [IO wait]:
internal/poll.runtime_pollWait(0x7f768a571470, 0x72, 0xc420043c98)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/runtime/netpoll.go:173 +0x57
internal/poll.(*pollDesc).wait(0xc4200a1dc8, 0x72, 0xffffffffffffff01, 0x79fd00, 0x8ef608)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/internal/poll/fd_poll_runtime.go:85 +0x9b
internal/poll.(*pollDesc).waitRead(0xc4200a1dc8, 0xc420197001, 0x1000, 0x1000)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/internal/poll/fd_poll_runtime.go:90 +0x3d
internal/poll.(*FD).Read(0xc4200a1db0, 0xc420197000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/internal/poll/fd_unix.go:157 +0x17d
os.(*File).read(0xc42009e138, 0xc420197000, 0x1000, 0x1000, 0xc420047000, 0x0, 0xc420043da0)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/os/file_unix.go:226 +0x4e
os.(*File).Read(0xc42009e138, 0xc420197000, 0x1000, 0x1000, 0x1000, 0x1000, 0x721740)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/os/file.go:107 +0x6a
bufio.(*Scanner).Scan(0xc420164200, 0x79f280)
	/home/travis/.gimme/versions/go1.10.2.linux.amd64/src/bufio/scan.go:208 +0xbf
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*Executor).service(0xc4200a1e50)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/executor.go:161 +0x209
created by github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*Executor).Start
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/executor.go:185 +0x155
goroutine 9 [chan receive]:
github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*Executor).logger(0xc4200a1e50)
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/executor.go:136 +0x15a
created by github.com/apache/incubator-openwhisk-runtime-go/openwhisk.(*Executor).Start
	/home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/openwhisk/executor.go:186 +0x17a
rax    0xca
rbx    0x92b100
rcx    0x45c133
rdx    0x0
rdi    0x92b248
rsi    0x0
rbp    0x7fffab085300
rsp    0x7fffab0852b8
r8     0x0
r9     0x0
r10    0x0
r11    0x286
r12    0xffffffffffffffff
r13    0xa1
r14    0xa0
r15    0x100
rip    0x45c131
rflags 0x286
cs     0x33
fs     0x0
gs     0x0
*** Test killed with quit: ran too long (10m0s).
FAIL	github.com/apache/incubator-openwhisk-runtime-go/openwhisk	600.004s
Test for github.com/apache/incubator-openwhisk-runtime-go/openwhisk finished, 1 completed, 1 failed
Generating HTML test report...
Finished generating test html results (0.083 secs) into: /home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/.gogradle/reports/test
:test FAILED
:test (Thread[Task worker for ':',5,main]) completed. Took 10 mins 3.528 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There are 1 failed tests. Please see /home/travis/gopath/src/github.com/apache/incubator-openwhisk-runtime-go/.gogradle/repor

Use a more light weight base image

Currently using ubuntu base image FROM ibmcom/ubuntu:14.04
We should use instead a more light way image like official golang images golang:1.10.1

replace github.com/sciabarracom

Several references to sciabarracom github user/org
like build.gradle has github.com/sciabarracom/incubator-openwhisk-runtime-go

Should be replace with github.com/apache

go build main.go Rename the file to exec

go build main.go Rename the file to exec, and create exec.env, cat exec.env
openwhisk/action-golang-v1.16 An error occurred during the call. wsk action invoke gozip -r --param name "openwhisk" -i
{
"error": "Cannot start action. Check logs for details."
}

Can't run tests in OSX

I would be good to be able to run build and test image on OSX
Steps to replicate

./gradlew build

It times out.

Golang plugin system

I'm not sure if this is the appropriate place to ask, but I'm wondering why the Golang runtime spawns a subprocess instead of using the plugin system to dynamically load the function.

Did you decide one is better than the other for Golang?

The openwhisk/actionloop-v2 includes the dynamic executable

The build.gradle uses the "-static" but the image published on Docker Hub as "actionloop-v2" is still dymanically linked

docker run --entrypoint=ldd openwhisk/actionloop-v2  /bin/proxy
	linux-vdso.so.1 =>  (0x00007ffc35f65000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8e4aee2000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8e4ab18000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f8e4b0ff000)

Note that if I rebuild the runtime locally it is statically linked:

docker run --entrypoint=ldd whisk/actionloop-v2  /bin/proxy
	not a dynamic executable

Add Support For Golang Modules

As everyone is probably aware, golang added modules for dependency management starting in 1.11 as experimental and the default in 1.13. In modules, the major version of a dependency can be added to the import path. This style of imports is not supported with dep. So any go library that has started to use modules with major versioning, can't be used with dep.

Given modules is the now official way for dependency management, this is going to increasingly become a problem. There are libraries we need to use, but can't due to this issue. I propose adding an additional flag to the -compile run of the docker image that would enable go modules, like -modules.

This is a pretty easy change. I've created a custom version by adding "GO111MODULE": "on" to the environment variables of the go build command in gobuild.py. I also had to add another filter to the output to remove the modules information statements about downloading dependencies, since any output was treated as an error.

    o = re.sub(r"go: finding.*\n", "", o, flags=re.MULTILINE)
    o = re.sub(r"go: downloading.*\n", "", o, flags=re.MULTILINE)
    e = re.sub(r"go: finding.*\n", "", e, flags=re.MULTILINE)
    e = re.sub(r"go: downloading.*\n", "", e, flags=re.MULTILINE)

Cannot build the runtime

I followed these instructions. I'm getting this error:


FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':tests:testCompileClasspath'.
> Could not find org.apache.openwhisk:openwhisk-tests:1.0.0-SNAPSHOT.
  Searched in the following locations:
      https://repo1.maven.org/maven2/org/apache/openwhisk/openwhisk-tests/1.0.0-SNAPSHOT/maven-metadata.xml
      https://repo1.maven.org/maven2/org/apache/openwhisk/openwhisk-tests/1.0.0-SNAPSHOT/openwhisk-tests-1.0.0-SNAPSHOT.pom
      https://repo1.maven.org/maven2/org/apache/openwhisk/openwhisk-tests/1.0.0-SNAPSHOT/openwhisk-tests-1.0.0-SNAPSHOT-tests.jar
  Required by:
      project :tests

proxy doesn't handle unicode conformance for OpenWhisk.

the proxy should be able to handle input JSON and output if it wants the same exact JSON output.

Currently it returns nil for unicode input

wsk action invoke golangfunc -p winter "❄ ☃ ❄" -r

The expected output should be:

{
"winter": "❄ ☃ ❄"
}

But the output is not is nil

{
"winter": nil
}

cc @sciabarra

Docs update needed: ACTION.md

Noticed this while reading the docs:

The payload of the request is stored in the key value. The action should read the field value assuming it is a JSON object (note, not an array, nor a string or number) and parse it.

I know there are a few PRs people were working on to add support for JSON arrays in addition to objects. I'm not involved in that so I don't know exactly when all docs need to be updated, but it looks like this will need to be updated when it's the right time to do so.

Change function Main signature to match OpenWhisk base Conformance JSON IN<->OUT

Currently the main function signature takes 1 input (raw []bytes) and returns 2 outputs (raw [] bytes, error)
I think is ok to have alternative signatures like we do for Swift and Codable, and 1 input, an 0 output.
This is done to adapt better with developer experience and the language idioms

But the base OW signature is the building block and the first one to be offer.

Currently the signature is

func Main(event json.RawMessage) (json.RawMessage, error)

In example:

// Main is the function implementing the action
func Main(event json.RawMessage) (json.RawMessage, error) {
  // decode the json
  var obj map[string]interface{}
  json.Unmarshal(event, &obj)
  // do your work
  name, ok := obj["name"].(string)
  if !ok {
    name = "Stranger"
  }
  msg := map[string]string{"message": ("Hello, " + name + "!")}
  // log in stdout or in stderr
  log.Printf("name=%s\n", name)
  // encode the result back in json
  return json.Marshal(msg)
}

This also has a drawback that dev will be 99% will be unmarshalling the input and the output.
in the way in

  var obj map[string]interface{}
  json.Unmarshal(event, &obj)

in the way out

json.Marshal(msg)

I propose we start with this base signature instead:

func Main(params map[string]interface{}) map[string]interface{} 

in example much simple for developer to deal with

func Main(params map[string]interface{}) map[string]interface{} {
	name, ok := params["name"].(string)
	if !ok {
		name = "World"
	}
	var result = make(map[string]interface{})
	result["body"] = "Hello " + name
	return result
}

to return error same base API for OW, return a error key in the out

...
myError["message"] = "My error msg here for OW to bubble up"
result["error"] = myError
return result

cc @sciabarra @rabbah

Go actions not working using source and image

I can't get go source action to run

Steps to replicate:
Build image

./gradle distDocker

Then use invoke.py from main repo

~/dev/whisk/git/apache/incubator-openwhisk/actionRuntimes/actionProxy (master)
😄  $ ./invoke.py init /Users/csantana23/dev/whisk/git/apache/incubator-openwhisk-runtime-go/test/src/hello_message.go
{"error":"cannot start action: command exited"}

Try to use docker image on already deploy openwhisk and got same problem

~/dev/whisk/git/apache/incubator-openwhisk-runtime-go (pr-8)
👻  $ bx wsk action update goaction test/src/hello_message.go --docker csantanapr/actionloop-golang-v1.9
ok: updated action goaction
~/dev/whisk/git/apache/incubator-openwhisk-runtime-go (pr-8)
👻  $ bx wsk action invoke goaction -b
ok: invoked /_/goaction with id 9277763eb33a4992b7763eb33a5992cf
{
    "activationId": "9277763eb33a4992b7763eb33a5992cf",
    "response": {
        "result": {
            "error": "cannot start action: command exited"
        },
        "status": "action developer error",
        "success": false
    },

}

Custom http status after function invocation

Hello,

I'm trying to write a web action that can return back different http status codes, but docs say nothing about it. I looked at the code and found that the launcher.go just forwards the returned map back to executor and the executor itself doesn't set any status into ResponceWriter (thus defauling it to StatusOK?).

If someone would want to patch the launcher/executor to allow actions return custom status, what would be the best way to do it?

One test fails in Ubuntu Xenial

One tests always fails on Xenial Ubuntu

Steps to reproduce, use the vagrant from openwhisk.
Setup Ubuntu

# Clone openwhisk
git clone --depth=1 https://github.com/apache/incubator-openwhisk.git openwhisk

# Change directory to tools/vagrant
cd openwhisk/tools/vagrant

# Run script to create vm and run hello action
./hello

Then login into vagrant and install go 1.9.2

vagrant ssh
mkdir bin
curl -sL -o ~/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
chmod +x ~/bin/gimme
eval "$(gimme 1.9.2)"

Then git clone this repo and run build and test

git clone https://github.com/apache/incubator-openwhisk-runtime-go
cd incubator-openwhisk-runtime-go
./gradlew build
vagrant@ubuntu-xenial:~/git/incubator-openwhisk-runtime-go$ ./gradlew build

> Configure project :
Found go 1.9.2 in /home/vagrant/.gimme/versions/go1.9.2.linux.amd64/bin/go, use it.

> Task :prepare
Use project GOPATH: /home/vagrant/git/incubator-openwhisk-runtime-go/.gogradle/project_gopath

> Task :test
Test for github.com/sciabarracom/incubator-openwhisk-runtime-go/test/src/hello finished, 3 completed, 0 failed
Test for github.com/sciabarracom/incubator-openwhisk-runtime-go/openwhisk finished, 18 completed, 1 failed


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There are 1 failed tests. Please see /home/vagrant/git/incubator-openwhisk-runtime-go/.gogradle/reports/test/index.html for more details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 10m 40s
6 actionable tasks: 4 executed, 2 up-to-date

Test that fails

=== RUN   ExampleNewExecutor_bc
2018/05/01 03:01:49 run: start
2018/05/01 03:01:49 run: end
*** Test killed: ran too long (10m0s).
FAIL	github.com/sciabarracom/incubator-openwhisk-runtime-go/openwhisk	605.005s

import package can not be compiled with the vendor folder

 zip -r - * | docker run -i openwhisk/actionloop-golang-v1.11 -compile main.go  >main

  adding: vendor/golang.org/x/sys/unix/race0.go (deflated 43%)
  adding: vendor/golang.org/x/sys/unix/syscall_linux_gc_386.go (deflated 44%)
  adding: vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go (deflated 70%)
  adding: vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go (deflated 50%)
  adding: vendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go (deflated 90%)
2018/09/28 18:46:06 func_main.go_.go:4:2: cannot find package "github.com/Sirupsen/logrus" in any of:
	/usr/local/go/src/github.com/Sirupsen/logrus (from $GOROOT)
	/action/action/1/src/github.com/Sirupsen/logrus (from $GOPATH)

The input file is attached.

wsk-go.zip

VSCode example setup for dev and test

VSCode is very popular among go developers, it would be useful to doc how to setup a typical project for an Action.
Like

src/hello
src/hello_test.go
main.go

If VSCode is setup with "go.inferGopath": true then it will detect the project, and opening hello_test.go and clicking Debug it will run the tests.

FAIL: Example_badinit_nocompiler

Build in travis is failing
https://travis-ci.org/apache/incubator-openwhisk-runtime-go/builds/373762183#L1197

--- FAIL: Example_badinit_nocompiler (1.11s)
got:
400 {"error":"no action defined yet"}
200 {"ok":true}
400 {"error":"cannot start action: command exited"}
400 {"error":"cannot start action: command exited"}
200 {"ok":true}
400 {"error":"command exited"}
want:
400 {"error":"no action defined yet"}
200 {"ok":true}
400 {"error":"cannot start action: command exited"}
400 {"error":"cannot start action: command exited"}
400 {"error":"cannot start action: command exited"}
400 {"error":"no action defined yet"}
=== RUN   Example_bininit_nocompiler

Same test passed when it was from the PR
https://travis-ci.org/apache/incubator-openwhisk-runtime-go/builds/373761010#L1208

Remove redundant Unmarshal in `gobuild.py.launcher.go`

Below are lines 71–91 of common/gobuild.py.launcher.go. Line 83 appears to be redundant and unnecessary, as it is the same as line 73, which has already unmarshalled the data.

https://github.com/apache/incubator-openwhisk-runtime-go/blob/1cbb96383502ca6df45058d966927c0796c31fbd/common/gobuild.py.launcher.go#L83

https://github.com/apache/incubator-openwhisk-runtime-go/blob/1cbb96383502ca6df45058d966927c0796c31fbd/common/gobuild.py.launcher.go#L73

		// parse one line
		var input map[string]interface{}
		err = json.Unmarshal(inbuf, &input)  // Line 73
		if err != nil {
			log.Println(err.Error())
			fmt.Fprintf(out, "{ error: %q}\n", err.Error())
			continue
		}
		if debug {
			log.Printf("%v\n", input)
		}
		// set environment variables
		err = json.Unmarshal(inbuf, &input)  // Line 83: Appears to be redundant.
		for k, v := range input {
			if k == "value" {
				continue
			}
			if s, ok := v.(string); ok {
				os.Setenv("__OW_"+strings.ToUpper(k), s)
			}
		}

Pin go dependencies

We need to list and pin all the go dependencies.
With this we need to document their respective dependencies for Apache Software Foundation

This also helps a bit for stability

Failing to write a response containing headers

Hello,

I am currently trying to create a response containing headers in openwhisk with golang.
I feel like I need a nested map with different value types. But since golang is strongly-typed that is impossible.
I tried to marshal a struct, but failed since the Main functions wants a map as return value.

My best try as response is:

  outobj := make(map[string]interface{})
  outobj["headers"] = "{\"Content-Type\": \"text/html\"}"
  outobj["statusCode"] = 201
  outobj["body"] = "123"
  return outobj

But invoking that action gives an http error.
The reason for that error is the content of the "headers" key. Uncommenting it makes the action work.

Can someone provide an example how to set headers in the golang response?

Travis Test failing randomly: Example_shell_nocompiler missing Goodbye!

Today May 19th Travis build failed: https://travis-ci.org/apache/incubator-openwhisk-runtime-go/builds/381051039#L1380

=== RUN   Example_shell_nocompiler
2018/05/19 11:53:01 /tmp/action839309642
2018/05/19 11:53:01 http://127.0.0.1:40685
2018/05/19 11:53:01 binary
2018/05/19 11:53:01 starting /tmp/action839309642/1/main
2018/05/19 11:53:01 run: start
2018/05/19 11:53:01 service: start
2018/05/19 11:53:01 logger: start
2018/05/19 11:53:01 >>>{"name":"Mike"}
2018/05/19 11:53:01 <<<{"hello": "Mike"}
2018/05/19 11:53:01 {"hello": "Mike"}
2018/05/19 11:53:01 >>>{"name":"*"}
2018/05/19 11:53:01 run: end
--- FAIL: Example_shell_nocompiler (1.03s)
got:
400 {"error":"no action defined yet"}
200 {"ok":true}
200 {"hello": "Mike"}
400 {"error":"command exited"}
400 {"error":"no action defined yet"}
msg=hello Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
want:
400 {"error":"no action defined yet"}
200 {"ok":true}
200 {"hello": "Mike"}
400 {"error":"command exited"}
400 {"error":"no action defined yet"}
msg=hello Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Goodbye!
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX

Update Apache license with third party content

We need to include in the License all 3rd party dependencies

Some would be hard dependencies source that we compiled into final compiled artifact.
Some would be we depend on like test frameworks, or go runtime.
These licenses would also need to be included in the repo

See the runtime-nodejs as an example:
https://github.com/apache/incubator-openwhisk-runtime-nodejs/blob/master/LICENSE.txt
https://github.com/apache/incubator-openwhisk-runtime-nodejs/tree/master/licenses

cc @houshengbo @sciabarracom

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.