CLI を使用したトラブルシューティング

Anypoint Flex Gateway には、ゲートウェイの API インスタンス、サービス、設定、使用可能な拡張機能 (ポリシー) に関連した情報を照会できる ​flexctl dump​ CLI が含まれています。

たとえば、次のインラインスニペットは、デフォルトの名前空間で ​jsonplaceholder-api​ という単独の API インスタンスを定義します (名前空間名画明確に指定されていないため ​default​ のままになっています)。 また、このスニペットは ​http-basic-authentication-flex​ という内部ポリシーを定義しています。

設定例

apiVersion: gateway.mulesoft.com/v1alpha1
kind: ApiInstance
metadata:
  name: jsonplaceholder-api
spec:
  address: http://0.0.0.0:8080
  services:
    jsonplaceholder:
      address: https://jsonplaceholder.typicode.com:443/
      routes:
        - rules:
            - path: /api(/users/.*)
            - path: /api(/comments/.*)
  policies:
    - policyRef:
        name: http-basic-authentication-flex
      config:
        username: chris
        password: admin

CLI を実行する

  1. API インスタンス、サービス、設定、拡張機能の JSON 表現を確認するには、次のコマンドを実行します。

    flexctl dump

    Docker または Podman コンテナで実行している場合は、このコマンドをコンテナ自身の中で実行してください。

    このコマンドでは 4 つのファイルが出力されます。

    • api-instances.json

    • services.json

    • configuration.json

    • extensions.json

  2. ファイル名に続いて ​cat​ を実行し、JSON ファイルの内容を表示します。

    • API インスタンス

    • サービス

    • 設定

    • 拡張機能

    cat api-instances.json

    api-instances.json​ ファイルの内容は次のようになります。

    [
       {
          "address":"http://0.0.0.0:8080",
          "kind":"ApiInstance",
          "name":"jsonplaceholder-api",
          "namespace":"default",
          "policies":[
             {
                "config":{
                   "password":"admin",
                   "username":"chris"
                },
                "extension":{
                   "kind":"Extension",
                   "name":"http-basic-authentication-flex",
                   "namespace":"default"
                },
                "kind":"Policy",
                "name":"jsonplaceholder-api-http-basic-authentication-flex-1",
                "namespace":"default"
             },
             {
                "config":{
                   "destinationRef":{
                      "kind":"Service",
                      "name":"jsonplaceholder-api-jsonplaceholder",
                      "namespace":"default"
                   }
                }
                "extension":{
                   "kind":"Extension",
                   "name":"route",
                   "namespace":"default"
                },
                "kind":"Policy",
                "name":"jsonplaceholder-api-jsonplaceholder-route-1",
                "namespace":"default",
                "order":50,
                "rules":[
                   {
                      "path":"/api(/users/.*)"
                   },
                   {
                      "path":"/api(/comments/.*)"
                   }
                ]
             },
             {
                "extension":{
                   "kind":"Extension",
                   "name":"envoy.filters.http.router",
                   "namespace":"default"
                },
                "kind":"Policy",
                "name":"envoy.filters.http.router",
                "namespace":"default",
                "order":2147483647
             }
          ]
       }
    ]
    cat services.json

    services.json​ ファイルの内容は次のようになります。

    [
       {
          "address":"https://jsonplaceholder.typicode.com:443/",
          "kind":"Service",
          "name":"jsonplaceholder-api-jsonplaceholder",
          "namespace":"default"
       }
    ]
    cat configuration.json

    configuration.json​ ファイルの内容は次のようになります。

    {
      "internalMetrics": {
        "enabled": false
      },
      "logging": {},
      "platformConnection": {
        "anypoint": {
          "url": "https://anypoint.mulesoft.com"
        },
        "environment": {
          "cluster_id": "4aa281e9-1a1d-4c56-8669-2d887b2e1938",
          "env_id": "ad067f80-69ee-4abb-9d05-bec98ece1e20",
          "org_id": "1caa0b9b-4f4d-43c4-a1b6-f925a8c77baa"
        },
        "logging": {
          "certificate": {
            "cert": "demo-local.pem",
            "key": "demo-local.key"
          },
          "url": "https://logging.ingestion.us-east-1.msap.io/ingestion/api/v1/logging"
        },
        "metering": {
          "certificate": {
            "cert": "demo-local.pem",
            "key": "demo-local.key"
          },
          "url": "https://metering.ingestion.us-east-1.msap.io/ingestion/api/v1/metering"
        },
        "mode": "offline",
        "monitoring": {
          "certificate": {
            "cert": "demo-local.pem",
            "key": "demo-local.key"
          },
          "url": "https://monitoring.ingestion.us-east-1.msap.io/ingestion/api/v1/monitoring"
        },
        "runtimeEvents": {
          "certificate": {
            "cert": "demo-local.pem",
            "key": "demo-local.key"
          },
          "url": "https://anypoint.mulesoft.com/apiruntime/v1/events"
        }
      },
      "resourceLimits": {
        "apiInstances": 100,
        "policies": 400
      },
      "sharedStorage": {},
      "version": "1.1.0"
    }
    cat extensions.json

    extensions.json​ ファイルには Flex Gateway で使用できるすべてのポリシーが含まれます。このファイルの内容は次のようになります。

    {
        "extends": [
          {
            "kind": "Extension",
            "labels": {
              "flex.mulesoft.com/created-by": "flex-filesystem",
              "flex.mulesoft.com/managed-by": "flex-filesystem"
            },
            "name": "extension-definition",
            "namespace": "default"
          },
          {
            "kind": "Extension",
            "labels": {
              "flex.mulesoft.com/created-by": "flex-filesystem",
              "flex.mulesoft.com/managed-by": "flex-filesystem"
            },
            "name": "extension-qos",
            "namespace": "default"
          }
        ],
        "kind": "Extension",
        "labels": {
          "flex.mulesoft.com/created-by": "flex-filesystem",
          "flex.mulesoft.com/managed-by": "flex-filesystem"
        },
        "name": "header-injection-definition",
        "namespace": "default",
        "properties": [
          {
            "name": "config",
            "properties": [
              {
                "items": {
                  "name": "inboundHeaders",
                  "properties": [
                    {
                      "name": "key",
                      "type": "stringOrDataweave"
                    },
                    {
                      "name": "value",
                      "type": "stringOrDataweave"
                    }
                  ],
                  "type": "object"
                },
                "name": "inboundHeaders",
                "type": "array"
              },
              {
                "items": {
                  "name": "outboundHeaders",
                  "properties": [
                    {
                      "name": "key",
                      "type": "stringOrDataweave"
                    },
                    {
                      "name": "value",
                      "type": "stringOrDataweave"
                    }
                  ],
                  "type": "object"
                },
                "name": "outboundHeaders",
                "type": "array"
              }
            ],
            "type": "object"
          }
        ]
      }

冗長レベルの変更

flexctl dump​ CLI によって出力される情報の量を変更できます。たとえば、冗長性を ​10​ の値まで増やすには、次を使用して ​flexctl dump​ を実行します。

flexctl dump -v 10

出力ディレクトリの変更

さらに、​flexctl dump​ で 4 つのファイルが出力されるディレクトリを変更できます。たとえば、​/tmp​ に出力するには、次を使用して ​flexctl dump​ を実行します。

flexctl dump --output-directory /tmp