clientutil

package
v0.99.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package clientutil contains the Datadog API client util functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// JSONHeaders headers for JSON requests.
	JSONHeaders = map[string]string{
		"Content-Type":     "application/json",
		"Content-Encoding": "gzip",
	}
	// ProtobufHeaders headers for protobuf requests.
	ProtobufHeaders = map[string]string{
		"Content-Type":     "application/x-protobuf",
		"Content-Encoding": "identity",
	}
)
View Source
var ErrInvalidAPI = errors.New("API Key validation failed")
View Source
var GZipSubmitMetricsOptionalParameters = datadogV2.NewSubmitMetricsOptionalParameters().WithContentEncoding(datadogV2.METRICCONTENTENCODING_GZIP)

GZipSubmitMetricsOptionalParameters is used to enable gzip compression for metric payloads submitted by native datadog client

Functions

func CreateAPIClient added in v0.69.0

func CreateAPIClient(buildInfo component.BuildInfo, endpoint string, hcs confighttp.ClientConfig) *datadog.APIClient

CreateAPIClient creates a new Datadog API client

func CreateZorkianClient added in v0.67.0

func CreateZorkianClient(apiKey string, endpoint string) *zorkian.Client

CreateZorkianClient creates a new Zorkian Datadog client Deprecated: CreateZorkianClient returns a Zorkian Datadog client and Zorkian is deprecated. Use CreateAPIClient instead.

func GetRequestContext added in v0.69.0

func GetRequestContext(ctx context.Context, apiKey string) context.Context

GetRequestContext creates a new context with API key for DatadogV2 requests

func NewHTTPClient

func NewHTTPClient(hcs confighttp.ClientConfig) *http.Client

NewHTTPClient returns a http.Client configured with a subset of the confighttp.ClientConfig options.

func SetDDHeaders

func SetDDHeaders(reqHeader http.Header, buildInfo component.BuildInfo, apiKey string)

SetDDHeaders sets the Datadog-specific headers

func SetExtraHeaders

func SetExtraHeaders(h http.Header, extras map[string]string)

SetExtraHeaders appends a header map to HTTP headers.

func UserAgent

func UserAgent(buildInfo component.BuildInfo) string

func ValidateAPIKey

func ValidateAPIKey(ctx context.Context, apiKey string, logger *zap.Logger, apiClient *datadog.APIClient) error

ValidateAPIKey checks if the API key (not the APP key) is valid

func ValidateAPIKeyZorkian added in v0.67.0

func ValidateAPIKeyZorkian(logger *zap.Logger, client *zorkian.Client) error

ValidateAPIKeyZorkian checks that the provided client was given a correct API key. Deprecated: ValidateAPIKeyZorkian uses the deprecated Zorkian client. Use ValidateAPIKey instead.

func WrapError added in v0.70.0

func WrapError(err error, resp *http.Response) error

WrapError wraps an error to a permanent consumer error that won't be retried if the http response code is non-retriable.

Types

type Retrier

type Retrier struct {
	// contains filtered or unexported fields
}

func NewRetrier

func NewRetrier(logger *zap.Logger, settings configretry.BackOffConfig, scrubber scrub.Scrubber) *Retrier

func (*Retrier) DoWithRetries

func (r *Retrier) DoWithRetries(ctx context.Context, fn func(context.Context) error) (int64, error)

DoWithRetries does a function with retries. This is a condensed version of the code on the exporterhelper, which we reuse here since we want custom retry logic.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL