internal

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const AnyBranch = "/any"

Special tag value to use when no branch filter was applied. This was chosen because branch names are not allowed to start with / in git.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fetcher

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

Fetcher interacts with the CircleCI API to retrieve metric details about Workflows and Jobs.

func NewFetcher

func NewFetcher(logger *log.Logger, token string, enc *LineProtocolEncoder, opts ...FetcherOption) (*Fetcher, error)

NewFetcher returns an initialized Fetcher.

func (*Fetcher) Discover

func (f *Fetcher) Discover(slug ProjectSlug) error

Discover uses the CircleCI insights API to discover the workflows and jobs within a project. Typically, a caller will call RecordWorkflowJobMetrics after Discover.

func (*Fetcher) RecordWorkflowJobMetrics

func (f *Fetcher) RecordWorkflowJobMetrics(slug ProjectSlug) (ok bool)

RecordWorkflowJobMetrics retrieves run details for workflows and jobs in the given project. It returns true if there were no errors; otherwise, errors are logged and a best effort is made to continue.

type FetcherOption

type FetcherOption func(*Fetcher) error

FetcherOption modifies a Fetcher returned by NewFetcher.

func WithBranch

func WithBranch(branch string) FetcherOption

WithBranch sets which branch to specify when scraping. If not set, then will scrape metrics for all aggregated branches.

func WithHost

func WithHost(hostname string) FetcherOption

WithHost sets the host for the Fetcher. If not provided, defaults to https://circleci.com.

func WithLookback

func WithLookback(lookback time.Duration) FetcherOption

WithLookback sets the limit on how old of metrics to report.

type JobItem

type JobItem struct {
	ID              string `json:"id"`
	StartedAt       string `json:"started_at"` // Job: StartedAt; Workflow: CreatedAt.
	DurationSeconds int    `json:"duration"`
	Status          string `json:"status"`
	CreditsUsed     int    `json:"credits_used"`
}

JobItem is the metrics for a single job "item" in CircleCI's insights API.

func (JobItem) Fields

func (i JobItem) Fields() map[string]interface{}

Fields returns the line protocol fields corresponding to i.

type LineProtocolEncoder

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

LineProtocolEncoder formats domain-specific metrics to line protocol.

func NewLineProtocolEncoder

func NewLineProtocolEncoder(logger *log.Logger, out io.Writer) *LineProtocolEncoder

NewLineProtocolEncoder returns a new LineProtocolEncoder.

func (*LineProtocolEncoder) FetcherRequest

func (e *LineProtocolEncoder) FetcherRequest(d time.Duration, typ string, resp *http.Response)

FetcherRequest records internal metrics for an HTTP request that the Fetcher made.

func (*LineProtocolEncoder) JobItem

func (e *LineProtocolEncoder) JobItem(p WorkflowJobPath, i JobItem, oldestAllowed time.Time) error

JobItem encodes the given JobItem to line protocol.

func (*LineProtocolEncoder) WorkflowItem

func (e *LineProtocolEncoder) WorkflowItem(p WorkflowJobPath, i WorkflowItem, oldestAllowed time.Time) error

WorkflowItem encodes the given WorkflowItem to line protocol.

type ProjectSlug

type ProjectSlug struct {
	VCS, Owner, Repo string
}

ProjectSlug is the CircleCI representation of a project.

func ProjectSlugFromString

func ProjectSlugFromString(s string) (ProjectSlug, error)

ProjectSlugFromString parses a stringified project slug into a ProjectSlug. Valid formats are "vcs/owner/repo", and "owner/repo", the latter of which implies vcs of "github".

func (ProjectSlug) String

func (s ProjectSlug) String() string

String returns a stringified version of s.

type TooOldError

type TooOldError struct {
	Time time.Time
}

TooOldError is returned when iterating through a slice of WorkItems or JobItems and an item older than the Fetcher's Lookback is encountered.

func (TooOldError) Error

func (e TooOldError) Error() string

type WorkflowItem

type WorkflowItem struct {
	ID              string `json:"id"`
	CreatedAt       string `json:"created_at"` // Workflow: CreatedAt; Job: StartedAt.
	DurationSeconds int    `json:"duration"`
	Status          string `json:"status"`
	CreditsUsed     int    `json:"credits_used"`
}

WorkflowItem is the metrics for a single workflow "item" in CircleCI's insights API.

func (WorkflowItem) Fields

func (i WorkflowItem) Fields() map[string]interface{}

Fields returns the line protocol fields corresponding to i.

type WorkflowJobPath

type WorkflowJobPath struct {
	VCS   string
	Owner string
	Repo  string

	// Name of branch used in request.
	// If empty, will be recorded as special value "/all" which is an invalid git branch name.
	Branch string

	// Names of workflow and job.
	// Job is empty if this is just a Workflow path.
	Workflow string
	Job      string
}

WorkflowJobPath represents the canonical location of a Workflow or Job in CircleCI.

Jump to

Keyboard shortcuts

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