Tyk Analytics + Azure Cosmos DB issue


#1

When using Azure Cosmos DB as datastore, I’m getting the following error when trying to fetch API activity in the tyk dashboard:

ERROR 2018/11/02 13:35:43.108074 panic_handler.go:26: PANIC
URL: /api/usage/apis/26/10/2018/3/11/2018?by=Hits&p=0&sort=1
ERROR: interface conversion: interface {} is float64, not int

Any ideas?


#2

Hi do you have more of the stacktrace from the panic?


#3

It seems my colleague was blacklisted, so I am posting the stack trace instead:

time="Nov  5 14:27:20" level=info msg="Aggregates disabled" 
ERROR 2018/11/05 14:27:20.637115 panic_handler.go:26: PANIC
URL: /api/usage/apis/29/10/2018/6/11/2018?by=Hits&p=0&sort=1
ERROR: interface conversion: interface {} is float64, not int
STACK:
goroutine 10136 [running]:
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.(*Router).handlePanic(0xc4205bcdd0, 0xc420080180, 0xc4200801a0, 0xb7d740, 0xc4204ea940)
    /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:273 +0x47a
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.(*Router).ServeHTTP.func1(0xc4205bcdd0, 0xc420080180)
    /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:43 +0x6f
panic(0xb7d740, 0xc4204ea940)
    /usr/local/go/src/runtime/panic.go:491 +0x283
main.(*AggregateAnalyticsData).unpackAggregate(0xc4203d4160, 0xb82220, 0xc4207277d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /src/github.com/TykTechnologies/tyk-analytics/model_key_analytics.go:247 +0xf8a
main.(*AggregateAnalyticsData).GetSliceDataFromRawLogs(0xc4203d4160, 0x1d, 0xa, 0x7e2, 0x0, 0x6, 0xb, 0x7e2, 0x0, 0x0, ...)
    /src/github.com/TykTechnologies/tyk-analytics/model_key_analytics.go:607 +0x287c
main.(*AggregateAnalyticsData).GetSlice(0xc4203d4160, 0x1d, 0xa, 0x7e2, 0x0, 0x6, 0xb, 0x7e2, 0x0, 0x0, ...)
    /src/github.com/TykTechnologies/tyk-analytics/model_key_analytics.go:450 +0x5d3
main.(*APIContext).handleDefaultReply(0xc42000e628, 0x1d, 0xa, 0x7e2, 0x0, 0x6, 0xb, 0x7e2, 0x0, 0x0, ...)
    /src/github.com/TykTechnologies/tyk-analytics/api_analytics.go:195 +0x80
main.(*APIContext).GetAverageUsagePerAPI(0xc42000e628, 0x10f72e0, 0xc420080180, 0xc4200801a0)
    /src/github.com/TykTechnologies/tyk-analytics/api_analytics.go:329 +0xd9
reflect.Value.call(0xb57da0, 0xcdead0, 0x13, 0xc585e6, 0x4, 0xc42075b348, 0x3, 0x3, 0x1446650, 0xc36760, ...)
    /usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xb57da0, 0xcdead0, 0x13, 0xc42075b348, 0x3, 0x3, 0xbb1f00, 0xc4203b22c0, 0x63657220746f6c70)
    /usr/local/go/src/reflect/value.go:302 +0xa4
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.middlewareStack.func1(0x10f72e0, 0xc420080180, 0xc4200801a0)
    /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:135 +0x37f
main.(*APIContext).InstrumentationMW(0xc42000e628, 0x10f72e0, 0xc420080180, 0xc4200801a0, 0xc4204e44c0)
    /src/github.com/TykTechnologies/tyk-analytics/instrumentation_helpers.go:48 +0x94
reflect.Value.call(0xb6ac80, 0xcdec78, 0x13, 0xc585e6, 0x4, 0xc42075b870, 0x4, 0x4, 0xc420192a80, 0xb6efa0, ...)
    /usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xb6ac80, 0xcdec78, 0x13, 0xc42075b870, 0x4, 0x4, 0x53241d, 0x13e, 0xc4203436c0)
    /usr/local/go/src/reflect/value.go:302 +0xa4
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.(*middlewareHandler).invoke(0xc420689680, 0xc56ec0, 0xc42000e628, 0x16, 0x10f72e0, 0xc420080180, 0xc4200801a0, 0xc4204e44c0)
    /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:155 +0x1e3
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.middlewareStack.func1(0x10f72e0, 0xc420080180, 0xc4200801a0)
    /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:144 +0x1b0
main.GoCraftHttphandlerFunc.func1(0x10f14a0, 0xc420080180, 0xc42051e000)
    /src/github.com/TykTechnologies/tyk-analytics/main.go:597 +0x43
net/http.HandlerFunc.ServeHTTP(0xc420dd0ab0, 0x10f14a0, 0xc420080180, 0xc42051e000)
    /usr/local/go/src/net/http/server.go:1918 +0x44
github.com/TykTechnologies/tyk-analytics/vendor/github.com/TykTechnologies/nosurf.(*CSRFHandler).handleSuccess(0xc42075bda0, 0x10f14a0, 0xc420080180, 0xc42051e000)
    /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/TykTechnologies/nosurf/handler.go:180 +0x51
github.com/TykTechnologies/tyk-analytics/vendor/github.com/TykTechnologies/nosurf.(*CSRFHandler).ServeHTTP(0xc42075bda0, 0x10f14a0, 0xc420080180, 0xc42051e000)
    /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/TykTechnologies/nosurf/handler.go:137 +0x1a4
main.CSRFMiddleware(0x10f72e0, 0xc420080180, 0xc4200801a0, 0xc4204e44c0)
    /src/github.com/TykTechnologies/tyk-analytics/main.go:618 +0x1ca
main.(*APIContext

#5

Hi, seems the forum system flagged one of the replies, I’ve just approved it.
We’re investigating this issue.


#6

Were you able to reproduce the issue?


#7

Hi Pavle, we were able to replicate this issue. We’re currently working on a fix.


#8

That is awesome, thanks!


#9

Is there any update on this as we too face same issue in dashboard, following is our stack trace:

ERROR 2019/02/01 20:55:17.797061 panic_handler.go:26: PANIC
URL: /api/activity/country/25/1/2019/2/2/2019?by=Hits&p=-2&sort=1
ERROR: interface conversion: interface {} is float64, not int
STACK:
goroutine 8231 [running]:
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.(*Router).handlePanic(0xc4205ab860, 0xc4206a15c0, 0xc4206a15e0, 0xb7e920, 0xc4206ae9c0)
        /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:273 +0x47a
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.(*Router).ServeHTTP.func1(0xc4205ab860, 0xc4206a15c0)
        /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:43 +0x6f
panic(0xb7e920, 0xc4206ae9c0)
        /usr/local/go/src/runtime/panic.go:491 +0x283
main.(*AggregateAnalyticsData).unpackAggregate(0xc420381360, 0xb83480, 0xc420b4cf00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /src/github.com/TykTechnologies/tyk-analytics/model_key_analytics.go:247 +0xf8a
main.(*AggregateAnalyticsData).GetSliceData(0xc420381360, 0x19, 0x1, 0x7e3, 0x0, 0x2, 0x2, 0x7e3, 0x0, 0x0, ...)
        /src/github.com/TykTechnologies/tyk-analytics/model_key_analytics_aggregates.go:271 +0x1667
main.(*AggregateAnalyticsData).GetSlice(0xc420381360, 0x19, 0x1, 0x7e3, 0x0, 0x2, 0x2, 0x7e3, 0x0, 0x0, ...)
        /src/github.com/TykTechnologies/tyk-analytics/model_key_analytics.go:483 +0x4e6
main.(*APIContext).handleDefaultReply(0xc420260500, 0x19, 0x1, 0x7e3, 0x0, 0x2, 0x2, 0x7e3, 0x0, 0x0, ...)
        /src/github.com/TykTechnologies/tyk-analytics/api_analytics.go:195 +0x80
main.(*APIContext).GetGroupTrafficByCountry(0xc420260500, 0x10fc320, 0xc4206a15c0, 0xc4206a15e0)
        /src/github.com/TykTechnologies/tyk-analytics/api_analytics.go:292 +0xd9
reflect.Value.call(0xb58fc0, 0xce2fe0, 0x13, 0xc59b66, 0x4, 0xc420667348, 0x3, 0x3, 0x144dc30, 0xc37c40, ...)
        /usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xb58fc0, 0xce2fe0, 0x13, 0xc420667348, 0x3, 0x3, 0xbb3300, 0xc42032cf60, 0x0)
        /usr/local/go/src/reflect/value.go:302 +0xa4
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.middlewareStack.func1(0x10fc320, 0xc4206a15c0, 0xc4206a15e0)
        /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:135 +0x37f
main.(*APIContext).InstrumentationMW(0xc420260500, 0x10fc320, 0xc4206a15c0, 0xc4206a15e0, 0xc42023db60)
        /src/github.com/TykTechnologies/tyk-analytics/instrumentation_helpers.go:48 +0x94
reflect.Value.call(0xb6bfa0, 0xce3130, 0x13, 0xc59b66, 0x4, 0xc420667870, 0x4, 0x4, 0xc420616900, 0xb701a0, ...)
        /usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0xb6bfa0, 0xce3130, 0x13, 0xc420667870, 0x4, 0x4, 0x53241d, 0x13e, 0xc420452cc0)
        /usr/local/go/src/reflect/value.go:302 +0xa4
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.(*middlewareHandler).invoke(0xc42021c9c0, 0xc58440, 0xc420260500, 0x16, 0x10fc320, 0xc4206a15c0, 0xc4206a15e0, 0xc42023db60)
        /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:155 +0x1e3
github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web.middlewareStack.func1(0x10fc320, 0xc4206a15c0, 0xc4206a15e0)
        /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/gocraft/web/router_serve.go:144 +0x1b0
main.GoCraftHttphandlerFunc.func1(0x10f64a0, 0xc4206a15c0, 0xc420b7a800)
        /src/github.com/TykTechnologies/tyk-analytics/main.go:597 +0x43
net/http.HandlerFunc.ServeHTTP(0xc420b4c120, 0x10f64a0, 0xc4206a15c0, 0xc420b7a800)
        /usr/local/go/src/net/http/server.go:1918 +0x44
github.com/TykTechnologies/tyk-analytics/vendor/github.com/TykTechnologies/nosurf.(*CSRFHandler).handleSuccess(0xc420667da0, 0x10f64a0, 0xc4206a15c0, 0xc420b7a800)
        /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/TykTechnologies/nosurf/handler.go:180 +0x51
github.com/TykTechnologies/tyk-analytics/vendor/github.com/TykTechnologies/nosurf.(*CSRFHandler).ServeHTTP(0xc420667da0, 0x10f64a0, 0xc4206a15c0, 0xc420b7a800)
        /src/github.com/TykTechnologies/tyk-analytics/vendor/github.com/TykTechnologies/nosurf/handler.go:137 +0x1a4
main.CSRFMiddleware(0x10fc320, 0xc4206a15c0, 0xc4206a15e0, 0xc42023db60)
        /src/github.com/TykTechnologies/tyk-analytics/main.go:618 +0x1ca
main.(*APIContext).CSRFAPIMidd

#10

Hi, we’ve merged the patch required for CosmosDB compatibility, it will be part of 1.8.1.