envoyproxy / envoy-tools

Companion tooling for Envoy proxy
Apache License 2.0
49 stars 24 forks source link

[csds-client] csds-client fails to parse node id contains "\" #26

Closed fuqianggao closed 3 years ago

fuqianggao commented 3 years ago

csds-client will throw an error: "found unknown escape character" if node id contains backslash

fuqianggao commented 3 years ago

cc @Rainton

Rainton commented 3 years ago

@fuqianggao Does this error occur when the -node_id field contains backslash in request.yaml? May I see your input yaml file?

fuqianggao commented 3 years ago

node_matchers:

Rainton commented 3 years ago

node_matchers:

  • node_id: exact: "sidecar-10.4.0.2-productpage-v1-787d794cf9-rztcj.default-\default.svc.cluster.local" node_metadatas:
  • path:
  • key: TRAFFICDIRECTOR_GCP_PROJECT_NUMBER value: string_match: exact: "798832730858"
  • path:
  • key: TRAFFICDIRECTOR_NETWORK_NAME value: string_match: exact: "default"

@fuqianggao I think maybe you should use \\ instead of \? eg:

node_matchers:
  - node_id:
      exact: "sidecar-10.4.0.2-productpage-v1-787d794cf9-rztcj.default-\\default.svc.cluster.local"
    node_metadatas:
      - path:
          - key: TRAFFICDIRECTOR_GCP_PROJECT_NUMBER
        value:
          string_match:
            exact: "798832730858"
      - path:
          - key: TRAFFICDIRECTOR_NETWORK_NAME
        value:
          string_match:
            exact: "default"

Then the client will work well and we can get the JSON output as following:

{
   "nodeId": {
      "exact": "sidecar-10.4.0.2-productpage-v1-787d794cf9-rztcj.default-\\default.svc.cluster.local"
   },
   "nodeMetadatas": [
      {
         "path": [
            {
               "key": "TRAFFICDIRECTOR_GCP_PROJECT_NUMBER"
            }
         ],
         "value": {
            "stringMatch": {
               "exact": "798832730858"
            }
         }
      },
      {
         "path": [
            {
               "key": "TRAFFICDIRECTOR_NETWORK_NAME"
            }
         ],
         "value": {
            "stringMatch": {
               "exact": "default"
            }
         }
      }
   ]
}

Since in JSON and YAML, backslash in the string is considered as a special character and the correct representation of the backslash inside strings is \\.

If the node id contains a backslash, the config in JSON in response should be like ".....\\....", or the JSON format is wrong.

fuqianggao commented 3 years ago

You are right. Thanks.