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

Tracing #1

Merged
merged 8 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Build Status](https://travis-ci.org/s8sg/faaschain.svg?branch=master)](https://travis-ci.org/s8sg/faaschain)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![GoDoc](https://godoc.org/github.com/s8sg/faaschain?status.svg)](https://godoc.org/github.com/s8sg/faaschain)
[![OpenTracing Badge](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io)
[![OpenFaaS](https://img.shields.io/badge/openfaas-serverless-blue.svg)](https://www.openfaas.com)

> **Pure FaaS**
Expand Down Expand Up @@ -72,6 +73,8 @@ faas-cli new test-chain --lang faaschain
write_timeout: 120
write_debug: true
combine_output: false
enable_tracing: true
trace_server: "jaegertracing:5775"
```
> `gateway` : We need to tell faaschain the address of openfaas gateway
> ```
Expand All @@ -85,8 +88,19 @@ faas-cli new test-chain --lang faaschain
> `write_timeout` : A value larger than `max` phase execution time.
> `write_debug`: It enables the debug msg in logs.
> `combine_output` : It allows debug msg to be excluded from `output`.
> `enable_tracing` : It ebales the opentracing for requests and their phases.
> `trace_server` : The address of opentracing backend jaeger.


#### Start The Trace Server (jaeger - opentracing-1.x)
To start the trace server we run `jaegertracing/all-in-one` as a service.
```bash
docker service rm jaegertracing
docker pull jaegertracing/all-in-one:latest
docker service create --constraint="node.role==manager" --detach=true \
--network func_functions --name jaegertracing -p 5775:5775/udp -p 16686:16686 \
jaegertracing/all-in-one:latest
```

#### **Edit the `test-chain/handler.go`:**.
```go
chain.Apply("myfunc1", map[string]string{"method": "post"}, nil).
Expand Down Expand Up @@ -132,13 +146,27 @@ cat data | faas-cli invoke --async -f test-chain.yml test-chain
Function submitted asynchronously.
```

## Request Tracking
## Request Tracking by ID
Request can be tracked from the log by `RequestId`. For each new Request a unique `RequestId` is generated.
```bash
2018/08/13 07:51:59 [request `bdojh7oi7u6bl8te4r0g`] Created
2018/08/13 07:52:03 [Request `bdojh7oi7u6bl8te4r0g`] Received
```

## Request Tracing by Open-Tracing
Request tracing can be enabled by providing by specifying
```yaml
enable_tracing: true
trace_server: "jaegertracing:5775"
```
Below is an example of tracing for an async request with 3 phases
![alt multi phase](https://github.com/s8sg/faaschain/blob/tracing/doc/tracing.png)

> *Due to some unresolved issue we can't extend the req span over multiple phases
> we use the waterfall model as an workaround
> For more details visit : https://github.com/opentracing/specification/issues/81


## TODO:
- [ ] Export support for Debug
> Request Execution Status.
Expand Down
2 changes: 1 addition & 1 deletion ci/script/buildlib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Run a gofmt and exclude all vendored code.
test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./example/*" -not -path "./faaschain/*" -not -path "./" ))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }
test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./example/*" -not -path "./template/*" -not -path "./doc/*" -not -path "./ci/" -not -path "./" ))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }

go test ./chain.go ./chain_test.go -cover
Binary file added doc/tracing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions example/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ functions:
write_timeout: 120
write_debug: true
combine_output: false
enable_tracing: true
trace_server: "jaegertracing:5775"


upload-chain-async:
Expand All @@ -28,6 +30,8 @@ functions:
write_timeout: 120
write_debug: true
combine_output: false
enable_tracing: true
trace_server: "jaegertracing:5775"

colorization:
lang: Dockerfile
Expand Down
1 change: 1 addition & 0 deletions example/upload-chain-async/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func Define(chain *faaschain.Fchain) (err error) {

// Define Chain
chain.Apply("colorization", map[string]string{"method": "post"}, nil).
ApplyAsync("image-resizer", map[string]string{"method": "post"}, nil).
ApplyAsync("image-resizer", map[string]string{"method": "post"}, nil).
ApplyModifier(func(data []byte) ([]byte, error) {
client := &http.Client{}
Expand Down
2 changes: 1 addition & 1 deletion sdk/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

type Chain struct {
Phases []*Phase `json:"-"` // Phases that will be executed in async
Phases []*Phase `json:"phases"` // Phases that will be executed in async
ExecutionPosition int `json:"position"` // Position of Executor
}

Expand Down
10 changes: 5 additions & 5 deletions sdk/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
type Modifier func([]byte) ([]byte, error)

type Function struct {
Function string `json:"-"` // The name of the function
CallbackUrl string `json:"-"` // Callback Url
Mod Modifier `json:"-"` // Modifier
Header map[string]string `json:"-"` // The HTTP call header
Param map[string][]string `json:"-"` // The Parameter in Query string
Function string `json:"function"` // The name of the function
CallbackUrl string `json:"callback"` // Callback Url
Mod Modifier `json:"-"` // Modifier
Header map[string]string `json:"header"` // The HTTP call header
Param map[string][]string `json:"param"` // The Parameter in Query string
}

// Create a function with execution name
Expand Down
2 changes: 1 addition & 1 deletion sdk/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sdk

type Phase struct {
// The list of function in the Phase
Functions []*Function `json:"-"`
Functions []*Function `json:"functions"`
}

func CreateExecutionPhase() *Phase {
Expand Down
2 changes: 1 addition & 1 deletion sdk/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
type Request struct {
Sign string `json: "sign"`
ID string `json: "id"`
Chaindef string `json: "-"`
Data []byte `json: "data"`
Chaindef string `json: "-"`
}

const (
Expand Down
Loading