diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d31645c65..3ff373d22e 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 `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 f406b2a890..3a2be0bc1f 100644 --- a/docs/source/development/traffic_monitor/traffic_monitor_api.rst +++ b/docs/source/development/traffic_monitor/traffic_monitor_api.rst @@ -343,22 +343,63 @@ 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` -TODO + :server name: The name of the server being monitored + + :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 + :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 -..???? -**raw** + :disabledLocations: A list of disabled locations for this delivery service + :isAvailable: Whether or not this delivery service is available for routing -The current state of this CDN per this Traffic Monitor only. +.. 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 + + { + "caches": { + "server-name-01": { + "isAvailable": true, + "ipv4Available": true, + "ipv6Available": true, + "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": { + "ds-1": { + "disabledLocations": [], + "isAvailable": true + },... + } + } ``/publish/CrConfig`` ===================== diff --git a/lib/go-tc/crstates.go b/lib/go-tc/crstates.go index eb8fe445a2..a7d99bffbc 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"` + 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 1cf6bcb58b..5247eeda73 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, + 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 871163ad89..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}) + combinedStates.AddCache(cacheName, tc.IsAvailable{IsAvailable: available, Ipv4Available: ipv4Available, Ipv6Available: ipv6Available, DirectlyPolled: localCacheState.DirectlyPolled, Status: localCacheState.Status, LastPoll: localCacheState.LastPoll}) } func combineDSState(