Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jovemfelix/cdcefe4b35254ab0f3c93afc153bc2ba to your computer and use it in GitHub Desktop.
Save jovemfelix/cdcefe4b35254ab0f3c93afc153bc2ba to your computer and use it in GitHub Desktop.

Example to Purge Backend Errors from 3scale

Enviroment version used

Openshift 4.10.22

Red Hat 3scale : 2.11

VARIABLES

NS_3SCALE=my-3scale
API_USER=$(oc extract secret/backend-internal-api --keys=username --to=- -n $NS_3SCALE)
API_PASS=$(oc extract secret/backend-internal-api --keys=password --to=- -n $NS_3SCALE)
API_URL=https://backend-3scale.apps.mycluster.example.com
# assumming that exists a service with id=10
SERVICE_ID=10

Create a Sample Error

MY_3SCALE_API_URL=https://reproducer-production-apicast.apps.mycluster.example.com/debug
INVALID_USER_KEY=e1817510d9389e5c59ba45d9fcf98e1B

$ curl -k "${MY_3SCALE_API_URL}?user_key=${INVALID_USER_KEY}"
Authentication failed

Backend-listener logging

$ oc logs -f dc/backend-listener --tail=1
172.24.207.32 - - [15/Dec/2022 15:02:38 UTC] "GET /transactions/authrep.xml?service_id=10&service_token=2768496457e5d2c65d63c174ad97e79bee927ec2201e125f51489c64f34b51b2&usage%5Bhits%5D=1&user_key=e1817510d9389e5c59ba45d9fcf98e1B HTTP/1.1" 403 - 0.005907889 0 0 0 6 415 323 - "rejection_reason_header=1&limit_headers=1&no_body=1"

List Errors by ServiceID

$ curl -s -k -u "$API_USER:$API_PASS" "${API_URL}/internal/services/${SERVICE_ID}/errors/" | jq
{
  "status": "found",
  "errors": [
    {
      "code": "user_key_invalid",
      "message": "user key \"e1817510d9389e5c59ba45d9fcf98e1B\" is invalid",
      "timestamp": "2022-12-15 15:02:38 UTC",
      "context_info": {
        "url": "https://backend-3scale.apps.mycluster.example.com/transactions/authrep.xml?service_id=10&service_token=2768496457e5d2c65d63c174ad97e79bee927ec2201e125f51489c64f34b51b2&usage%5Bhits%5D=1&user_key=e1817510d9389e5c59ba45d9fcf98e1B",
        "method": "GET",
        "form_vars": null,
        "user_agent": "APIcast/3.11.0 (Linux; x64; env:production)",
        "ip": "172.24.207.32",
        "content_type": null,
        "content_length": null,
        "extensions": {
          "rejection_reason_header": "1",
          "limit_headers": "1",
          "no_body": true
        }
      }
    }
  ],
  "count": 1
}

Backend-listener logging

$ oc logs -f dc/backend-listener --tail=1
10.203.21.67 - 3scale_api_user [15/Dec/2022 15:05:51 UTC] "GET /internal/services/10/errors/ HTTP/1.1" 200 668 0.005773352 0 0 0 6 2449 2323 - -

Delete Errors from by ServiceID

$ curl -X DELETE -s -k -u "$API_USER:$API_PASS" "${API_URL}/internal/services/${SERVICE_ID}/errors/"
{"status":"deleted"}%

Backend-listener logging

$ oc logs -f dc/backend-listener --tail=1
10.203.27.190 - 3scale_api_user [15/Dec/2022 17:10:20 UTC] "DELETE /internal/services/10/errors/ HTTP/1.1" 200 20 0.003587789 0 0 0 12 1524 1408 - -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment