Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
58013db
Fixes https://github.com/apache/trafficcontrol/issues/7544 Updated V5…
jagan-parthiban May 26, 2023
cf68b85
Fixes https://github.com/apache/trafficcontrol/issues/7544 Updated In…
jagan-parthiban May 26, 2023
002d80f
Fixes https://github.com/apache/trafficcontrol/issues/7544 Added Unit…
jagan-parthiban May 28, 2023
db8a54b
CHANGELOG.md Update
jagan-parthiban May 28, 2023
f1c71ea
Documentation Update
jagan-parthiban May 30, 2023
09f8924
Fixed PR review comments
jagan-parthiban Jun 2, 2023
4869b8e
Use SOH timestamp to calculate bandwidth in TM (#7539)
rimashah25 May 31, 2023
e79e87a
Fixed PR review comments for https://github.com/apache/trafficcontrol…
jagan-parthiban Jun 8, 2023
7a008a9
Fixed CHANGELOG.md for https://github.com/apache/trafficcontrol/issue…
jagan-parthiban Jun 8, 2023
04f6f74
Fixed CHANGELOG.md for https://github.com/apache/trafficcontrol/issue…
jagan-parthiban Jun 8, 2023
f87d693
Fixed CHANGELOG.md for https://github.com/apache/trafficcontrol/issue…
jagan-parthiban Jun 8, 2023
bb287cc
Fixed PR review comments for https://github.com/apache/trafficcontrol…
jagan-parthiban Jun 8, 2023
9f8fe05
Fixed PR Review comments
jagan-parthiban Jun 14, 2023
6974d89
Fixed CHANGELOG.md
jagan-parthiban Jun 14, 2023
02c4a53
Update stats_summary lib
jagan-parthiban Jun 21, 2023
a7e490a
Updated statessummary file
jagan-parthiban Jun 23, 2023
1676dc6
Updated unit test cases
jagan-parthiban Jun 23, 2023
33088b7
Temp changes to check GHA
jagan-parthiban Jun 23, 2023
789d98b
Temp changes to check GHA
jagan-parthiban Jun 23, 2023
200b082
revert Temp changes to check GHA
jagan-parthiban Jun 23, 2023
d057485
Updated CHANGELOG.md
jagan-parthiban Jul 3, 2023
9f3a6dd
Updated GHA failing test case for testing.
jagan-parthiban Jul 3, 2023
2c7b7d4
Updated GHA failing test case.
jagan-parthiban Jul 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7570](https://github.com/apache/trafficcontrol/pull/7570) *Traffic Ops* Fixes `deliveryservice_request_comments` v5 apis to respond with `RFC3339` date/time Format.
- [#7312](https://github.com/apache/trafficcontrol/issues/7312) *Docs* Changing docs for CDN locks for DELETE response structure v4 and v5.
- [#7572](https://github.com/apache/trafficcontrol/pull/7572) *Traffic Ops* Fixes Delivery Service Requests V5 apis docs with RFC3339 date/time Format
- [#7544](https://github.com/apache/trafficcontrol/issues/7544) *Traffic Ops* Fixes stats_summary v5 apis to respond with RFC3339 date/time Format.
- [#7542](https://github.com/apache/trafficcontrol/pull/7542) *Traffic Ops* Fixed `CDN Locks` documentation to reflect the correct RFC3339 timestamps.
Comment thread
jagan-parthiban marked this conversation as resolved.
- [#6340](https://github.com/apache/trafficcontrol/issues/6340) *Traffic Ops* Fixed alert messages for POST and PUT invalidation job APIs.
- [#7519] (https://github.com/apache/trafficcontrol/issues/7519) *Traffic Ops* Fixed TO API /servers/{id}/deliveryservices endpoint to responding with all DS's on cache that are directly assigned and inherited through topology.
Expand Down
16 changes: 8 additions & 8 deletions docs/source/api/v5/stats_summary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Summary Stats

:statName: Stat name summary stat represents
:statValue: Summary stat value
:summaryTime: Timestamp of summary, in :ref:`non-rfc-datetime`
:summaryTime: Timestamp of summary, in :rfc:`3339` format
:statDate: Date stat was taken, in ``YYYY-MM-DD`` format

.. code-block:: http
Expand All @@ -134,31 +134,31 @@ Summary Stats
"deliveryServiceName": "all",
"statName": "daily_maxgbps",
"statValue": 5,
"summaryTime": "2019-11-19 00:04:06+00",
"summaryTime": "2019-11-19T03:37:33+05:30",
"statDate": "2019-11-19"
},
{
"cdnName": "CDN-in-a-Box",
"deliveryServiceName": "all",
"statName": "daily_maxgbps",
"statValue": 3,
"summaryTime": "2019-11-18 00:04:06+00",
"summaryTime": "2019-11-18T07:59:54+05:30",
"statDate": "2019-11-18"
},
{
"cdnName": "CDN-in-a-Box",
"deliveryServiceName": "all",
"statName": "daily_bytesserved",
"statValue": 1000,
"summaryTime": "2019-11-19 00:04:06+00",
"summaryTime": "2019-11-19T00:42:12+05:30",
"statDate": "2019-11-19"
}
]}

Last Updated Summary Stat
"""""""""""""""""""""""""

:summaryTime: Timestamp of the last updated summary, in :ref:`non-rfc-datetime`
:summaryTime: Timestamp of the last updated summary, in :rfc:`3339` format

.. code-block:: http
:caption: Response Example
Expand All @@ -176,7 +176,7 @@ Last Updated Summary Stat
Content-Length: 150

{ "response": {
"summaryTime": "2019-11-19 00:04:06+00"
"summaryTime": "2019-11-19T06:12:34+05:30"
}}

``POST``
Expand All @@ -201,7 +201,7 @@ Request Structure

:statName: Stat name summary stat represents
:statValue: Summary stat value
:summaryTime: Timestamp of summary, in :ref:`non-rfc-datetime`
:summaryTime: Timestamp of summary, in :rfc:`3339` format
:statDate: Date stat was taken, in ``YYYY-MM-DD`` format

.. note:: ``statName``, ``statValue`` and ``summaryTime`` are required. If ``cdnName`` and ``deliveryServiceName`` are not given they will default to ``all``.
Expand All @@ -222,7 +222,7 @@ Request Structure
"deliveryServiceName": "all",
"statName": "daily_maxgbps",
"statValue": 10,
"summaryTime": "2019-12-05 00:03:57+00",
"summaryTime": "2019-12-05T09:55:07+05:30",
"statDate": "2019-12-05"
}

Expand Down
147 changes: 147 additions & 0 deletions lib/go-tc/stats_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"time"

"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
Expand Down Expand Up @@ -187,3 +188,149 @@ type StatsSummaryLastUpdatedAPIResponse struct {
Response StatsSummaryLastUpdated `json:"response"`
Alerts
}

// StatsSummaryV5 is an alias for the latest minor version for the major version 5.
type StatsSummaryV5 StatsSummaryV50

// StatsSummaryV50 is a summary of some kind of statistic for a CDN and/or
// Delivery Service.
type StatsSummaryV50 struct {
CDNName *string `json:"cdnName" db:"cdn_name"`
DeliveryService *string `json:"deliveryServiceName" db:"deliveryservice_name"`
StatName *string `json:"statName" db:"stat_name"`
StatValue *float64 `json:"statValue" db:"stat_value"`
SummaryTime time.Time `json:"summaryTime" db:"summary_time"`
StatDate *time.Time `json:"statDate" db:"stat_date"`
Comment thread
jagan-parthiban marked this conversation as resolved.
}

// Validate implements the
// github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api.ParseValidator
// interface.
func (ss StatsSummaryV5) Validate(tx *sql.Tx) error {
errs := tovalidate.ToErrors(validation.Errors{
"statName": validation.Validate(ss.StatName, validation.Required),
"statValue": validation.Validate(ss.StatValue, validation.Required),
})
return util.JoinErrs(errs)
}

// UnmarshalJSON implements the encoding/json.Unmarshaler interface with a
// customized decoding to force the date format on StatDate.
func (ss *StatsSummaryV5) UnmarshalJSON(data []byte) error {
type Alias StatsSummaryV5
resp := struct {
SummaryTime string `json:"summaryTime"`
StatDate *string `json:"statDate"`
*Alias
}{
Alias: (*Alias)(ss),
}
err := json.Unmarshal(data, &resp)
if err != nil {
return err
}
if resp.StatDate != nil {
statDate, err := parseTimeV5(*resp.StatDate)
if err != nil {
return fmt.Errorf("invalid timestamp given for statDate: %v", err)
}
ss.StatDate = &statDate
}

ss.SummaryTime, err = parseTimeV5(resp.SummaryTime)
if err != nil {
return fmt.Errorf("invalid timestamp given for summaryTime: %v", err)
}
return nil
}

func parseTimeV5(ts string) (time.Time, error) {
rt, err := time.Parse(time.RFC3339, ts)
if err == nil {
return rt, err
}
return time.Parse(dateFormat, ts)
}

// MarshalJSON implements the encoding/json.Marshaler interface with a
// customized encoding to force the date format on StatDate.
func (ss StatsSummaryV5) MarshalJSON() ([]byte, error) {
type Alias StatsSummaryV5
resp := struct {
StatDate *string `json:"statDate"`
SummaryTime string `json:"summaryTime"`
Alias
}{
SummaryTime: ss.SummaryTime.Format(time.RFC3339),
Alias: (Alias)(ss),
}
if ss.StatDate != nil {
resp.StatDate = util.Ptr(ss.StatDate.Format(dateFormat))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this also be RFC3339?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC3339 will return date and time. but the expectation is only the date. So as used in the v4 function, in v5 aswell we are using dateFormat

const dateFormat = "2006-01-02"

}
return json.Marshal(&resp)
}

// StatsSummaryResponseV5 is an alias for the latest minor version for the major version 5.
type StatsSummaryResponseV5 StatsSummaryResponseV50

// StatsSummaryResponseV50 is the structure of a response from Traffic Ops to
// GET requests made to its /stats_summary V5 API endpoint.
type StatsSummaryResponseV50 struct {
Response []StatsSummaryV5 `json:"response"`
Alerts
}

// StatsSummaryLastUpdatedV5 is an alias for the latest minor version for the major version 5.
type StatsSummaryLastUpdatedV5 StatsSummaryLastUpdatedV50

// StatsSummaryLastUpdatedV50 is the type of the `response` property of a response
// from Traffic Ops to a GET request made to its /stats_summary endpoint when
// the 'lastSummaryDate' query string parameter is passed as 'true'.
type StatsSummaryLastUpdatedV50 struct {
SummaryTime *time.Time `json:"summaryTime" db:"summary_time"`
}

// MarshalJSON implements the encoding/json.Marshaler interface with a
// customized encoding to force the date format on SummaryTime.
func (ss StatsSummaryLastUpdatedV5) MarshalJSON() ([]byte, error) {
resp := struct {
SummaryTime *string `json:"summaryTime"`
}{}
if ss.SummaryTime != nil {
resp.SummaryTime = util.Ptr(ss.SummaryTime.Format(time.RFC3339))
}
return json.Marshal(&resp)
}

// UnmarshalJSON implements the encoding/json.Unmarshaler interface with a
// customized decoding to force the SummaryTime format.
func (ss *StatsSummaryLastUpdatedV5) UnmarshalJSON(data []byte) error {
resp := struct {
SummaryTime *string `json:"summaryTime"`
}{}
err := json.Unmarshal(data, &resp)
if err != nil {
return err
}
if resp.SummaryTime != nil {
var summaryTime time.Time
summaryTime, err = time.Parse(time.RFC3339, *resp.SummaryTime)
if err == nil {
ss.SummaryTime = &summaryTime
return nil
}
return err
}
return nil
}

// StatsSummaryLastUpdatedAPIResponseV5 is an alias for the latest minor version for the major version 5.
type StatsSummaryLastUpdatedAPIResponseV5 StatsSummaryLastUpdatedAPIResponseV50

// StatsSummaryLastUpdatedAPIResponseV50 is the type of a response from Traffic
// Ops to a request to its /stats_summary endpoint with the 'lastSummaryDate'
// query string parameter set to 'true'.
type StatsSummaryLastUpdatedAPIResponseV50 struct {
Response StatsSummaryLastUpdatedV5 `json:"response"`
Alerts
}
9 changes: 5 additions & 4 deletions traffic_ops/testing/api/v5/stats_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestStatsSummary(t *testing.T) {

CreateTestStatsSummaries(t)

methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.StatsSummary]{
methodTests := utils.TestCase[client.Session, client.RequestOptions, tc.StatsSummaryV5]{
"GET": {
"OK when VALID request": {
ClientSession: TOSession,
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestStatsSummary(t *testing.T) {
func validateStatsSummaryFields(expectedResp map[string]interface{}) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected Stats Summary response to not be nil.")
statsSummaryResp := resp.([]tc.StatsSummary)
statsSummaryResp := resp.([]tc.StatsSummaryV5)
for field, expected := range expectedResp {
for _, statsSummary := range statsSummaryResp {
switch field {
Expand All @@ -141,9 +141,10 @@ func validateStatsSummaryFields(expectedResp map[string]interface{}) utils.CkReq
func validateStatsSummaryLastUpdatedField(expectedTime time.Time) utils.CkReqFunc {
return func(t *testing.T, _ toclientlib.ReqInf, resp interface{}, _ tc.Alerts, _ error) {
assert.RequireNotNil(t, resp, "Expected StatsSummaryLastUpdated response to not be nil.")
statsSummaryLastUpdated := resp.(tc.StatsSummaryLastUpdated)
statsSummaryLastUpdated := resp.(tc.StatsSummaryLastUpdatedV5)
assert.RequireNotNil(t, statsSummaryLastUpdated.SummaryTime, "Expected SummaryTime to not be nil.")
assert.Equal(t, expectedTime, *statsSummaryLastUpdated.SummaryTime, "Expected SummaryTime to be %v, but got %v", expectedTime, *statsSummaryLastUpdated.SummaryTime)
assert.Equal(t, true, expectedTime.Equal(*statsSummaryLastUpdated.SummaryTime), "Expected SummaryTime to be %v, but got %v", expectedTime, *statsSummaryLastUpdated.SummaryTime)

}
}

Expand Down
2 changes: 1 addition & 1 deletion traffic_ops/testing/api/v5/traffic_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type TrafficControl struct {
ServiceCategories []tc.ServiceCategoryV5 `json:"serviceCategories"`
Statuses []tc.StatusNullable `json:"statuses"`
StaticDNSEntries []tc.StaticDNSEntry `json:"staticdnsentries"`
StatsSummaries []tc.StatsSummary `json:"statsSummaries"`
StatsSummaries []tc.StatsSummaryV5 `json:"statsSummaries"`
Tenants []tc.Tenant `json:"tenants"`
ServerCheckExtensions []tc.ServerCheckExtensionNullable `json:"servercheck_extensions"`
Topologies []tc.Topology `json:"topologies"`
Expand Down
Loading