Documentation ¶
Index ¶
- Variables
- func AddNextPageQueryParams(u *url.URL, nextPage string) *url.URL
- type AddEntriesToResult
- type Client
- func (c Client) Client() *http.Client
- func (c Client) Delete(ctx context.Context, url string) (Response, error)
- func (c Client) Get(ctx context.Context, url string) (Response, error)
- func (c Client) GetWithRetry(ctx context.Context, url string, settings RetrySetting) (resp Response, err error)
- func (c Client) Post(ctx context.Context, url string, data []byte) (Response, error)
- func (c Client) PostMultiPartFile(ctx context.Context, url string, data *bytes.Buffer, contentType string) (Response, error)
- func (c Client) Put(ctx context.Context, url string, data []byte) (Response, error)
- type RateLimitStrategy
- type RequestInfo
- type RespError
- type Response
- func ListPaginated(ctx context.Context, client *Client, retrySettings RetrySettings, url *url.URL, ...) (Response, error)
- func SendWithRetry(ctx context.Context, sendWithBody SendRequestWithBody, path string, ...) (resp Response, err error)
- func SendWithRetryWithInitialTry(ctx context.Context, sendWithBody SendRequestWithBody, path string, ...) (resp Response, err error)
- type RetrySetting
- type RetrySettings
- type SendRequestWithBody
Constants ¶
This section is empty.
Variables ¶
var DefaultRetrySettings = RetrySettings{ Normal: RetrySetting{ WaitTime: time.Second, MaxRetries: 15, }, Long: RetrySetting{ WaitTime: time.Second, MaxRetries: 30, }, VeryLong: RetrySetting{ WaitTime: time.Second, MaxRetries: 60, }, }
Functions ¶
func AddNextPageQueryParams ¶
AddNextPageQueryParams handles both Dynatrace v1 and v2 pagination logic. For api/v2 URLs the given next page key will be the only query parameter of the modified URL For any other ULRs the given next page key will be added to existing query parameters
Types ¶
type AddEntriesToResult ¶
AddEntriesToResult is a function which should parse an API response body and append the returned entries to a result slice. Handling the parsing, any possible filtering and owning and filling the result list is left to the caller of ListPaginated, as it might differ notably between client implementations. The function MUST return the number of entries it has parsed from the received API payload body. This is used to validate that the final parsed number matches the reported total count of the API. This receivedEntries count is not necessarily equal to the number of entries added to the result slice, as filtering might exclude some entries that where received from the API.
type Client ¶ added in v2.6.0
type Client struct {
// contains filtered or unexported fields
}
func NewRestClient ¶ added in v2.6.0
func NewRestClient(client *http.Client, trafficLogger *trafficlogs.FileBasedLogger, strategy RateLimitStrategy) *Client
func (Client) GetWithRetry ¶ added in v2.6.0
func (Client) PostMultiPartFile ¶ added in v2.6.0
type RateLimitStrategy ¶ added in v2.6.0
type RateLimitStrategy interface {
ExecuteRequest(timelineProvider timeutils.TimelineProvider, callback func() (Response, error)) (Response, error)
}
RateLimitStrategy ensures that the concrete implementation of the rate limiting strategy can be hidden behind this interface
func CreateRateLimitStrategy ¶ added in v2.6.0
func CreateRateLimitStrategy() RateLimitStrategy
CreateRateLimitStrategy creates a RateLimitStrategy. In the future this can be extended to instantiate different rate limiting strategies based on e.g. environment variables. The current implementation always returns the strategy simpleSleepRateLimitStrategy, which suspends the current goroutine until the time in the rate limiting header 'X-RateLimit-Reset' is up.
type RequestInfo ¶
type RespError ¶
type RespError struct { // Reason describing what went wrong Reason string `json:"reason"` // StatusCode is the HTTP status code StatusCode int `json:"statusCode"` // Body of the HTTP response Body string `json:"body"` // Err is the underlying error that occurred - maybe be empty Err error `json:"error"` // Request contains information about the HTTP request that caused the RespError Request *RequestInfo `json:"request"` }
RespError represents a HTTP response error
func NewRespErr ¶
func (RespError) ConcurrentError ¶
func (RespError) WithRequestInfo ¶
type Response ¶
type Response struct { StatusCode int Body []byte Headers map[string][]string NextPageKey string TotalCount int PageSize int }
func ListPaginated ¶
func ListPaginated(ctx context.Context, client *Client, retrySettings RetrySettings, url *url.URL, logLabel string, addToResult AddEntriesToResult) (Response, error)
func SendWithRetry ¶
func SendWithRetry(ctx context.Context, sendWithBody SendRequestWithBody, path string, body []byte, setting RetrySetting) (resp Response, err error)
SendWithRetry will retry to call sendWithBody for a given number of times, waiting a give duration between calls
func SendWithRetryWithInitialTry ¶
func SendWithRetryWithInitialTry(ctx context.Context, sendWithBody SendRequestWithBody, path string, body []byte, setting RetrySetting) (resp Response, err error)
SendWithRetryWithInitialTry will try to call sendWithBody and if it didn't succeed call SendWithRetry
func (Response) Is4xxError ¶
func (Response) Is5xxError ¶
type RetrySetting ¶
type RetrySettings ¶
type RetrySettings struct { Normal RetrySetting Long RetrySetting VeryLong RetrySetting }