common

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

PagerDuty Agent: Common Package

Common utilities used across agent packages.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BaseLogger *zap.Logger
View Source
var Commit = "unavailable"

Normally set at build time.

View Source
var Date = time.Now().Format(time.RFC3339)
View Source
var ErrPidfileDoesntExist = errors.New("pidfile doesn't exist")
View Source
var ErrPidfileExists = errors.New("pidfile already exists")
View Source
var Version = "unavailable"

Functions

func GenerateKey

func GenerateKey() string

GenerateKey generates a random lowercase alphanumeric key.

These keys approximate the Events API's routing keys for use in testing, but may be useful more generally.

func GetPid

func GetPid(pidfile string) (int, error)

func InitPidfile

func InitPidfile(pidfile string) error

func IsProduction

func IsProduction() bool

func IsRunning

func IsRunning(pidfile string) (bool, error)

func IsSuccessResponse added in v0.3.0

func IsSuccessResponse(resp *http.Response, err error) bool

IsSuccessResponse returns true if the corresponding request was successful.

Per documentation this is when the server responds with a 202, but we treat any 2XX as a success.

func PdApiUrl added in v0.4.0

func PdApiUrl() string

func PdEventsUrl added in v0.4.0

func PdEventsUrl() string

func RemovePidfile

func RemovePidfile(pidfile string) error

func TerminateProcess

func TerminateProcess(pidfile string) error

func UserAgent added in v0.3.0

func UserAgent() string

Types

type Clock added in v0.5.1

type Clock interface {
	Now() time.Time
}

func NewClock added in v0.5.1

func NewClock() Clock

type RetryTransport added in v0.3.0

type RetryTransport struct {
	MaxRetries  int
	MaxInterval time.Duration
	Transport   http.RoundTripper
	Backoff     func(int, time.Duration) time.Duration
	IsRetryable func(*http.Response, error) bool
	IsSuccess   func(*http.Response, error) bool
	// contains filtered or unexported fields
}

RetryTransport provides automatic retry support as an `http.RoundTripper`.

Default cases are when a 429 or 500-series error is encountered, with an exponential backoff determined by `Backoff` and a maximum retry count of `MaxRetries`.

Example basic usage:

    client :=  &http.Client{
		   Transport: NewRetryTransport(),
	   }

    client.Get("https://www.pagerduty.com")

func NewRetryTransport added in v0.3.0

func NewRetryTransport() RetryTransport

func (RetryTransport) RoundTrip added in v0.3.0

func (r RetryTransport) RoundTrip(req *http.Request) (*http.Response, error)

Implementing the `http.RoundTripper` interface.

Jump to

Keyboard shortcuts

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