zorkian / go-datadog-api

A Go implementation of the Datadog API.
BSD 3-Clause "New" or "Revised" License
183 stars 156 forks source link

Add methods to retrieve logs from logs-queries/list API endpoint #292

Closed sendqueery closed 4 years ago

sendqueery commented 4 years ago

The datadog web interface only allows a user to export up to 5k log lines at a time. Sometimes, you just need more than that. This PR adds functionality that allows a user to hit the logs-queries/list API and retrieve any number of logs, along with the corresponding tags and attributes for each.

As this particular API only returns up to 1000 lines at a time, GetLogsListPages() handles the pagination and can retrieve all results.

This has appropriate tests and mock JSON response data, and has been successfully tested for use in a small scraper tool I'm writing for internal use at work.

sendqueery commented 4 years ago

Whoops, I should probably link to the API doc: https://docs.datadoghq.com/api/?lang=bash#get-a-list-of-logs

irabinovitch commented 4 years ago

@sendqueery Thank you for the PR. We have a few folks at Datadog reviewing.

sendqueery commented 4 years ago

@bkabrda I also changed the naming of QueryTime and Attributes to keep things consistent.