snltd / wavefront-sdk

A Ruby SDK for Wavefront

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alert class does not allow searching by name or tags

dimas opened this issue · comments

Hi, Rob.
Wavefront forces us to abandon their deprecated client as they breaking more and more server-side v1 support with every release they make so we are looking into converting all our code to your client library.

The first thing we ran into is inability to use Alert class for any search apart from status.
Namely we are lacking search by name and by tags.
Not a huge issue of course as we will just use Wavefront::Search.new(creds, opts).search(), just wanted show a potential improvement.

Another thing which really puzzles me is that Alert class passes PAGE_SIZE as an offset to API calls. A little bit strange as I would expect offset to be zero when you doing your initial query.

I am talking about these two places:
https://github.com/snltd/wavefront-sdk/blob/master/lib/wavefront-sdk/alert.rb#L277
and
https://github.com/snltd/wavefront-sdk/blob/master/lib/wavefront-sdk/alert.rb#L292

sorry if I misunderstood your code but from my experiments (specifically with the search) - the value I pass as offset actually works as an offset and it "hides" that number of entries from the response...

Cheers

Hey Dimitry.

The v1 API was EOL in, I think, 2017. I'm pretty surprised it still works at all!

For searching use, as you suggest, the Wavefront::Search class directly. The #alerts_in_state method is just a shim to simplify methods like #firing. I was going to make it a private method to avoid the confusion of it looking like an incomplete public interface, and probably should have done that. Best to keep the search code centralised in the Search class I think, rather than having it grow arms everywhere else.

The question about PAGE_SIZE is a good one. It is explained in the Pagination class, but not, I think well enough, so I've tried to improve it. Have a look at https://github.com/snltd/wavefront-sdk/blob/master/lib/wavefront-sdk/paginator/base.rb#L16-L30, but the gist is that you can ask for all objects in a search by supplying limit: :all in your options hash. When you do that, you can specify the number of objects requested in each API call by overriding the offset value. So fetching all objects ten at a time is done via limit: :all, offset: 10, but it will begin with the first object. I admit it's a little confusing, but I think it does make sense from a certain point of view. I hope so anyway!

Hey.
Yeah, I guess you still can not predict all the ways people will be searching for alerts so you probably cannot provide enough public methods in the alerting class anyway - whatever you do there will always be someone needing slightly different search. I am perfectly happy with the Search class.

Re the offset things - yes, once explained it makes perfect sense. But I bet I won't be the only one confused there. If it was called page_size or something it would not raise any question.
Anyway, my fault - should have read docs and code first :)

Cheers

I agree, the repurposing of offset is confusing, but the page size and the offset are tangled up together to the point of pretty much being the same thing.

I've tried to improved the rdoc and README, but you're right, it'll likely catch someone else out in the future.

Thanks for the report. Glad you're happy with the result.