Documentation
¶
Index ¶
- Constants
- type Client
- func (c *Client) Do(request *http.Request, responseTarget any) error
- func (c *Client) ListActiveMetrics(ctx context.Context, from time.Time) ([]string, error)
- func (c *Client) NewRequest(ctx context.Context, method, path string, body any) (*http.Request, error)
- func (c *Client) Query(ctx context.Context, queries []string, from, to time.Time) ([][]Point, error)
- type Point
Constants ¶
const ( // MaxRetries is how many times Do retries a request that Datadog rate limits. MaxRetries = 5 // DefaultRetryWait is used when a 429 carries no X-RateLimit-Reset header. DefaultRetryWait = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles communication with the Datadog REST API
func NewClient ¶
NewClient creates new Datadog API client for baseURL, the API host of the caller's Datadog site, e.g. https://api.datadoghq.com, with an API key and an application key. Accepts custom *http.Client, uses a copy of DefaultClient if nil. The client is copied, and the copy does not follow redirects: Go sends custom headers such as DD-API-KEY on to the redirect target, even on another host, and the Datadog API does not redirect. A redirect comes back as an error instead.
func (*Client) Do ¶
Do executes an API request and unmarshals the response body into responseTarget. A 429 is retried up to MaxRetries times, after the X-RateLimit-Reset seconds. A request the http.Client times out returns an error that wraps errors.ErrTimeout and leaves out the URL, which can carry a long query.
func (*Client) ListActiveMetrics ¶
ListActiveMetrics lists the metrics that reported since from.
func (*Client) NewRequest ¶
func (c *Client) NewRequest(ctx context.Context, method, path string, body any) (*http.Request, error)
NewRequest creates an API request A relative path can be provided, e.g. "/api/v1/query?from=..."
func (*Client) Query ¶
func (c *Client) Query(ctx context.Context, queries []string, from, to time.Time) ([][]Point, error)
Query runs the queries as one /api/v1/query call, so a batch costs one request against the metrics rate limit. The result has the points of each query, in order. A query with no data in the window gets none, and the null points Datadog pads a batch onto one time grid with are dropped.