bugsnag / bugsnag-api-ruby

BugSnag API toolkit for Ruby
Other
21 stars 15 forks source link

No way to disable pagination #6

Closed aimee-ault closed 5 years ago

aimee-ault commented 9 years ago

I'm hoping this isn't actually a bug but just user error on my part, but reporting it either way to clarify (also sorry if I'm reporting this in the wrong place, but it seemed like it might be an API issue instead of with the gem, but I know you guys maintain the gem as well...)

So, using the ruby gem for the Bugsnag API, if I set up a client with auto_paginate set to false in the client config, it continues to return paginated results.

For example:

2.1.5 :125 > client = Bugsnag::Api::Client.new(auth_token: [my_token], auto_paginate: false)

 => #<Bugsnag::Api::Client:0x007fca91239868 @configuration=#<Bugsnag::Api::Configuration:0x007fca91239840 @endpoint="https://api.bugsnag.com", @user_agent="Bugsnag API Ruby Gem 1.0.3", @middleware=#
<Faraday::RackBuilder:0x007fca8a50c740 @handlers=[Bugsnag::Api::Response::RaiseError, Faraday::Adapter::NetHttp], @app=#<Bugsnag::Api::Response::RaiseError:0x007fca8a952b10 @app=#<Faraday::Adapter::NetHttp:0x007fca8a952b60 @app=#<Proc:0x007fca8a952c28@/Users/aimeeault/.rvm/gems/ruby-2.1.5@warehouse/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:152 (lambda)>>>>, @auto_paginate=false, @connection_options={:headers=>{:user_agent=>"Bugsnag API Ruby Gem 1.0.3"}}, @auth_token=[removed]>> 

I then use the client to fetch errors and events counts on the last project on my account:

2.1.5 :126 > client.errors(client.projects.last.id).count
 => 30 
2.1.5 :126 > client.events(client.projects.last.id).count
 => 30 

30 being the default pagination in the API. However, if I take a look at client.projects.last, I can see that it has an errors count of 2719, much higher than 30. Overriding the paginated count in the options sent with the request seems to cap the set to 100 results (which also seems to be the client's default).

Also: To provide better context for what I'm trying to do: I just want to get daily counts of events--I excluded the start_date, end_date arguments from above just to clarify the issue but in actual use, I'm including those... so it seems wasteful to need to pull so much event data and also kind of weird that I'd have to iterate over multiple requests just to get accurate counts. I've gone through the API docs a few times but it seems like this is the only way to get that information?

snmaynard commented 9 years ago

Hey,

To get daily counts of events I think you'll have to do

count = 0
events = client.events(client.projects.last.id)
count += events.count
last_response = client.last_response
until last_response.rels[:next].nil?
  last_response = last_response.rels[:next].get
  count += last_response.data.count
end

and include the timestamps you want to restrict to. Apologies that this isn't super easy at the moment. As part of a new dashboard we want to release soon there will be an api available to get arbitrary counts between two dates relatively easily!

robmorgan commented 7 years ago

hey @snmaynard , I just stumbled across this issue. Did you ever release any updates to the API to make getting event counts easier? Would be super handy for error rate % calculations.

snmaynard commented 5 years ago

Apologies I didnt get back to this issue, missed the github notifications. For future reference you can now do this with the trends API -> https://bugsnagapiv2.docs.apiary.io/#reference/errors/trends/list-the-trends-for-a-project-(buckets)