dmohan001c commented on a change in pull request #6235:
URL: https://github.com/apache/trafficcontrol/pull/6235#discussion_r717239095
##########
File path: docs/source/api/v4/logs.rst
##########
@@ -37,7 +37,7 @@ Request Structure
+===========+==========+=====================================================================================================================================+
| days | no | An integer number of days of change logs to
return
|
+-----------+----------+-------------------------------------------------------------------------------------------------------------------------------------+
- | limit | no | The number of records to which to limit the
response
|
+ | limit | no | The number of records to which to limit the
response, by default it will display all the response
|
Review comment:
Fixed the malformed tables.
##########
File path: traffic_ops/traffic_ops_golang/logs/log.go
##########
@@ -135,11 +163,64 @@ FROM "log" as l JOIN tm_user as u ON l.tm_user = u.id`
const countQuery = `SELECT count(l.tm_user) FROM log as l`
+func getLogV40(inf *api.APIInfo, days int) ([]tc.Log, uint64, error) {
+ var count = uint64(0)
+ var whereCount string
+
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "username": {Column: "u.username", Checker: nil},
+ }
+ where, _, pagination, queryValues, errs :=
+ dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params,
queryParamsToQueryCols)
+
+ if len(errs) > 0 {
+ return nil, 0, util.JoinErrs(errs)
+ }
+
+ timeInterval := fmt.Sprintf("l.last_updated > now() - INTERVAL '%v'
DAY", days)
+ if where != "" {
+ whereCount = ", tm_user as u\n" + where + " AND l.tm_user =
u.id"
+ where = where + " AND " + timeInterval
+ } else {
+ whereCount = where
+ where = "\nWHERE " + timeInterval
+ }
+ queryCount := countQuery + whereCount
+ rowCount, err := inf.Tx.NamedQuery(queryCount, queryValues)
+ if err != nil {
+ return nil, count, errors.New("querying log count for a given
user: " + err.Error())
Review comment:
Fixed
##########
File path: traffic_ops/traffic_ops_golang/logs/log.go
##########
@@ -135,11 +163,64 @@ FROM "log" as l JOIN tm_user as u ON l.tm_user = u.id`
const countQuery = `SELECT count(l.tm_user) FROM log as l`
+func getLogV40(inf *api.APIInfo, days int) ([]tc.Log, uint64, error) {
+ var count = uint64(0)
+ var whereCount string
+
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "username": {Column: "u.username", Checker: nil},
+ }
+ where, _, pagination, queryValues, errs :=
+ dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params,
queryParamsToQueryCols)
+
+ if len(errs) > 0 {
+ return nil, 0, util.JoinErrs(errs)
+ }
+
+ timeInterval := fmt.Sprintf("l.last_updated > now() - INTERVAL '%v'
DAY", days)
+ if where != "" {
+ whereCount = ", tm_user as u\n" + where + " AND l.tm_user =
u.id"
+ where = where + " AND " + timeInterval
+ } else {
+ whereCount = where
+ where = "\nWHERE " + timeInterval
+ }
+ queryCount := countQuery + whereCount
+ rowCount, err := inf.Tx.NamedQuery(queryCount, queryValues)
+ if err != nil {
+ return nil, count, errors.New("querying log count for a given
user: " + err.Error())
+ }
+ defer rowCount.Close()
+ for rowCount.Next() {
+ if err = rowCount.Scan(&count); err != nil {
+ return nil, count, errors.New("scanning logs: " +
err.Error())
Review comment:
Fixed.
##########
File path: traffic_ops/traffic_ops_golang/logs/log.go
##########
@@ -135,11 +163,64 @@ FROM "log" as l JOIN tm_user as u ON l.tm_user = u.id`
const countQuery = `SELECT count(l.tm_user) FROM log as l`
+func getLogV40(inf *api.APIInfo, days int) ([]tc.Log, uint64, error) {
+ var count = uint64(0)
+ var whereCount string
+
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "username": {Column: "u.username", Checker: nil},
+ }
+ where, _, pagination, queryValues, errs :=
+ dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params,
queryParamsToQueryCols)
+
+ if len(errs) > 0 {
+ return nil, 0, util.JoinErrs(errs)
+ }
+
+ timeInterval := fmt.Sprintf("l.last_updated > now() - INTERVAL '%v'
DAY", days)
+ if where != "" {
+ whereCount = ", tm_user as u\n" + where + " AND l.tm_user =
u.id"
+ where = where + " AND " + timeInterval
+ } else {
+ whereCount = where
+ where = "\nWHERE " + timeInterval
+ }
+ queryCount := countQuery + whereCount
+ rowCount, err := inf.Tx.NamedQuery(queryCount, queryValues)
+ if err != nil {
+ return nil, count, errors.New("querying log count for a given
user: " + err.Error())
+ }
+ defer rowCount.Close()
+ for rowCount.Next() {
+ if err = rowCount.Scan(&count); err != nil {
+ return nil, count, errors.New("scanning logs: " +
err.Error())
+ }
+ }
+
+ query := selectFromQuery + where + "\n ORDER BY last_updated DESC" +
pagination
+ rows, err := inf.Tx.NamedQuery(query, queryValues)
+ if err != nil {
+ return nil, count, errors.New("querying logs: " + err.Error())
Review comment:
Fixed.
##########
File path: traffic_ops/traffic_ops_golang/logs/log.go
##########
@@ -135,11 +163,64 @@ FROM "log" as l JOIN tm_user as u ON l.tm_user = u.id`
const countQuery = `SELECT count(l.tm_user) FROM log as l`
+func getLogV40(inf *api.APIInfo, days int) ([]tc.Log, uint64, error) {
+ var count = uint64(0)
+ var whereCount string
+
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "username": {Column: "u.username", Checker: nil},
+ }
+ where, _, pagination, queryValues, errs :=
+ dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params,
queryParamsToQueryCols)
+
+ if len(errs) > 0 {
+ return nil, 0, util.JoinErrs(errs)
+ }
+
+ timeInterval := fmt.Sprintf("l.last_updated > now() - INTERVAL '%v'
DAY", days)
+ if where != "" {
+ whereCount = ", tm_user as u\n" + where + " AND l.tm_user =
u.id"
+ where = where + " AND " + timeInterval
+ } else {
+ whereCount = where
+ where = "\nWHERE " + timeInterval
+ }
+ queryCount := countQuery + whereCount
+ rowCount, err := inf.Tx.NamedQuery(queryCount, queryValues)
+ if err != nil {
+ return nil, count, errors.New("querying log count for a given
user: " + err.Error())
+ }
+ defer rowCount.Close()
+ for rowCount.Next() {
+ if err = rowCount.Scan(&count); err != nil {
+ return nil, count, errors.New("scanning logs: " +
err.Error())
+ }
+ }
+
+ query := selectFromQuery + where + "\n ORDER BY last_updated DESC" +
pagination
+ rows, err := inf.Tx.NamedQuery(query, queryValues)
+ if err != nil {
+ return nil, count, errors.New("querying logs: " + err.Error())
+ }
+ defer rows.Close()
+ ls := []tc.Log{}
+ for rows.Next() {
+ l := tc.Log{}
+ if err = rows.Scan(&l.ID, &l.Level, &l.Message, &l.User,
&l.TicketNum, &l.LastUpdated); err != nil {
+ return nil, count, errors.New("scanning logs: " +
err.Error())
Review comment:
Fixed.
##########
File path: traffic_ops/traffic_ops_golang/logs/log.go
##########
@@ -79,6 +78,35 @@ func Get(w http.ResponseWriter, r *http.Request) {
}
}
+// Get is the handler for GET requests to /logs V4.0.
+func Getv40(w http.ResponseWriter, r *http.Request) {
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, []string{"days",
"limit"})
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+ days := DefaultLogDays
+ if pDays, ok := inf.IntParams["days"]; ok {
+ days = pDays
+ }
+
+ a := tc.Alerts{}
+ setLastSeenCookie(w)
+ logs, count, err := getLogV40(inf, days)
+
+ if err != nil {
+ a.AddNewAlert(tc.ErrorLevel, err.Error())
+ api.WriteAlerts(w, r, http.StatusInternalServerError, a)
Review comment:
Fixed.
##########
File path: traffic_ops/traffic_ops_golang/logs/log.go
##########
@@ -79,6 +78,35 @@ func Get(w http.ResponseWriter, r *http.Request) {
}
}
+// Get is the handler for GET requests to /logs V4.0.
+func Getv40(w http.ResponseWriter, r *http.Request) {
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, []string{"days",
"limit"})
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+ days := DefaultLogDays
+ if pDays, ok := inf.IntParams["days"]; ok {
+ days = pDays
+ }
+
+ a := tc.Alerts{}
+ setLastSeenCookie(w)
+ logs, count, err := getLogV40(inf, days)
+
+ if err != nil {
+ a.AddNewAlert(tc.ErrorLevel, err.Error())
+ api.WriteAlerts(w, r, http.StatusInternalServerError, a)
+ return
+ }
+ if a.HasAlerts() {
Review comment:
Fixed.
##########
File path: traffic_ops/traffic_ops_golang/logs/log.go
##########
@@ -135,11 +163,64 @@ FROM "log" as l JOIN tm_user as u ON l.tm_user = u.id`
const countQuery = `SELECT count(l.tm_user) FROM log as l`
+func getLogV40(inf *api.APIInfo, days int) ([]tc.Log, uint64, error) {
+ var count = uint64(0)
+ var whereCount string
+
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "username": {Column: "u.username", Checker: nil},
+ }
+ where, _, pagination, queryValues, errs :=
+ dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params,
queryParamsToQueryCols)
+
+ if len(errs) > 0 {
+ return nil, 0, util.JoinErrs(errs)
+ }
+
+ timeInterval := fmt.Sprintf("l.last_updated > now() - INTERVAL '%v'
DAY", days)
Review comment:
updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]