diff --git a/README.md b/README.md index 0b48e16f..3527ffea 100644 --- a/README.md +++ b/README.md @@ -276,10 +276,10 @@ curl -H "Content-Type: application/json" -X POST -d '{ }' http://localhost:8080/r/myapp/hello-async ``` -You will get a `call_id` in the response: +You will get a `task_id` in the response: ```json -{"call_id":"572415fd-e26e-542b-846f-f1f5870034f2"} +{"task_id":"572415fd-e26e-542b-846f-f1f5870034f2"} ``` If you watch the logs, you will see the function actually runs in the background: diff --git a/api/mqs/bolt.go b/api/mqs/bolt.go index 8e83257b..f7b4470c 100644 --- a/api/mqs/bolt.go +++ b/api/mqs/bolt.go @@ -205,7 +205,7 @@ func (mq *BoltDbMQ) delayTask(job *models.Task) (*models.Task, error) { } func (mq *BoltDbMQ) Push(ctx context.Context, job *models.Task) (*models.Task, error) { - ctx, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + ctx, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) log.Println("Pushed to MQ") if job.Delay > 0 { @@ -315,7 +315,7 @@ func (mq *BoltDbMQ) Reserve(ctx context.Context) (*models.Task, error) { return nil, err } - _, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + _, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) log.Println("Reserved") return &job, nil @@ -325,7 +325,7 @@ func (mq *BoltDbMQ) Reserve(ctx context.Context) (*models.Task, error) { } func (mq *BoltDbMQ) Delete(ctx context.Context, job *models.Task) error { - _, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + _, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) defer log.Println("Deleted") return mq.db.Update(func(tx *bolt.Tx) error { diff --git a/api/mqs/memory.go b/api/mqs/memory.go index bcb8b4da..4043e569 100644 --- a/api/mqs/memory.go +++ b/api/mqs/memory.go @@ -112,7 +112,7 @@ func (ji *TaskItem) Less(than btree.Item) bool { } func (mq *MemoryMQ) Push(ctx context.Context, job *models.Task) (*models.Task, error) { - _, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + _, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) log.Println("Pushed to MQ") // It seems to me that using the job ID in the reservation is acceptable since each job can only have one outstanding reservation. @@ -173,13 +173,13 @@ func (mq *MemoryMQ) Reserve(ctx context.Context) (*models.Task, error) { return nil, nil } - _, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + _, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) log.Println("Reserved") return job, mq.pushTimeout(job) } func (mq *MemoryMQ) Delete(ctx context.Context, job *models.Task) error { - _, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + _, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) mq.Mutex.Lock() defer mq.Mutex.Unlock() diff --git a/api/mqs/redis.go b/api/mqs/redis.go index 6a3b4271..72e5b083 100644 --- a/api/mqs/redis.go +++ b/api/mqs/redis.go @@ -210,7 +210,7 @@ func (mq *RedisMQ) delayTask(conn redis.Conn, job *models.Task) (*models.Task, e } func (mq *RedisMQ) Push(ctx context.Context, job *models.Task) (*models.Task, error) { - _, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + _, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) defer log.Println("Pushed to MQ") conn := mq.pool.Get() @@ -280,14 +280,14 @@ func (mq *RedisMQ) Reserve(ctx context.Context) (*models.Task, error) { return nil, err } - _, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + _, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) log.Println("Reserved") return &job, nil } func (mq *RedisMQ) Delete(ctx context.Context, job *models.Task) error { - _, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": job.ID}) + _, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": job.ID}) defer log.Println("Deleted") conn := mq.pool.Get() diff --git a/api/runner/async_runner.go b/api/runner/async_runner.go index af9df792..dcb06e20 100644 --- a/api/runner/async_runner.go +++ b/api/runner/async_runner.go @@ -124,7 +124,7 @@ func startAsyncRunners(ctx context.Context, url string, tasks chan task.Request, continue } - ctx, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": task.ID}) + ctx, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": task.ID}) log.Debug("Running task:", task.ID) wg.Add(1) diff --git a/api/runner/func_logger.go b/api/runner/func_logger.go index 88602b87..950f669f 100644 --- a/api/runner/func_logger.go +++ b/api/runner/func_logger.go @@ -25,7 +25,7 @@ func (l *DefaultFuncLogger) Writer(ctx context.Context, appName, path, image, re r, w := io.Pipe() log := common.Logger(ctx) - log = log.WithFields(logrus.Fields{"user_log": true, "app_name": appName, "path": path, "image": image, "call_id": reqID}) + log = log.WithFields(logrus.Fields{"user_log": true, "app_name": appName, "path": path, "image": image, "task_id": reqID}) go func(reader io.Reader) { scanner := bufio.NewScanner(reader) diff --git a/api/server/runner.go b/api/server/runner.go index 818222f5..d8159e00 100644 --- a/api/server/runner.go +++ b/api/server/runner.go @@ -76,7 +76,7 @@ func (s *Server) handleRequest(c *gin.Context, enqueue models.Enqueue) { ctx := c.MustGet("ctx").(context.Context) reqID := uuid.NewV5(uuid.Nil, fmt.Sprintf("%s%s%d", c.Request.RemoteAddr, c.Request.URL.Path, time.Now().Unix())).String() - ctx, log := common.LoggerWithFields(ctx, logrus.Fields{"call_id": reqID}) + ctx, log := common.LoggerWithFields(ctx, logrus.Fields{"task_id": reqID}) var err error var payload io.Reader @@ -228,7 +228,7 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun // Push to queue enqueue(c, s.MQ, task) log.Info("Added new task to queue") - c.JSON(http.StatusAccepted, map[string]string{"call_id": task.ID}) + c.JSON(http.StatusAccepted, map[string]string{"task_id": task.ID}) default: result, err := runner.RunTask(s.tasks, ctx, cfg) diff --git a/api/server/server.go b/api/server/server.go index e7fce276..1e5c66c7 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -125,7 +125,7 @@ func prepareMiddleware(ctx context.Context) gin.HandlerFunc { } func DefaultEnqueue(ctx context.Context, mq models.MessageQueue, task *models.Task) (*models.Task, error) { - ctx, _ = common.LoggerWithFields(ctx, logrus.Fields{"call_id": task.ID}) + ctx, _ = common.LoggerWithFields(ctx, logrus.Fields{"task_id": task.ID}) return mq.Push(ctx, task) } diff --git a/docs/definitions.md b/docs/definitions.md index 87d13a6c..1b716468 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -119,7 +119,7 @@ Options: `sync` and `async` `type` is defines how the function will be executed. If type is `sync` the request will be hold until the result is ready and flushed. -In `async` functions the request will be ended with a `call_id` and the function will be executed in the background. +In `async` functions the request will be ended with a `task_id` and the function will be executed in the background. #### memory (number) diff --git a/docs/operating/logging.md b/docs/operating/logging.md index 48383bcc..b359748b 100644 --- a/docs/operating/logging.md +++ b/docs/operating/logging.md @@ -10,18 +10,18 @@ We recommend using [logspout](https://github.com/gliderlabs/logspout) to forward All logs are emitted in [logfmt](https://godoc.org/github.com/kr/logfmt) format for easy parsing. -## Call ID +## TASK ID -Every function call/request is assigned a `call_id`. If you search your logs, you can track all the activity -for each function call and find errors on a call by call basis. For example, these are the log lines for an aynschronous +Every function call/request is assigned a `task_id`. If you search your logs, you can track all the activity +for each function call and find errors on a call by call basis. For example, these are the log lines for an asynchronous function call: ![async logs](/docs/assets/async-log-full.png) -Note the easily searchable `call_id=x` format. +Note the easily searchable `task_id=x` format. ```sh -call_id=477949e2-922c-5da9-8633-0b2887b79f6e +task_id=477949e2-922c-5da9-8633-0b2887b79f6e ``` ## Metrics