sleuth

package
v1.81.4 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sleuth is a basic client for the official Sleuth.io API to register deployments, manual changes, custom incident impact, and custom metric impact.

Ref.: https://help.sleuth.io/sleuth-api

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents the config options required by this client.

func New

func New(addr, org, apiKey string, opts ...Option) (*Client, error)

New creates a new client instance. Example for addr: "https://app.sleuth.io/api/1"

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck performs a status check on this service. Note: sleuth.io API currently does not provide a ping endpoint, so we check if we are getting the right error using the correct API Key and inexistent deployment ID.

func (*Client) SendCustomIncidentImpactRegistration

func (c *Client) SendCustomIncidentImpactRegistration(ctx context.Context, request *CustomIncidentImpactRegistrationRequest) error

SendCustomIncidentImpactRegistration register Custom Incident Impact values. Allows to submit custom incident impact values to Sleuth to get Failure Rate and MTTR values.

func (*Client) SendCustomMetricImpactRegistration

func (c *Client) SendCustomMetricImpactRegistration(ctx context.Context, request *CustomMetricImpactRegistrationRequest) error

SendCustomMetricImpactRegistration register Custom Metric Impact values. Allows to submit custom metric impact values to Sleuth. Sleuth will perform anomaly detection on these values and they will inform the health of the deployments.

func (*Client) SendDeployRegistration

func (c *Client) SendDeployRegistration(ctx context.Context, request *DeployRegistrationRequest) error

SendDeployRegistration register a deployment with Sleuth.

func (*Client) SendManualChange

func (c *Client) SendManualChange(ctx context.Context, request *ManualChangeRequest) error

SendManualChange register a manual change with Sleuth. Manual changes are any changes not tracked by source code, feature flags, or any other type of change not supported by Sleuth.

type CustomIncidentImpactRegistrationRequest

type CustomIncidentImpactRegistrationRequest struct {
	// Project is the Sleuth project ID as found in the Sleuth URL, following the prefix https://app.sleuth.io/org_slug/.
	Project string `json:"-" validate:"required,max=50"`

	// Environment is the environment to register the deploy against.
	// Found at the end of the URL of the Sleuth org when navigating to the target project
	// and selecting the target custom incident impact source: env_slug=ENVIRONMENT_SLUG.
	Environment string `json:"-" validate:"required,max=50"`

	// ImpactSource is found in the URL of the Sleuth org when navigating to the target project
	// and selecting the target custom incident impact source, just before the ?env_slug.
	ImpactSource string `json:"-" validate:"required,max=50"`

	// Type Valid types are triggered, resolved, and reopened.
	Type IncidentType `json:"type" validate:"required,oneof=triggered resolved reopened"`

	// ID is the unique (custom) incident identifier.
	ID string `json:"id" validate:"omitempty,max=50"`

	// Date is the ISO 8601 date and time string when the event occurred.
	// Defaults to the current time.
	Date string `json:"date,omitempty" validate:"omitempty,datetime=2006-01-02 15:04:05"`

	// EndedDate is the ISO 8601 date and time string when the event ended.
	// Use it with "type": "triggered" to register past incident event.
	EndedDate string `json:"ended_date,omitempty" validate:"omitempty,datetime=2006-01-02 15:04:05"`

	// Title is the human-readable title of the incident.
	Title string `json:"title,omitempty" validate:"omitempty,max=255"`

	// URL to the incident in the external system.
	URL string `json:"url,omitempty" validate:"omitempty,url"`
}

CustomIncidentImpactRegistrationRequest defines the request for Custom Incident Impact Registration.

type CustomMetricImpactRegistrationRequest

type CustomMetricImpactRegistrationRequest struct {
	// ImpactID is the integer ID that can be found bny navigating in the Custom Metric Impact Source,
	// clicking the gearwheel icon in the top-right corner, and selecting "Show register details".
	ImpactID int `json:"-" validate:"required"`

	// Value is the metric value to be registered.
	Value float64 `json:"value" validate:"required"`

	// Date is the ISO 8601 date and time string at which the metric value should be registered.
	// Defaults to the current time.
	Date string `json:"date,omitempty" validate:"omitempty,datetime=2006-01-02 15:04:05"`
}

CustomMetricImpactRegistrationRequest defines the request for Custom Metric Impact Registration.

type DeployRegistrationRequest

type DeployRegistrationRequest struct {
	// Deployment is the Sleuth deploymnet ID as found in the Sleuth URL, following the prefix https://app.sleuth.io/org_slug/deployments/.
	Deployment string `json:"-" validate:"required,max=50"`

	// Sha is the Git SHA of the commit to be registered as a deploy.
	Sha string `json:"sha" validate:"required,max=40"`

	// Environment is the environment to register the deploy against.
	// If not provided Sleuth will use the default environment of the Project.
	Environment string `json:"environment,omitempty" validate:"omitempty,max=50"`

	// Date is the ISO 8601 deployment date and time string.
	Date string `json:"date,omitempty" validate:"omitempty,datetime=2006-01-02 15:04:05"`

	// Tags is a comma-delimited list of tags.
	// Default to tags calculated by matching paths defined in the .sleuth/TAGS file.
	Tags []string `json:"tags,omitempty" validate:"omitempty,max=50,dive,max=50,startswith=#"`

	// IgnoreIfDuplicate ignores duplicate SHA and do not return an error.
	IgnoreIfDuplicate bool `json:"ignore_if_duplicate,omitempty" validate:"omitempty"`

	// Email is the email address of the author.
	Email string `json:"email,omitempty" validate:"omitempty,email"`

	// Links contains key/value pair consisting of the link name and the link itself.
	Links map[string]string `json:"links,omitempty" validate:"omitempty,max=50,dive,url"`
}

DeployRegistrationRequest defines the request for Deploy Registration.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient contains the function to perform the actual HTTP request.

type IncidentType

type IncidentType string

IncidentType defines the valid values for an Incident Type.

const (
	// Triggered indicates a new incident.
	Triggered IncidentType = "triggered"

	// Resolved indicates the incident has been resolved.
	Resolved IncidentType = "resolved"

	// Reopened indicated the incident has been reopened.
	Reopened IncidentType = "reopened"
)

type ManualChangeRequest

type ManualChangeRequest struct {
	// Project is the Sleuth project ID as found in the Sleuth URL, following the prefix https://app.sleuth.io/org_slug/.
	Project string `json:"-" validate:"required,max=50"`

	// Name is the title for the manual change.
	Name string `json:"name" validate:"required,max=255"`

	// Description for manual changes. Omit if using SHA instead.
	Description string `json:"description,omitempty" validate:"omitempty,max=65535"`

	// Environment is the environment to register the deploy against.
	// If not provided Sleuth will use the default environment of the Project.
	Environment string `json:"environment,omitempty" validate:"omitempty,max=50"`

	// Tags is a comma-delimited list of tags.
	// Default to tags calculated by matching paths defined in the .sleuth/TAGS file.
	Tags []string `json:"tags,omitempty" validate:"omitempty,max=50,dive,max=50,startswith=#"`

	// Author is the email address of the change author.
	Author string `json:",omitempty" validate:"omitempty,email"`

	// Email is the email address of the user associated with the project receiving the manual change.
	Email string `json:"email,omitempty" validate:"omitempty,email"`
}

ManualChangeRequest defines the request for Manual Change.

type Option

type Option func(c *Client)

Option is the interface that allows to set client options.

func WithHTTPClient

func WithHTTPClient(hc HTTPClient) Option

WithHTTPClient overrides the default HTTP client.

func WithPingTimeout

func WithPingTimeout(timeout time.Duration) Option

WithPingTimeout overrides the default ping timeout.

func WithRetryAttempts

func WithRetryAttempts(attempts uint) Option

WithRetryAttempts overrides the default HTTP client.

func WithRetryDelay

func WithRetryDelay(value time.Duration) Option

WithRetryDelay sets the delay to apply after the first failed attempt.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout overrides the default request timeout.

Jump to

Keyboard shortcuts

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