Strange Sum metric behavior / output

34 views
Skip to first unread message

Jean-Charles Eloi

unread,
Jul 5, 2013, 8:47:27 AM7/5/13
to cube...@googlegroups.com
Hello,

I've been toying with Cube for a few hours and I'm getting blocked and puzzled by the output I get from the server while querying it for some really simple results...

Example :
Extract from my events collection, directly out of mongo :

{ "t" : ISODate("2013-07-05T00:05:03Z"), "d" : { "key" : "P2_android_VSCM_NbWSCalls", "value" : "1477" }, "_id" : ObjectId("51d6bf0a24b7ab480d00004a") }
{ "t" : ISODate("2013-07-05T00:15:03Z"), "d" : { "key" : "P2_android_VSCM_NbWSCalls", "value" : "1308" }, "_id" : ObjectId("51d6bf0a24b7ab480d0001a6") }
{ "t" : ISODate("2013-07-05T00:25:03Z"), "d" : { "key" : "P2_android_VSCM_NbWSCalls", "value" : "1140" }, "_id" : ObjectId("51d6bf0a24b7ab480d00030b") }
{ "t" : ISODate("2013-07-05T00:35:03Z"), "d" : { "key" : "P2_android_VSCM_NbWSCalls", "value" : "1081" }, "_id" : ObjectId("51d6bf0a24b7ab480d0004be") }
{ "t" : ISODate("2013-07-05T00:45:03Z"), "d" : { "key" : "P2_android_VSCM_NbWSCalls", "value" : "816" }, "_id" : ObjectId("51d6bf0a24b7ab480d000671") }

Extract from the metrics collection (the output is the same via the evaluator) :

{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbWSCalls\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:05:00Z") }, "i" : false, "v" : 1.477007437120739e+48 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbWSCalls\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:15:00Z") }, "i" : false, "v" : 1.3080113312327026e+43 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbWSCalls\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:25:00Z") }, "i" : false, "v" : 1.1400013121915602e+49 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbWSCalls\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:35:00Z") }, "i" : false, "v" : 7.101108120056911e+47 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbWSCalls\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:45:00Z") }, "i" : false, "v" : 8.1600722604836e+45 }

As you can see, the metric values look completely wild... they do start by the correct numbers ("1477" -> 1.47700.........e+48) but the exponent is just crazy.

I do have other metrics that provide a correct output... but I can't figure why this one outputs those values.

Does anyone have an idea about my issue ?

Thanks a lot,

Jc

Mike Bostock

unread,
Jul 5, 2013, 11:21:59 AM7/5/13
to cube...@googlegroups.com
The problem is that your values are strings (e.g., "1081") not numbers (1081), so the sum is actually concatenating the strings rather than performing addition. It would probably be better if Cube coerced values to numbers when adding, but it’s still a good idea to store the data in the correct type to begin with.

Mike

Jean-Charles Eloi

unread,
Jul 5, 2013, 11:56:29 AM7/5/13
to cube...@googlegroups.com
Thank you for your quick answer Mike.

Yet this behavior is not consistent, as those data do "work", for instance :

Events :

{ "t" : ISODate("2013-07-05T00:05:03Z"), "d" : { "key" : "P2_android_VSCM_NbCurSessions", "value" : "193" }, "_id" : ObjectId("51d6bf0a24b7ab480d000047") }
{ "t" : ISODate("2013-07-05T00:15:03Z"), "d" : { "key" : "P2_android_VSCM_NbCurSessions", "value" : "187" }, "_id" : ObjectId("51d6bf0a24b7ab480d0001a3") }
{ "t" : ISODate("2013-07-05T00:25:03Z"), "d" : { "key" : "P2_android_VSCM_NbCurSessions", "value" : "177" }, "_id" : ObjectId("51d6bf0a24b7ab480d000308") }
{ "t" : ISODate("2013-07-05T00:35:03Z"), "d" : { "key" : "P2_android_VSCM_NbCurSessions", "value" : "150" }, "_id" : ObjectId("51d6bf0a24b7ab480d0004bb") }
{ "t" : ISODate("2013-07-05T00:45:03Z"), "d" : { "key" : "P2_android_VSCM_NbCurSessions", "value" : "125" }, "_id" : ObjectId("51d6bf0a24b7ab480d00066e") }
{ "t" : ISODate("2013-07-05T00:55:03Z"), "d" : { "key" : "P2_android_VSCM_NbCurSessions", "value" : "108" }, "_id" : ObjectId("51d6bf0a24b7ab480d000821") }


Metrics :

{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbCurSessions\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:05:00Z") }, "i" : false, "v" : 193 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbCurSessions\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:15:00Z") }, "i" : false, "v" : 187 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbCurSessions\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:25:00Z") }, "i" : false, "v" : 177 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbCurSessions\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:35:00Z") }, "i" : false, "v" : 150 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbCurSessions\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:45:00Z") }, "i" : false, "v" : 125 }
{ "_id" : { "e" : "sum(whr_metrics_2(value).re(key,\"P2_android_VSCM_NbCurSessions\"))", "l" : 300000, "t" : ISODate("2013-07-05T00:55:00Z") }, "i" : false, "v" : 108 }

Do I miss something ?

Jean-Charles





On Fri, Jul 5, 2013 at 5:21 PM, Mike Bostock <mi...@ocks.org> wrote:
The problem is that your values are strings (e.g., "1081") not numbers (1081), so the sum is actually concatenating the strings rather than performing addition. It would probably be better if Cube coerced values to numbers when adding, but it’s still a good idea to store the data in the correct type to begin with.

Mike

--
You received this message because you are subscribed to the Google Groups "cube-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cube-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jean-Charles Eloi

unread,
Jul 5, 2013, 12:13:43 PM7/5/13
to cube...@googlegroups.com
Just to be precise on my previous email : Mike is true, and forcing a number while storing the data does solve the problem. I was now just wondering why the behavior a bit erratic.

Thanks again, Mike.

Mike Bostock

unread,
Jul 5, 2013, 12:22:58 PM7/5/13
to cube...@googlegroups.com
When metrics are saved, the value is coerced to a double (see metric.js):

  v: new Double(value)

The problem is the values are not coerced to a double before the sum is made. So, the sum happens as strings, and then the value is coerced to a double. In the case where only one event matches the metric query, it’s okay to coerce after summing. But if there’s more than one matching event, the values are concatenated rather than added.

Also, the fact a bug is not exhibited in certain circumstances is not usually a safe indication to ignore the bug. :)

Mike
Reply all
Reply to author
Forward
0 new messages