This is an automated email from the ASF dual-hosted git repository.
zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 65f9941d17 V5 logs should return rfc3339 time format (#7690)
65f9941d17 is described below
commit 65f9941d179164418756c7679f01dca8c405e6e5
Author: Srijeet Chatterjee <[email protected]>
AuthorDate: Fri Aug 4 12:28:39 2023 -0600
V5 logs should return rfc3339 time format (#7690)
* V5 logs should return rfc3339 time format
* add changelog
* Add docs
---
CHANGELOG.md | 1 +
docs/source/api/v5/logs.rst | 6 ++--
lib/go-tc/log.go | 46 ++++++++++++++++++++++++++++++
traffic_ops/testing/api/v5/logs_test.go | 2 +-
traffic_ops/traffic_ops_golang/logs/log.go | 18 ++++++++++--
traffic_ops/v5-client/log.go | 4 +--
6 files changed, 69 insertions(+), 8 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b1e727cb1..de4076e249 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -73,6 +73,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
### Fixed
- [#4393](https://github.com/apache/trafficcontrol/issues/4393) *Traffic Ops*
Fixed the error code and alert structure when TO is queried for a delivery
service with no ssl keys.
+- [#7690](https://github.com/apache/trafficcontrol/pull/7690) *Traffic Ops*
Fixes Logs V5 apis to respond with RFC3339 tiestamps.
- [#7631] (https://github.com/apache/trafficcontrol/pull/7631) *Traffic Ops*
Fixes Phys_Location V5 apis to respond with RFC3339 date/time Format
- [#7623] (https://github.com/apache/trafficcontrol/pull/7623) *Traffic Ops*
Removed TryIfModifiedSinceQuery from servicecategories.go and reused from ims.go
- [#7608](https://github.com/apache/trafficcontrol/pull/7608) *Traffic
Monitor* Use stats_over_http(plugin.system_stats.timestamp_ms) timestamp field
to calculate bandwidth for TM's caches.
diff --git a/docs/source/api/v5/logs.rst b/docs/source/api/v5/logs.rst
index 84f7afe912..1748047d51 100644
--- a/docs/source/api/v5/logs.rst
+++ b/docs/source/api/v5/logs.rst
@@ -63,7 +63,7 @@ Request Structure
Response Structure
------------------
:id: Integral, unique identifier for the Log entry
-:lastUpdated: Date and time at which the change was made, in
:ref:`non-rfc-datetime`
+:lastUpdated: Date and time at which the change was made, in :rfc:`3339` format
:level: Log categories for each entry, e.g. 'UICHANGE', 'OPER',
'APICHANGE'
:message: Log detail about what occurred
:ticketNum: Optional field to cross reference with any bug tracking systems
@@ -91,7 +91,7 @@ Response Structure
{
"ticketNum": null,
"level": "APICHANGE",
- "lastUpdated": "2018-11-14 21:40:06.493975+00",
+ "lastUpdated": "2018-11-14T21:40:06-06:00",
"user": "admin",
"id": 444,
"message": "User [ test ] unlinked from deliveryservice
[ 1 | demo1 ]."
@@ -99,7 +99,7 @@ Response Structure
{
"ticketNum": null,
"level": "APICHANGE",
- "lastUpdated": "2018-11-14 21:37:30.707571+00",
+ "lastUpdated": "2018-11-14T21:37:30-06:00",
"user": "admin",
"id": 443,
"message": "1 delivery services were assigned to test"
diff --git a/lib/go-tc/log.go b/lib/go-tc/log.go
index 27879f9c4f..e11dec1677 100644
--- a/lib/go-tc/log.go
+++ b/lib/go-tc/log.go
@@ -1,5 +1,10 @@
package tc
+import (
+ "github.com/apache/trafficcontrol/lib/go-util"
+ "time"
+)
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -25,6 +30,15 @@ type LogsResponse struct {
Alerts
}
+// LogsResponseV5 is a list of Logs as a response, for the latest minor
version of api 5.x.
+type LogsResponseV5 = LogsResponseV50
+
+// LogsResponseV50 is a list of Logs as a response, for api version 5.0.
+type LogsResponseV50 struct {
+ Response []LogV50 `json:"response"`
+ Alerts
+}
+
// Log contains a change that has been made to the Traffic Control system.
type Log struct {
ID *int `json:"id"`
@@ -35,6 +49,38 @@ type Log struct {
User *string `json:"user"`
}
+// Upgrade changes a Log structure into a LogV5 structure
+func (l Log) Upgrade() LogV5 {
+ logV5 := LogV5{
+ ID: l.ID,
+ Level: l.Level,
+ Message: l.Message,
+ TicketNum: l.TicketNum,
+ User: l.User,
+ }
+ if l.LastUpdated != nil {
+ t := &l.LastUpdated.Time
+ if t != nil {
+ t, _ := util.ConvertTimeFormat(*t, time.RFC3339)
+ logV5.LastUpdated = t
+ }
+ }
+ return logV5
+}
+
+// LogV50 contains a change that has been made to the Traffic Control system,
for api version 5.0.
+type LogV50 struct {
+ ID *int `json:"id"`
+ LastUpdated *time.Time `json:"lastUpdated"`
+ Level *string `json:"level"`
+ Message *string `json:"message"`
+ TicketNum *int `json:"ticketNum"`
+ User *string `json:"user"`
+}
+
+// LogV5 is the Log structure used by the latest 5.x API version
+type LogV5 = LogV50
+
// NewLogCountResp is the response returned when the total number of new
changes
// made to the Traffic Control system is requested. "New" means since the last
// time this information was requested.
diff --git a/traffic_ops/testing/api/v5/logs_test.go
b/traffic_ops/testing/api/v5/logs_test.go
index f974b69832..1c7360c0d1 100644
--- a/traffic_ops/testing/api/v5/logs_test.go
+++ b/traffic_ops/testing/api/v5/logs_test.go
@@ -70,7 +70,7 @@ func TestLogs(t *testing.T) {
func validateLogsFields(expectedResp map[string]interface{}) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _
tc.Alerts, _ error) {
- logs := resp.([]tc.Log)
+ logs := resp.([]tc.LogV5)
for field, expected := range expectedResp {
for _, log := range logs {
switch field {
diff --git a/traffic_ops/traffic_ops_golang/logs/log.go
b/traffic_ops/traffic_ops_golang/logs/log.go
index 25cbb9a25a..2128b2a507 100644
--- a/traffic_ops/traffic_ops_golang/logs/log.go
+++ b/traffic_ops/traffic_ops_golang/logs/log.go
@@ -94,10 +94,24 @@ func Getv40(w http.ResponseWriter, r *http.Request) {
api.WriteAlerts(w, r, http.StatusInternalServerError, a)
return
}
+ var result interface{}
+ var logsV5 []tc.LogV5
+ if inf.Version.GreaterThanOrEqualTo(&api.Version{
+ Major: 5,
+ Minor: 0,
+ }) {
+ for _, l := range logs {
+ logV5 := l.Upgrade()
+ logsV5 = append(logsV5, logV5)
+ }
+ result = logsV5
+ } else {
+ result = logs
+ }
if a.HasAlerts() {
- api.WriteAlertsObj(w, r, 200, a, logs)
+ api.WriteAlertsObj(w, r, 200, a, result)
} else {
- api.WriteRespWithSummary(w, r, logs, count)
+ api.WriteRespWithSummary(w, r, result, count)
}
}
diff --git a/traffic_ops/v5-client/log.go b/traffic_ops/v5-client/log.go
index f828f4e3a5..65ddacef9c 100644
--- a/traffic_ops/v5-client/log.go
+++ b/traffic_ops/v5-client/log.go
@@ -24,8 +24,8 @@ import (
const apiLogs = "/logs"
// GetLogs gets a list of logs.
-func (to *Session) GetLogs(opts RequestOptions) (tc.LogsResponse,
toclientlib.ReqInf, error) {
- var data tc.LogsResponse
+func (to *Session) GetLogs(opts RequestOptions) (tc.LogsResponseV5,
toclientlib.ReqInf, error) {
+ var data tc.LogsResponseV5
reqInf, err := to.get(apiLogs, opts, &data)
return data, reqInf, err
}