Tyk with eureka


#1

hi

service descovery in API define object

we define follow:

“proxy”: {
“preserve_host_header”: true,
“listen_path”: “/openapitest/”,
“target_url”: “”,
“strip_listen_path”: true,
“enable_load_balancing”: true,
“target_list”: [],
“check_host_against_uptime_tests”: false,
“service_discovery”: {
“use_discovery_service”: true,
“query_endpoint”: “http://x.x.x.x:xxxx/eureka/apps/stackservice-test”,
“use_nested_query”: false,
“parent_data_path”: “application.instance”,
“data_path”: “hostName”,
“port_data_path”: “port.$”,
“target_path”: “”,
“use_target_list”: true,
“cache_timeout”: 60,
“endpoint_returns_list”: false
}
},

it is not working… with error message follow :

[Aug 23 13:17:38] ERROR invalid character ‘<’ looking for beginning of value
2016/08/23 13:17:38 http: panic serving 10.0.2.15:43896: runtime error: invalid memory address or nil pointer dereference
goroutine 194 [running]:
net/http.(*conn).serve.func1(0xc8206f5d80)
/usr/local/go/src/net/http/server.go:1389 +0xc1
panic(0xd40ae0, 0xc82000e120)
/usr/local/go/src/runtime/panic.go:426 +0x4e9
main.(*ServiceDiscovery).ParseObject(0xc820b25b00, 0xc82031f400, 0xd00, 0xc82079b080, 0x0, 0x0)
/home/tyk/go/src/github.com/lonelycode/tyk/service_discovery.go:254 +0x4b4
main.(*ServiceDiscovery).ProcessRawData(0xc820b25b00, 0xc82031f400, 0xd00, 0x0, 0x0, 0x0, 0x0)
/home/tyk/go/src/github.com/lonelycode/tyk/service_discovery.go:294 +0x7e2
main.(*ServiceDiscovery).GetTarget(0xc820b25b00, 0xc820402870, 0x22, 0x0, 0x0, 0x0, 0x0)
/home/tyk/go/src/github.com/lonelycode/tyk/service_discovery.go:316 +0xc4
main.GetURLFromService(0xc820135200, 0x0, 0x0, 0x0, 0x0)
/home/tyk/go/src/github.com/lonelycode/tyk/tyk_reverse_proxy_clone.go:31 +0x1d7
main.TykNewSingleHostReverseProxy.func1(0xc8210ff260)
/home/tyk/go/src/github.com/lonelycode/tyk/tyk_reverse_proxy_clone.go:112 +0x7d
main.(*ReverseProxy).WrappedServeHTTP(0xc8210cb740, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180, 0x57bbce00, 0x0)
/home/tyk/go/src/github.com/lonelycode/tyk/tyk_reverse_proxy_clone.go:422 +0x600
main.(*ReverseProxy).ServeHTTP(0xc8210cb740, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180, 0xc82079ae60)
/home/tyk/go/src/github.com/lonelycode/tyk/tyk_reverse_proxy_clone.go:327 +0x59
main.SuccessHandler.ServeHTTP(0xc8208fd1a0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180, 0x0)
/home/tyk/go/src/github.com/lonelycode/tyk/handler_success.go:350 +0x5cc
main.DummyProxyHandler.ServeHTTP(0xc8208fd1a0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/handler_proxy.go:13 +0x42
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cb8c0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cb900, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cb940, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cb980, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cb9c0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cba00, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cba40, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cba80, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbac0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbb00, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbbc0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbc00, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbc40, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbc80, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbcc0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbd40, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbdc0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
main.CreateMiddleware.func1.1(0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/lonelycode/tyk/middleware.go:61 +0x38b
net/http.HandlerFunc.ServeHTTP(0xc8210cbe00, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1618 +0x3a
github.com/gorilla/mux.(*Router).ServeHTTP(0xc820586370, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/home/tyk/go/src/github.com/gorilla/mux/mux.go:98 +0x29e
net/http.(*ServeMux).ServeHTTP(0xc8210779e0, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:1910 +0x17d
net/http.serverHandler.ServeHTTP(0xc820473980, 0x7f9b81cd8e78, 0xc820119520, 0xc8210ff180)
/usr/local/go/src/net/http/server.go:2081 +0x19e
net/http.(*conn).serve(0xc8206f5d80)
/usr/local/go/src/net/http/server.go:1472 +0xf2e
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2137 +0x44e

how to solve it…?


http://x.x.x.x:xxxx/eureka/apps/stackservice-test

<?xml version="1.0"?>
<application>
	<name>STACKSERVICE-TEST</name>
	<instance>
		<instanceId>SEOGI:stackService-Test:8080</instanceId>
		<hostName>x.x.x.x</hostName>
		<app>STACKSERVICE-TEST</app>
		<ipAddr>y.y.y.y</ipAddr>
		<status>UP</status>
		<overriddenstatus>UNKNOWN</overriddenstatus>
		<port enabled="true">8080</port>
		<securePort enabled="false">443</securePort>
		<countryId>1</countryId>
		<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
			<name>MyOwn</name>
		</dataCenterInfo>
		<leaseInfo>
			<renewalIntervalInSecs>30</renewalIntervalInSecs>
			<durationInSecs>90</durationInSecs>
			<registrationTimestamp>1471916965472</registrationTimestamp>
			<lastRenewalTimestamp>1471926478958</lastRenewalTimestamp>
			<evictionTimestamp>0</evictionTimestamp>
			<serviceUpTimestamp>1471916964961</serviceUpTimestamp>
		</leaseInfo>
		<metadata class="java.util.Collections$EmptyMap"/>
		<homePageUrl>http://x.x.x.x:xxxx/</homePageUrl>
		<statusPageUrl>http://x.x.x.x:xxxx/info</statusPageUrl>
		<healthCheckUrl>http://x.x.x.x:xxxx/health</healthCheckUrl>
		<vipAddress>stackService-Test</vipAddress>
		<secureVipAddress>stackService-Test</secureVipAddress>
		<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
		<lastUpdatedTimestamp>1471916965472</lastUpdatedTimestamp>
		<lastDirtyTimestamp>1471911678633</lastDirtyTimestamp>
		<actionType>ADDED</actionType>
	</instance>
</application>

#2

With Eureka you will need to have it return JSON - the trick is to define an API in your gateway that points at the eureka endpoint and to inject the header that forced a JSON response.

There’s a post somewhere on the forum about it I think…

M.


#3

i trid it… but i don’t understand
the way to inject the header is extended_path?

it is my API define object… please advise me

{
    "id": "57b58da93283560a57000001",
    "name": "test",
    "slug": "test",
    "api_id": "168f2b69fc764ec95a368d3c279beeff",
    "org_id": "57849d033283560a63000001",
    "use_keyless": false,
    "use_oauth2": false,
    "use_openid": false,
    "openid_options": {
        "providers": [],
        "segregate_by_client": false
    },
    "oauth_meta": {
        "allowed_access_types": [],
        "allowed_authorize_types": [],
        "auth_login_redirect": ""
    },
    "auth": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization"
    },
    "use_basic_auth": false,
    "enable_jwt": false,
    "jwt_signing_method": "",
    "jwt_source": "",
    "jwt_identity_base_field": "",
    "jwt_client_base_field": "",
    "jwt_policy_field_name": "",
    "notifications": {
        "shared_secret": "",
        "oauth_on_keychange_url": ""
    },
    "enable_signature_checking": false,
    "hmac_allowed_clock_skew": -1,
    "definition": {
        "location": "header",
        "key": "x-api-version"
    },
    "version_data": {
        "not_versioned": true,
        "versions": {
            "Default": {
                "name": "Default",
                "expires": "",
                "paths": {
                    "ignored": [],
                    "white_list": [],
                    "black_list": []
                },
                "use_extended_paths": true,
                "extended_paths": {
                    "ignored": [
						{
                            "path": "/test/",
                            "method_actions": {
                                "POST": {
                                    "action": "reply",
                                    "code": 200,
                                    "data": "{\"test\":\"okey\"}",
                                    "headers": {}
                                }
                            }
                        }
					],
                    "white_list": [],
                    "black_list": [],
                    "cache": [],
                    "transform": [],
                    "transform_response": [],
                    "transform_headers": [],
                    "transform_response_headers": [{
			"delete_headers":[],
			"add_headers":{"test":"test1"},
			"path":"widgets{rest}",
			"method":"GET"
		    }],
                    "hard_timeouts": [],
                    "circuit_breakers": [],
                    "url_rewrites": [],
                    "virtual": [],
                    "size_limits": [],
                    "method_transforms": []
                },
                "global_headers": {"Accept":"application/json", "Content-Type":"application/json"},
                "global_headers_remove": [],
                "global_size_limit": 0,
                "override_target": ""
            }
        }
    },
    "uptime_tests": {
        "check_list": [],
        "config": {
            "expire_utime_after": 0,
            "service_discovery": {
                "use_discovery_service": false,
                "query_endpoint": "",
                "use_nested_query": false,
                "parent_data_path": "",
                "data_path": "",
                "port_data_path": "",
                "target_path": "",
                "use_target_list": false,
                "cache_timeout": 60,
                "endpoint_returns_list": false
            },
            "recheck_wait": 0
        }
    },
    "proxy": {
        "preserve_host_header": true,
        "listen_path": "/test/",
        "target_url": "
        "strip_listen_path": true,
        "enable_load_balancing": true,
        "target_list": [],
        "check_host_against_uptime_tests": false,
        "service_discovery": {
            "use_discovery_service": true,
            "query_endpoint": "http://10.0.1.254:8761/eureka/apps/stackservice-test",
            "use_nested_query": false,
            "parent_data_path": "application.instance",								
            "data_path": "hostName",
            "port_data_path": "port.$",
            "target_path": "",
            "use_target_list": true,
            "cache_timeout": 60,
            "endpoint_returns_list": false
        }
    },
    "custom_middleware": {
	"pre": [
	{
            "name": "samplePreProcessMiddleware",
            "path": "/opt/tyk-gateway/middleware/apre.js",
            "require_session": false
	}
	],
	"post": [
	{
            "name": "samplePostProcessMiddleware",
            "path": "/opt/tyk-gateway/middleware/apost.js",
            "require_session": false
	}],
        "response": []
    },
    "cache_options": {
        "cache_timeout": 60,
        "enable_cache": true,
        "cache_all_safe_requests": false,
        "cache_response_codes": [],
        "enable_upstream_cache_control": false
    },
    "session_lifetime": 0,
    "active": true,
    "auth_provider": {
        "name": "",
        "storage_engine": "",
        "meta": {}
    },
    "session_provider": {
        "name": "",
        "storage_engine": "",
        "meta": null
    },
    "event_handlers": {
        "events": {}
    },
    "enable_batch_request_support": false,
    "enable_ip_whitelisting": false,
    "allowed_ips": [],
    "dont_set_quota_on_create": false,
    "expire_analytics_after": 0,
    "response_processors": [],
    "CORS": {
        "enable": false,
        "allowed_origins": [],
        "allowed_methods": [],
        "allowed_headers": [],
        "exposed_headers": [],
        "allow_credentials": false,
        "max_age": 24,
        "options_passthrough": false,
        "debug": false
    },
    "domain": "",
    "do_not_track": false,
    "tags": [],
    "enable_context_vars": false
}

#4

It might be easier to use the global injector for this, as this is a one-off service proxy, saves you messing around with the match path.


#5

i used global header. but it is not workd…


#6

have you tried searching the forum? This chap here sorted it out using this method:


#7

Thank you!
i solved it.!!