From 9a1a96daf0ec8c8fe138a78ebf1bc9e214bafc35 Mon Sep 17 00:00:00 2001 From: shohamroditimemphis Date: Mon, 26 Jun 2023 14:30:19 +0300 Subject: [PATCH 1/2] fix GetAllActiveUsers --- db/db.go | 6 +++--- models/monitoring.go | 2 +- server/memphis_cloud.go | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/db/db.go b/db/db.go index b43e3f597..c101172cc 100644 --- a/db/db.go +++ b/db/db.go @@ -4419,9 +4419,9 @@ func GetAllActiveUsers(tenantName string) ([]models.FilteredUser, error) { defer conn.Release() query := ` SELECT DISTINCT u.username - FROM users u - JOIN stations s ON u.id = s.created_by - WHERE tenant_name=$1 + FROM users AS u + JOIN stations AS s ON u.id = s.created_by + WHERE s.tenant_name=$1 ` stmt, err := conn.Conn().Prepare(ctx, "get_all_active_users", query) if err != nil { diff --git a/models/monitoring.go b/models/monitoring.go index 58bee716b..0368f2999 100644 --- a/models/monitoring.go +++ b/models/monitoring.go @@ -58,8 +58,8 @@ type GetStationOverviewDataSchema struct { type SystemLogsRequest struct { LogType string `form:"log_type" json:"log_type" binding:"required"` - StartIdx int `form:"start_index" json:"start_index" binding:"required"` LogSource string `form:"log_source" json:"log_source"` + StartIdx int `form:"start_index" json:"start_index" binding:"required"` } type Log struct { diff --git a/server/memphis_cloud.go b/server/memphis_cloud.go index e71994684..e0c75fe03 100644 --- a/server/memphis_cloud.go +++ b/server/memphis_cloud.go @@ -871,6 +871,11 @@ func (mh MonitoringHandler) GetSystemLogs(c *gin.Context) { } logSource := request.LogSource + if logSource == "" { + serv.Warnf("GetSystemLogs: log_source should be one of the following: empty or memphis-{number between 1 to amount of clusters}") + c.AbortWithStatusJSON(SHOWABLE_ERROR_STATUS_CODE, gin.H{"message": "log_source should be one of the following: empty or memphis-{number between 1 to amount of clusters}"}) + return + } if filterSubjectSuffix != _EMPTY_ { if request.LogSource != "empty" && request.LogType != "external" { filterSubject = fmt.Sprintf("%s.%s.%s", syslogsStreamName, logSource, filterSubjectSuffix) From 0a13a77a4f73748edbc0598374c31131cb302443 Mon Sep 17 00:00:00 2001 From: shohamroditimemphis Date: Mon, 26 Jun 2023 15:26:46 +0300 Subject: [PATCH 2/2] fix --- server/memphis_cloud.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server/memphis_cloud.go b/server/memphis_cloud.go index e0c75fe03..196c1140e 100644 --- a/server/memphis_cloud.go +++ b/server/memphis_cloud.go @@ -871,18 +871,13 @@ func (mh MonitoringHandler) GetSystemLogs(c *gin.Context) { } logSource := request.LogSource - if logSource == "" { - serv.Warnf("GetSystemLogs: log_source should be one of the following: empty or memphis-{number between 1 to amount of clusters}") - c.AbortWithStatusJSON(SHOWABLE_ERROR_STATUS_CODE, gin.H{"message": "log_source should be one of the following: empty or memphis-{number between 1 to amount of clusters}"}) - return - } if filterSubjectSuffix != _EMPTY_ { - if request.LogSource != "empty" && request.LogType != "external" { + if request.LogSource == "empty" || request.LogSource == "" { + filterSubject = fmt.Sprintf("%s.%s.%s", syslogsStreamName, "*", filterSubjectSuffix) + } else if request.LogSource != "empty" && request.LogType != "external" { filterSubject = fmt.Sprintf("%s.%s.%s", syslogsStreamName, logSource, filterSubjectSuffix) } else if request.LogSource != "empty" && request.LogType == "external" { filterSubject = fmt.Sprintf("%s.%s.%s.%s", syslogsStreamName, logSource, "extern", ">") - } else { - filterSubject = fmt.Sprintf("%s.%s.%s", syslogsStreamName, "*", filterSubjectSuffix) } }