liquidm / ruby-druid

Ruby utilities for metamx druid
MIT License
43 stars 34 forks source link

Added topN query (new topn method in query class that accepts the dimens... #17

Closed nebrera closed 10 years ago

nebrera commented 10 years ago

...ion, the metric and the threshold to use)

ryanza commented 10 years ago

Hi Carlos,

Could you please provide tests for this? :)

itszootime commented 10 years ago

please add to the console delegators too: https://github.com/liquidm/ruby-druid/blob/master/lib/druid/console.rb#L70

carlosrdrz commented 10 years ago

Hi ryanza! I just uploaded a test to check the topn method. Let me know if you need something more! :)

ryanza commented 10 years ago

Cool thanks!

carlosrdrz commented 10 years ago

No problem!

But I must mention that druid response's to topn query is a bit particular. It returns a array with just one element, which contains the timestamp and the result (another array with the actual values).

An example:

[
   {
      "timestamp": "2014-01-13T11:26:00.000Z",
      "result":[
         {
            "events": 48315,
            "msg": "top1msg"
         },
         {
            "events": 22344,
            "msg": "top2msg"
         },
         {
            "events":17202,
            "msg": "top3msg"
         },
         {
            "events":13223,
            "msg": "top4msg"
         },
         {
            "events":11685,
            "msg": "top5msg"
         }
      ]
   }
]

That provokes a crash on the console (bin/dripl), right here https://github.com/liquidm/ruby-druid/blob/master/lib/druid/console.rb#L14, when you try to do a topn query with the method I provided, since "result.last", in that context, is an Array and not a Hash

Sorry about that, I never used the console you provide so I think I wont be very useful with that. I hope you guys could think something about that.

Let me know if I can help you!

ryanza commented 10 years ago

Ive pushed out a new version with your code - might need to look into fixing the repl now. :)

https://github.com/liquidm/ruby-druid/releases/tag/v0.1.4