Tyk v2.2 Documentation Components

HomeTyk v2.2 Documentation ComponentsService Discovery: GUI

Service Discovery: GUI

The Service Discovery settings are in your API editor, near the bottom of the Core Settings Tab:

Service discovery checkbox location

Configuring service discovery via the Dashboard

Set this to checked to enable the discovery module.

Once enabled, you will have all the options to configure your SD endpoints:

Service discovery configuration form

The settings are as follows:

  • Query endpoint: The endpoint to call, this would probably be your Consul, etcd or Eureka K/V store.
  • Target path: Use this setting to set a target path to append to the discovered endpoint, since many SD services only provide host and port data, it is important to be able to target a specific resource on that host, setting this value will enable that.
  • Data path: The namespace of the data path, so for example if your service responds with:

    { 
        "action": "get", 
        "node": { 
            "key": "/services/single", 
            "value": "http://httpbin.org:6000", 
            "modifiedIndex": 6, 
            "createdIndex": 6 
        } 
    }
    

    Then your namespace would be node.value.

  • Are the values nested?: Sometimes the data you are retrieving is nested in another JSON object, e.g. this is how etcd responds with a JSON object as a value key:

    {
        "action": "get",
        "node": {
            "key": "/services/single",
            "value": "{"hostname": "http://httpbin.org", "port": "80"}",
            "modifiedIndex": 6,
            "createdIndex": 6
        }
    }
    

    In this case, the data actually lives within this string-encoded JSON object, so in this case, you set the value to checked, and use a combination of the data path and parent data path (below).

  • Parent data path: This is the namespace of the where to find the nested value, in the above example, it would be node.value. You would then change the data path setting to be hostname, since this is where the hostname data resides in the JSON string. Tyk automatically assumes that the data_path in this case is in a string-encoded JSON object and will try to deserialise it.

    Tyk will decode the JSON string and then apply the data path namespace to that object in order to find the value.

  • Port data path: In the above nested example, we can see that there is a separate port value for the service in the nested JSON. In this case you can set the port data path value and Tyk will treat data path as the hostname and zip them together (this assumes that the hostname element does not end in a slash or resource identifier such as /widgets/).

    In the above example, the port data path would be port.

  • Does the endpoint provide a target list?: If you are using load balancing, set this value to true and Tyk will treat the data path as a list and inject it into the target list of your API Definition.

  • Cache timeout: Tyk caches target data from a discovery service, in order to make this dynamic you can set a cache value when the data expires and new data is loaded. Setting it too low will cause Tyk to call the SD service too often, setting it too high could mean that failures are not recovered from quickly enough.

Was this article helpful to you? Yes No