This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 70128dc2 [feat-2742]: Handle logging config (#2781)
70128dc2 is described below
commit 70128dc2524e5d5d99804de93c8fc13689a90d5e
Author: Keon Amini <[email protected]>
AuthorDate: Wed Aug 24 02:27:27 2022 -0500
[feat-2742]: Handle logging config (#2781)
* feat: add default logging directory
* feat: logging dir added to docker-compose instead
* fix: remove default logging dir setting from src code
* feat: return 404 if logs don't exist
* fix: update swagger doc with 404
* refactor: more detailed missing-logs error message
---
.env.example | 2 +-
api/pipelines/pipelines.go | 9 +++++++--
docker-compose.yml | 3 +++
services/pipeline.go | 8 ++++----
4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/.env.example b/.env.example
index 2214b354..42f9a303 100644
--- a/.env.example
+++ b/.env.example
@@ -27,7 +27,7 @@ TEMPORAL_URL=
TEMPORAL_TASK_QUEUE=
# Debug Info Warn Error
LOGGING_LEVEL=
-LOGGING_DIR=./logs
+LOGGING_DIR=
##########################
# Sensitive information encryption key
diff --git a/api/pipelines/pipelines.go b/api/pipelines/pipelines.go
index d6cbb5e4..377d1e70 100644
--- a/api/pipelines/pipelines.go
+++ b/api/pipelines/pipelines.go
@@ -18,6 +18,7 @@ limitations under the License.
package pipelines
import (
+ goerror "errors"
"github.com/apache/incubator-devlake/errors"
"net/http"
"os"
@@ -181,7 +182,7 @@ GET /pipelines/:pipelineId/logging.tar.gz
// @Param pipelineId path int true "query"
// @Success 200 "The archive file"
// @Failure 400 {string} errcode.Error "Bad Request"
-// @Failure 404 {string} errcode.Error "Pipeline not found"
+// @Failure 404 {string} errcode.Error "Pipeline or Log files not found"
// @Failure 500 {string} errcode.Error "Internel Error"
// @Router /pipelines/{pipelineId}/logging.tar.gz [get]
func DownloadLogs(c *gin.Context) {
@@ -202,7 +203,11 @@ func DownloadLogs(c *gin.Context) {
}
archive, err := services.GetPipelineLogsArchivePath(pipeline)
if err != nil {
- shared.ApiOutputError(c, err, http.StatusInternalServerError)
+ if goerror.Is(err, os.ErrNotExist) {
+ shared.ApiOutputError(c, err, http.StatusNotFound)
+ } else {
+ shared.ApiOutputError(c, err,
http.StatusInternalServerError)
+ }
return
}
defer os.Remove(archive)
diff --git a/docker-compose.yml b/docker-compose.yml
index aee2117d..5782e153 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -71,6 +71,9 @@ services:
restart: always
volumes:
- ./.env:/app/.env
+ - ./logs:/app/logs
+ environment:
+ LOGGING_DIR: /app/logs
depends_on:
- mysql
diff --git a/services/pipeline.go b/services/pipeline.go
index be6774a5..820a306b 100644
--- a/services/pipeline.go
+++ b/services/pipeline.go
@@ -389,13 +389,13 @@ func CancelPipeline(pipelineId uint64) error {
// getPipelineLogsPath gets the logs directory of this pipeline
func getPipelineLogsPath(pipeline *models.Pipeline) (string, error) {
pipelineLog := getPipelineLogger(pipeline)
- path := filepath.Dir(pipelineLog.GetConfig().Path)
+ path := pipelineLog.GetConfig().Path
_, err := os.Stat(path)
if err == nil {
- return path, nil
+ return filepath.Dir(path), nil
}
if os.IsNotExist(err) {
- return "", fmt.Errorf("logs for pipeline #%d not found: %v",
pipeline.ID, err)
+ return "", fmt.Errorf("logs for pipeline #%d not found. You may
be missing the LOGGING_DIR setting: %w", pipeline.ID, err)
}
- return "", fmt.Errorf("err validating logs path for pipeline #%d: %v",
pipeline.ID, err)
+ return "", fmt.Errorf("err validating logs path for pipeline #%d: %w",
pipeline.ID, err)
}