Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Added filter (host name or ID) to query API route: /servercheck#5545

Merged
ocket8888 merged 16 commits intoapache:masterfrom
rimashah25:improvement/git-3577
Feb 26, 2021
Merged

Added filter (host name or ID) to query API route: /servercheck#5545
ocket8888 merged 16 commits intoapache:masterfrom
rimashah25:improvement/git-3577

Conversation

@rimashah25
Copy link
Copy Markdown
Contributor

@rimashah25 rimashah25 commented Feb 18, 2021

What does this PR (Pull Request) do?

Which Traffic Control components are affected by this PR?

  • Traffic Ops
  • Documentation

What is the best way to verify this PR?

curl GET for the following calls:

  1. Get all servers: /api/4.0/servercheck or using unknown query param
    image
    image

  2. Get server with a specific param id: /api/4.0/servercheck?id=12

{
  "response": [
    {
      "adminState": "REPORTED",
      "cacheGroup": "CDN_in_a_Box_Mid-02",
      "id": 12,
      "hostName": "mid-02",
      "revalPending": false,
      "profile": "ATS_MID_TIER_CACHE",
      "type": "MID",
      "updPending": false
    }
  ]
}
  1. Get server with a specific param name: /api/4.0/servercheck?name=edge
{
  "response": [
    {
      "adminState": "REPORTED",
      "cacheGroup": "CDN_in_a_Box_Edge",
      "id": 10,
      "hostName": "edge",
      "revalPending": false,
      "profile": "ATS_EDGE_TIER_CACHE",
      "type": "EDGE",
      "updPending": false
    }
  ]
}
  1. Using both query param
    image

  2. Using server names and id that don't match in the DB.
    image

If this is a bug fix, what versions of Traffic Control are affected?

The following criteria are ALL met by this PR

  • This PR includes tests OR I have explained why tests are unnecessary
  • This PR includes documentation OR I have explained why documentation is unnecessary
  • This PR includes an update to CHANGELOG.md OR such an update is not necessary
  • This PR includes any and all required license headers
  • This PR DOES NOT FIX A SERIOUS SECURITY VULNERABILITY (see the Apache Software Foundation's security guidelines for details)

Additional Information

@rimashah25 rimashah25 marked this pull request as ready for review February 19, 2021 16:08
@ocket8888 ocket8888 self-assigned this Feb 19, 2021
Comment thread docs/source/api/v3/servercheck.rst Outdated
Comment thread traffic_ops/traffic_ops_golang/servercheck/servercheck.go Outdated
Comment thread traffic_ops/v4-client/servercheck.go
Comment thread traffic_ops/v4-client/servercheck.go Outdated
Comment thread docs/source/api/v3/servercheck.rst
Comment thread docs/source/api/v3/servercheck.rst
Comment thread traffic_ops/v4-client/servercheck.go Outdated
Comment thread docs/source/api/v3/servercheck.rst Outdated
@rimashah25 rimashah25 requested a review from ocket8888 February 23, 2021 18:10
Comment thread docs/source/api/v3/servercheck.rst Outdated
Copy link
Copy Markdown
Contributor

@ocket8888 ocket8888 left a comment

Choose a reason for hiding this comment

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

So I'm noticing two things. First of all, the two query parameters cannot be used at the same time; it results in no filtering:

GET /api/3.0/servercheck?name=mid-01&id=11 HTTP/1.1
User-Agent: python-requests/2.24.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Cookie: mojolicious=...
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin: *
Content-Encoding: gzip
Content-Type: application/json
Set-Cookie: mojolicious=...; Path=/; Expires=Wed, 24 Feb 2021 00:22:40 GMT; Max-Age=3600; HttpOnly
Vary: Accept-Encoding
X-Server-Name: traffic_ops_golang/
Date: Tue, 23 Feb 2021 23:22:40 GMT
Content-Length: 217

{
        "response": [
                {
                        "adminState": "REPORTED",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 11,
                        "hostName": "edge",
                        "revalPending": false,
                        "profile": "ATS_EDGE_TIER_CACHE",
                        "type": "EDGE",
                        "updPending": false
                },
                {
                        "adminState": "REPORTED",
                        "cacheGroup": "CDN_in_a_Box_Mid-01",
                        "id": 12,
                        "hostName": "mid-01",
                        "revalPending": false,
                        "profile": "ATS_MID_TIER_CACHE",
                        "type": "MID",
                        "updPending": false
                },
                {
                        "adminState": "REPORTED",
                        "cacheGroup": "CDN_in_a_Box_Mid-02",
                        "id": 6,
                        "hostName": "mid-02",
                        "revalPending": false,
                        "profile": "ATS_MID_TIER_CACHE",
                        "type": "MID",
                        "updPending": false
                }
        ]
}

If this is intended behavior and the two cannot both exist in the request, that should be documented, and ideally it'd return a warning-level alert indicating why filtering wasn't performed. Otherwise, if the intent is that they can both be used, then filtering when the id and hostname refer to the same server should result in an output length of exactly one, and if they do not refer to the same server, then it should return an empty array because nothing matches.

Secondly, if I give it a query parameter that it doesn't recognize or requires others, I can get back a response that includes non-cache servers:

GET /api/3.0/servercheck?page=1 HTTP/1.1
User-Agent: python-requests/2.24.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Cookie: mojolicious=...
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Access-Control-Allow-Origin: *
Content-Encoding: gzip
Content-Type: application/json
Set-Cookie: mojolicious=...
Vary: Accept-Encoding
X-Server-Name: traffic_ops_golang/
Date: Tue, 23 Feb 2021 23:27:46 GMT
Content-Length: 477

{
        "response": [
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 3,
                        "hostName": "db",
                        "revalPending": false,
                        "profile": "TRAFFIC_OPS_DB",
                        "type": "TRAFFIC_OPS_DB",
                        "updPending": false
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 5,
                        "hostName": "dns",
                        "revalPending": false,
                        "profile": "BIND_ALL",
                        "type": "BIND",
                        "updPending": false
                },
                {
                        "adminState": "REPORTED",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 11,
                        "hostName": "edge",
                        "revalPending": false,
                        "profile": "ATS_EDGE_TIER_CACHE",
                        "type": "EDGE",
                        "updPending": false
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 9,
                        "hostName": "enroller",
                        "revalPending": false,
                        "profile": "ENROLLER_ALL",
                        "type": "ENROLLER",
                        "updPending": false
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 7,
                        "hostName": "influxdb",
                        "revalPending": false,
                        "profile": "INFLUXDB",
                        "type": "INFLUXDB",
                        "updPending": false
                },
                {
                        "adminState": "REPORTED",
                        "cacheGroup": "CDN_in_a_Box_Mid-01",
                        "id": 12,
                        "hostName": "mid-01",
                        "revalPending": false,
                        "profile": "ATS_MID_TIER_CACHE",
                        "type": "MID",
                        "updPending": false
                },
                {
                        "adminState": "REPORTED",
                        "cacheGroup": "CDN_in_a_Box_Mid-02",
                        "id": 6,
                        "hostName": "mid-02",
                        "revalPending": false,
                        "profile": "ATS_MID_TIER_CACHE",
                        "type": "MID",
                        "updPending": false
                },
                {
                        "adminState": "REPORTED",
                        "cacheGroup": "CDN_in_a_Box_Origin",
                        "id": 8,
                        "hostName": "origin",
                        "revalPending": false,
                        "profile": "ORG_MSO",
                        "type": "ORG",
                        "updPending": true
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 2,
                        "hostName": "trafficmonitor",
                        "revalPending": false,
                        "profile": "RASCAL-Traffic_Monitor",
                        "type": "RASCAL",
                        "updPending": true
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 13,
                        "hostName": "trafficops",
                        "revalPending": false,
                        "profile": "TRAFFIC_OPS",
                        "type": "TRAFFIC_OPS",
                        "updPending": false
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 4,
                        "hostName": "trafficportal",
                        "revalPending": false,
                        "profile": "TRAFFIC_PORTAL",
                        "type": "TRAFFIC_PORTAL",
                        "updPending": false
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 10,
                        "hostName": "trafficrouter",
                        "revalPending": false,
                        "profile": "CCR_CIAB",
                        "type": "CCR",
                        "updPending": true
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 1,
                        "hostName": "trafficstats",
                        "revalPending": false,
                        "profile": "TRAFFIC_STATS",
                        "type": "TRAFFIC_STATS",
                        "updPending": false
                },
                {
                        "adminState": "ONLINE",
                        "cacheGroup": "CDN_in_a_Box_Edge",
                        "id": 14,
                        "hostName": "trafficvault",
                        "revalPending": false,
                        "profile": "RIAK_ALL",
                        "type": "RIAK",
                        "updPending": false
                }
        ]
}

Copy link
Copy Markdown
Contributor

@ocket8888 ocket8888 left a comment

Choose a reason for hiding this comment

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

It all seems to be working rather consistently now.

@ocket8888 ocket8888 merged commit 3aa3bc6 into apache:master Feb 26, 2021
@rimashah25 rimashah25 deleted the improvement/git-3577 branch February 26, 2021 17:45
@rawlinp rawlinp added new feature A new feature, capability or behavior Traffic Ops related to Traffic Ops labels Mar 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

new feature A new feature, capability or behavior Traffic Ops related to Traffic Ops

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFE: API route to query servercheck data by host name or ID

4 participants