Skip to content

Commit

Permalink
Add log shim and collect command
Browse files Browse the repository at this point in the history
The collect command redirects function logs to the journal for
viewing on journalctl. faas-cli logs is not implemented as of
yet. View logs with journalctl -t openfaas-fn:FN_NAME_HERE.

Tested on Dell XPS with Ubuntu Linux. The approach takes
inspiration from the Stellar project.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Feb 23, 2020
1 parent 853830c commit 2307fc7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ ofc-bootstrap registry-login --username <your-registry-username> --password-stdi
```
The file will be created in `./credentials/`

### Logs for functions

You can view the logs of functions using `journalctl`:

```bash
journalctl -t openfaas-fn:FUNCTION_NAME


faas-cli store deploy figlet
journalctl -t openfaas-fn:figlet -f &
echo logs | faas-cli invoke figlet
```

### Manual / developer instructions

See [here for manual / developer instructions](docs/DEV.md)
Expand Down
4 changes: 4 additions & 0 deletions cmd/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/spf13/cobra"
)

func CollectCommand() *cobra.Command {
return collectCmd
}

var collectCmd = &cobra.Command{
Use: "collect",
Short: "Collect logs to the journal",
Expand Down
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func init() {
rootCommand.AddCommand(collectCmd)
}

func RootCommand() *cobra.Command {
return rootCommand
}

var (
// GitCommit Git Commit SHA
GitCommit string
Expand Down
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"os"

"github.com/openfaas/faasd/cmd"
Expand All @@ -15,6 +16,21 @@ var (
)

func main() {

if _, ok := os.LookupEnv("CONTAINER_ID"); ok {
collect := cmd.RootCommand()
collect.SetArgs([]string{"collect"})
collect.SilenceUsage = true
collect.SilenceErrors = true

err := collect.Execute()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
os.Exit(0)
}

if err := cmd.Execute(Version, GitCommit); err != nil {
os.Exit(1)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/provider/handlers/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container
func createTask(ctx context.Context, client *containerd.Client, container containerd.Container, cni gocni.CNI) error {

name := container.ID()
task, taskErr := container.NewTask(ctx, cio.NewCreator(cio.WithStdio))
// task, taskErr := container.NewTask(ctx, cio.NewCreator(cio.WithStdio))

task, taskErr := container.NewTask(ctx, cio.BinaryIO("/usr/local/bin/faasd", nil))

if taskErr != nil {
return fmt.Errorf("unable to start task: %s, error: %s", name, taskErr)
}
Expand Down

0 comments on commit 2307fc7

Please sign in to comment.