From 5d18d6796a5a339e799ebfead3ffe5dc43731ea8 Mon Sep 17 00:00:00 2001 From: Srijeet Chatterjee Date: Thu, 3 Mar 2022 12:27:23 -0700 Subject: [PATCH 1/4] Adding status and lastHmPoll fields to CrStates --- CHANGELOG.md | 3 ++- lib/go-tc/crstates.go | 11 +++++++---- traffic_monitor/health/cache.go | 2 ++ traffic_monitor/manager/statecombiner.go | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c2c2afd0c..da4f16f037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [unreleased] ### Added +- [#6448](https://github.com/apache/trafficcontrol/issues/6448) Added `status` and `lastHmPoll` fields to the `publish/CrStates` endpoint of Traffic Monitor (TM). - Added a new Traffic Ops endpoint to `GET` capacity and telemetry data for CDNi integration. - Added a Traffic Ops endpoints to `PUT` a requested configuration change for a full configuration or per host and an endpoint to approve or deny the request. - Traffic Monitor config option `distributed_polling` which enables the ability for Traffic Monitor to poll a subset of the CDN and divide into "local peer groups" and "distributed peer groups". Traffic Monitors in the same group are local peers, while Traffic Monitors in other groups are distibuted peers. Each TM group polls the same set of cachegroups and gets availability data for the other cachegroups from other TM groups. This allows each TM to be responsible for polling a subset of the CDN while still having a full view of CDN availability. In order to use this, `stat_polling` must be disabled. @@ -16,7 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed a cdn-in-a-box build issue when using `RHEL_VERSION=7` - [#6580](https://github.com/apache/trafficcontrol/issues/6580) Fixed cache config generation remap.config targets for MID-type servers in a Topology with other caches as parents and HTTPS origins. - Traffic Router: fixed a null pointer exception that caused snapshots to be rejected if a topology cachegroup did not have any online/reported/admin_down caches -- [#6549](https://github.com/apache/trafficcontrol/issues/6549) Fixed internal server error while deleting a delivery service created from a DSR (Traafic Ops). +- [#6549](https://github.com/apache/trafficcontrol/issues/6549) Fixed internal server error while deleting a delivery service created from a DSR (Traffic Ops). - [#6538](https://github.com/apache/trafficcontrol/pull/6538) Fixed the incorrect use of secure.port on TrafficRouter and corrected to the httpsPort value from the TR server configuration. - [#6562](https://github.com/apache/trafficcontrol/pull/6562) Fixed incorrect template in Ansible dataset loader role when fallbackToClosest is defined. - [#6590](https://github.com/apache/trafficcontrol/pull/6590) Python client: Corrected parameter name in decorator for get_parameters_by_profile_id diff --git a/lib/go-tc/crstates.go b/lib/go-tc/crstates.go index eb8fe445a2..0c7900623c 100644 --- a/lib/go-tc/crstates.go +++ b/lib/go-tc/crstates.go @@ -21,6 +21,7 @@ package tc import ( "encoding/json" + "time" ) // CRStates includes availability data for caches and delivery services, as gathered and aggregated by this Traffic Monitor. It is designed to be served at an API endpoint primarily for Traffic Routers (Content Router) to consume. @@ -37,10 +38,12 @@ type CRStatesDeliveryService struct { // IsAvailable contains whether the given cache or delivery service is available. It is designed for JSON serialization, namely in the Traffic Monitor 1.0 API. type IsAvailable struct { - IsAvailable bool `json:"isAvailable"` - Ipv4Available bool `json:"ipv4Available"` - Ipv6Available bool `json:"ipv6Available"` - DirectlyPolled bool `json:"-"` + IsAvailable bool `json:"isAvailable"` + Ipv4Available bool `json:"ipv4Available"` + Ipv6Available bool `json:"ipv6Available"` + DirectlyPolled bool `json:"-"` + Status string `json:"status"` + LastHmPoll time.Time `json:"lastHmPoll"` } // NewCRStates creates a new CR states object, initializing pointer members. diff --git a/traffic_monitor/health/cache.go b/traffic_monitor/health/cache.go index 1cf6bcb58b..c4f7426938 100644 --- a/traffic_monitor/health/cache.go +++ b/traffic_monitor/health/cache.go @@ -361,6 +361,8 @@ func CalcAvailability( Ipv4Available: availStatus.Available.IPv4, Ipv6Available: availStatus.Available.IPv6, DirectlyPolled: true, // we know this cache was directly polled because otherwise we wouldn't have a cache.Result for it + Status: availStatus.Why, + LastHmPoll: result.Time, }) if available, ok := localStates.GetCache(tc.CacheName(result.ID)); !ok || available.IsAvailable != lastStatus.ProcessedAvailable { diff --git a/traffic_monitor/manager/statecombiner.go b/traffic_monitor/manager/statecombiner.go index 871163ad89..116f8a3c7a 100644 --- a/traffic_monitor/manager/statecombiner.go +++ b/traffic_monitor/manager/statecombiner.go @@ -133,7 +133,7 @@ func combineCacheState( IPv6Available: ipv6Available}) } - combinedStates.AddCache(cacheName, tc.IsAvailable{IsAvailable: available, Ipv4Available: ipv4Available, Ipv6Available: ipv6Available, DirectlyPolled: localCacheState.DirectlyPolled}) + combinedStates.AddCache(cacheName, tc.IsAvailable{IsAvailable: available, Ipv4Available: ipv4Available, Ipv6Available: ipv6Available, DirectlyPolled: localCacheState.DirectlyPolled, Status: localCacheState.Status, LastHmPoll: localCacheState.LastHmPoll}) } func combineDSState( From 22ca634dc42c26389de8a57c06d41a5256a32c08 Mon Sep 17 00:00:00 2001 From: Srijeet Chatterjee Date: Thu, 3 Mar 2022 14:24:53 -0700 Subject: [PATCH 2/4] adding documentation for publish/CrStates --- .../traffic_monitor/traffic_monitor_api.rst | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/docs/source/development/traffic_monitor/traffic_monitor_api.rst b/docs/source/development/traffic_monitor/traffic_monitor_api.rst index f406b2a890..dbe98c31c4 100644 --- a/docs/source/development/traffic_monitor/traffic_monitor_api.rst +++ b/docs/source/development/traffic_monitor/traffic_monitor_api.rst @@ -343,22 +343,60 @@ TODO ``/publish/CrStates`` ===================== -The current state of this CDN per the ref:`health-proto`. +The current state of this CDN per the :ref:`health-proto`. ``GET`` ------- -:Response Type: ? +:Response Type: Object + +.. code-block:: http + :caption: Example Request + + GET /publish/CrStates HTTP/1.1 + Accept: */* + Content-Type: application/json Response Structure """""""""""""""""" +:caches: An object with keys that are the names of monitored :term:`cache servers` + :server name: The name of the server being monitored -TODO + :isAvailable: Whether or not this cache is available for monitoring + :ipv4Available: Whether or not an IPV4 interface on this cache is available for monitoring + :ipv6Available: Whether or not an IPV6 interface on this cache is available for monitoring + :status: The status of this server, along with any additional reason for it to be marked as such + :lastHmPoll: The last time the health data for this server was polled by a traffic monitor +:deliveryServices: An object with keys as the names of monitored :term:`Delivery Services` + :delivery service name: The name of the delivery service being monitored + :disabledLocations: A list of disabled locations for this delivery service + :isAvailable: Whether or not this delivery service is available for monitoring -..???? -**raw** +.. code-block:: http + :caption: Example Response + + HTTP/1.1 200 OK + Content-Type: application/json + Date: Thu, 14 May 2020 15:54:35 GMT + Transfer-Encoding: chunked -The current state of this CDN per this Traffic Monitor only. + { + "caches": { + "cdn-ec-atl-03": { + "isAvailable": true, + "ipv4Available": true, + "ipv6Available": true, + "status": "REPORTED - id cdn-ec-atl-03 url http://[2001:558:fe13:b1::2]:80/_astats?application=system&inf.name=bond0 fetch error: bad HTTP status: 403; bond0: not found in polled data", + "lastHmPoll": "2022-03-03T12:26:02.78556-07:00" + },... + }, + "deliveryServices": { + "ds-1": { + "disabledLocations": [], + "isAvailable": true + },... + } + } ``/publish/CrConfig`` ===================== From 3c8cc154a1831600e082a0ab904e708b46b589ea Mon Sep 17 00:00:00 2001 From: Srijeet Chatterjee Date: Thu, 3 Mar 2022 15:48:43 -0700 Subject: [PATCH 3/4] code review --- CHANGELOG.md | 2 +- .../traffic_monitor/traffic_monitor_api.rst | 16 ++++++++-------- lib/go-tc/crstates.go | 2 +- traffic_monitor/health/cache.go | 2 +- traffic_monitor/manager/statecombiner.go | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da4f16f037..9652793688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [unreleased] ### Added -- [#6448](https://github.com/apache/trafficcontrol/issues/6448) Added `status` and `lastHmPoll` fields to the `publish/CrStates` endpoint of Traffic Monitor (TM). +- [#6448](https://github.com/apache/trafficcontrol/issues/6448) Added `status` and `lastPoll` fields to the `publish/CrStates` endpoint of Traffic Monitor (TM). - Added a new Traffic Ops endpoint to `GET` capacity and telemetry data for CDNi integration. - Added a Traffic Ops endpoints to `PUT` a requested configuration change for a full configuration or per host and an endpoint to approve or deny the request. - Traffic Monitor config option `distributed_polling` which enables the ability for Traffic Monitor to poll a subset of the CDN and divide into "local peer groups" and "distributed peer groups". Traffic Monitors in the same group are local peers, while Traffic Monitors in other groups are distibuted peers. Each TM group polls the same set of cachegroups and gets availability data for the other cachegroups from other TM groups. This allows each TM to be responsible for polling a subset of the CDN while still having a full view of CDN availability. In order to use this, `stat_polling` must be disabled. diff --git a/docs/source/development/traffic_monitor/traffic_monitor_api.rst b/docs/source/development/traffic_monitor/traffic_monitor_api.rst index dbe98c31c4..4a1c237cb3 100644 --- a/docs/source/development/traffic_monitor/traffic_monitor_api.rst +++ b/docs/source/development/traffic_monitor/traffic_monitor_api.rst @@ -361,16 +361,16 @@ Response Structure :caches: An object with keys that are the names of monitored :term:`cache servers` :server name: The name of the server being monitored - :isAvailable: Whether or not this cache is available for monitoring - :ipv4Available: Whether or not an IPV4 interface on this cache is available for monitoring - :ipv6Available: Whether or not an IPV6 interface on this cache is available for monitoring + :isAvailable: Whether or not this cache is available for routing + :ipv4Available: Whether or not an IPV4 interface on this cache is available for routing + :ipv6Available: Whether or not an IPV6 interface on this cache is available for routing :status: The status of this server, along with any additional reason for it to be marked as such - :lastHmPoll: The last time the health data for this server was polled by a traffic monitor + :lastPoll: The last time the health data for this server was polled by a traffic monitor :deliveryServices: An object with keys as the names of monitored :term:`Delivery Services` :delivery service name: The name of the delivery service being monitored :disabledLocations: A list of disabled locations for this delivery service - :isAvailable: Whether or not this delivery service is available for monitoring + :isAvailable: Whether or not this delivery service is available for routing .. code-block:: http :caption: Example Response @@ -382,12 +382,12 @@ Response Structure { "caches": { - "cdn-ec-atl-03": { + "server-name-01": { "isAvailable": true, "ipv4Available": true, "ipv6Available": true, - "status": "REPORTED - id cdn-ec-atl-03 url http://[2001:558:fe13:b1::2]:80/_astats?application=system&inf.name=bond0 fetch error: bad HTTP status: 403; bond0: not found in polled data", - "lastHmPoll": "2022-03-03T12:26:02.78556-07:00" + "status": "REPORTED - id server-name-01 url http://[2001:db8:3333:4444:5555:6666:7777:8888]:80 fetch error: bad HTTP status: 403; interface0: not found in polled data", + "lastPoll": "2022-03-03T12:26:02.78556-07:00" },... }, "deliveryServices": { diff --git a/lib/go-tc/crstates.go b/lib/go-tc/crstates.go index 0c7900623c..a7d99bffbc 100644 --- a/lib/go-tc/crstates.go +++ b/lib/go-tc/crstates.go @@ -43,7 +43,7 @@ type IsAvailable struct { Ipv6Available bool `json:"ipv6Available"` DirectlyPolled bool `json:"-"` Status string `json:"status"` - LastHmPoll time.Time `json:"lastHmPoll"` + LastPoll time.Time `json:"lastPoll"` } // NewCRStates creates a new CR states object, initializing pointer members. diff --git a/traffic_monitor/health/cache.go b/traffic_monitor/health/cache.go index c4f7426938..5247eeda73 100644 --- a/traffic_monitor/health/cache.go +++ b/traffic_monitor/health/cache.go @@ -362,7 +362,7 @@ func CalcAvailability( Ipv6Available: availStatus.Available.IPv6, DirectlyPolled: true, // we know this cache was directly polled because otherwise we wouldn't have a cache.Result for it Status: availStatus.Why, - LastHmPoll: result.Time, + LastPoll: result.Time, }) if available, ok := localStates.GetCache(tc.CacheName(result.ID)); !ok || available.IsAvailable != lastStatus.ProcessedAvailable { diff --git a/traffic_monitor/manager/statecombiner.go b/traffic_monitor/manager/statecombiner.go index 116f8a3c7a..9eb45745a4 100644 --- a/traffic_monitor/manager/statecombiner.go +++ b/traffic_monitor/manager/statecombiner.go @@ -133,7 +133,7 @@ func combineCacheState( IPv6Available: ipv6Available}) } - combinedStates.AddCache(cacheName, tc.IsAvailable{IsAvailable: available, Ipv4Available: ipv4Available, Ipv6Available: ipv6Available, DirectlyPolled: localCacheState.DirectlyPolled, Status: localCacheState.Status, LastHmPoll: localCacheState.LastHmPoll}) + combinedStates.AddCache(cacheName, tc.IsAvailable{IsAvailable: available, Ipv4Available: ipv4Available, Ipv6Available: ipv6Available, DirectlyPolled: localCacheState.DirectlyPolled, Status: localCacheState.Status, LastPoll: localCacheState.LastPoll}) } func combineDSState( From 03b6f91e1217164d35e5b47018e8130c2d117d4d Mon Sep 17 00:00:00 2001 From: Srijeet Chatterjee Date: Fri, 11 Mar 2022 14:57:04 -0700 Subject: [PATCH 4/4] code review fixes --- .../source/development/traffic_monitor/traffic_monitor_api.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/source/development/traffic_monitor/traffic_monitor_api.rst b/docs/source/development/traffic_monitor/traffic_monitor_api.rst index 4a1c237cb3..3a2be0bc1f 100644 --- a/docs/source/development/traffic_monitor/traffic_monitor_api.rst +++ b/docs/source/development/traffic_monitor/traffic_monitor_api.rst @@ -359,6 +359,7 @@ The current state of this CDN per the :ref:`health-proto`. Response Structure """""""""""""""""" :caches: An object with keys that are the names of monitored :term:`cache servers` + :server name: The name of the server being monitored :isAvailable: Whether or not this cache is available for routing @@ -368,7 +369,9 @@ Response Structure :lastPoll: The last time the health data for this server was polled by a traffic monitor :deliveryServices: An object with keys as the names of monitored :term:`Delivery Services` + :delivery service name: The name of the delivery service being monitored + :disabledLocations: A list of disabled locations for this delivery service :isAvailable: Whether or not this delivery service is available for routing