From 5ec63e7f3880453386507bcc2de24044e0151a9d Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Wed, 1 Mar 2017 23:32:45 +0700 Subject: [PATCH] Switch from call_id to task_id for consistency Partially addresses: #415 --- README.md | 4 ++-- api/mqs/bolt.go | 6 +++--- api/mqs/memory.go | 6 +++--- api/mqs/redis.go | 6 +++--- api/runner/async_runner.go | 2 +- api/runner/func_logger.go | 2 +- api/server/runner.go | 4 ++-- api/server/server.go | 2 +- docs/definitions.md | 2 +- docs/operating/logging.md | 10 +++++----- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 14be83d7..7c60c34a 100644 --- a/README.md +++ b/README.md @@ -275,10 +275,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 1909e47f..eb75e69f 100644 --- a/api/runner/async_runner.go +++ b/api/runner/async_runner.go @@ -120,7 +120,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 6b800632..ad9fa963 100644 --- a/api/server/runner.go +++ b/api/server/runner.go @@ -73,7 +73,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 @@ -220,7 +220,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 8ad9b113..04438e3f 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