appoptics

package module
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: Apache-2.0 Imports: 22 Imported by: 4

README

appoptics-api-go

The official Go client for the AppOptics metrics API.

Documentation Build Status Go Report Card

See Also

AppOptics also provides a Go APM instrumentation library for distributed tracing.

Questions/Comments?

Please open an issue, we'd love to hear from you.

Acknowledgements

This library's client design was partially inspired by the Librato Go client from @henrickhodne.

Documentation

Index

Constants

View Source
const (
	// MeasurementPostMaxBatchSize defines the max number of Measurements to send to the API at once
	MeasurementPostMaxBatchSize = 1000
	// DefaultPersistenceErrorLimit sets the number of errors that will be allowed before persistence shuts down
	DefaultPersistenceErrorLimit = 5
)
View Source
const (
	// AggregationKey is the key in the Measurement attributes used to tell the AppOptics system to aggregate values
	AggregationKey = "aggregate"
)
View Source
const MetricTagSeparator = "\x00"

MetricTagSeparator is used by MetricWithTags as a separator when serializing the metric name and tags as a key for aggregation with measurements matching the same metric name and tags.

Users can build these strings internally if desired, using a format like below, substituting MetricTagSeparator for the "|" pipes: - "metric_name" - "metric_name|tag_1_key|tag_1_value" - "metric_name|tag_1_key|tag_1_value|tag_2_key|tag_2_value" ...

Variables

View Source
var (
	DefaultSink = NewMeasurementSet()
)

DefaultSink is a convenience instance of MeasurementSet that can be used to centrally aggregate measurements for an entire process.

View Source
var (

	// ErrBadStatus is returned if the AppOptics API returns a non-200 error code.
	ErrBadStatus = errors.New("Received non-OK status from AppOptics POST")
)

Functions

func ContextWithMeasurementSet

func ContextWithMeasurementSet(ctx context.Context) context.Context

ContextWithMeasurementSet wraps the specified context with a MeasurementSet. XXX TODO: add convenience methods to read that MeasurementSet and manipulate Counters/Aggregators on it.

func MetricWithTags

func MetricWithTags(name string, tags map[string]interface{}) string

func RecordRuntimeMetrics

func RecordRuntimeMetrics(m *MeasurementSet)

Types

type Aggregator

type Aggregator struct {
	Count int64
	Sum   float64
	Min   float64
	Max   float64
	Last  float64
}

An Aggregator uses the "summary fields" measurement feature in AppOptics to aggregate multiple values into a single measurement, storing a count/sum/min/max/last that can be periodically sent as a single aggregate measurement. It can be either updated by passing sequential values to UpdateValue or by passing an Aggregator to Update, e.g. s.Update(Aggregator{Sum:100,Count:10,Min:5,Max:15})

func (*Aggregator) Update

func (g *Aggregator) Update(other Aggregator)

Update merges another Aggregator into this Aggregator, merging sum/count/min/max/last accordingly. It can be used to facilitate efficient input of many data points into an Aggregator in one call, and it can also be used to merge two different Aggregators (for example, workers can each maintain their own and periodically merge them).

func (*Aggregator) UpdateValue

func (g *Aggregator) UpdateValue(val float64)

UpdateValue sets the most recently observed value for this Aggregator, updating sum/count/min/max/last accordingly.

type Alert

type Alert struct {
	ID           int                    `json:"id,omitempty"`
	Name         string                 `json:"name,omitempty"`
	Description  string                 `json:"description,omitempty"`
	Active       *bool                  `json:"active,omitempty"`
	RearmSeconds int                    `json:"rearm_seconds,omitempty"`
	Conditions   []*AlertCondition      `json:"conditions,omitempty"`
	Attributes   map[string]interface{} `json:"attributes,omitempty"`
	Services     []*Service             `json:"services,omitempty"`
	CreatedAt    int                    `json:"created_at,omitempty"`
	UpdatedAt    int                    `json:"updated_at,omitempty"`
}

Alert defines a policy for sending alarms to services when conditions are met

type AlertCondition

type AlertCondition struct {
	ID              int     `json:"id,omitempty"`
	Type            string  `json:"type,omitempty"`
	MetricName      string  `json:"metric_name,omitempty"`
	Threshold       float64 `json:"threshold"`
	SummaryFunction string  `json:"summary_function,omitempty"`
	Duration        int     `json:"duration,omitempty"`
	DetectReset     bool    `json:"detect_reset,omitempty"`
	Tags            []*Tag  `json:"tags,omitempty"`
}

type AlertRequest

type AlertRequest struct {
	ID           int                    `json:"id,omitempty"`
	Name         string                 `json:"name,omitempty"`
	Description  string                 `json:"description,omitempty"`
	Active       *bool                  `json:"active,omitempty"`
	RearmSeconds int                    `json:"rearm_seconds,omitempty"`
	Conditions   []*AlertCondition      `json:"conditions,omitempty"`
	Attributes   map[string]interface{} `json:"attributes,omitempty"`
	Services     []int                  `json:"services,omitempty"` // correspond to IDs of Service objects
	CreatedAt    int                    `json:"created_at,omitempty"`
	UpdatedAt    int                    `json:"updated_at,omitempty"`
}

AlertRequest is identical to Alert except for the fact that Services is a []int in AlertRequest

type AlertStatus

type AlertStatus struct {
	Alert  Alert  `json:"alert,omitempty"`
	Status string `json:"status,omitempty"`
}

type AlertsCommunicator

type AlertsCommunicator interface {
	List() (*AlertsListResponse, error)
	Retrieve(int) (*Alert, error)
	Create(*AlertRequest) (*Alert, error)
	Update(*AlertRequest) error
	AssociateToService(int, int) error
	DisassociateFromService(alertId, serviceId int) error
	Delete(int) error
	Status(int) (*AlertStatus, error)
}

type AlertsListResponse

type AlertsListResponse struct {
	Query  QueryInfo `json:"query,omitempty"`
	Alerts []*Alert  `json:"alerts,omitempty"`
}

type AlertsService

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

func NewAlertsService

func NewAlertsService(c *Client) *AlertsService

func (*AlertsService) AssociateToService

func (as *AlertsService) AssociateToService(alertId, serviceId int) error

AssociateToService updates the Alert to allow assign it to the Service identified

func (*AlertsService) Create

func (as *AlertsService) Create(a *AlertRequest) (*Alert, error)

Create creates the Alert

func (*AlertsService) Delete

func (as *AlertsService) Delete(id int) error

Delete deletes the Alert

func (*AlertsService) DisassociateFromService

func (as *AlertsService) DisassociateFromService(alertId, serviceId int) error

DisassociateFromService updates the Alert to remove the Service identified

func (*AlertsService) List

func (as *AlertsService) List() (*AlertsListResponse, error)

List retrieves all Alerts

func (*AlertsService) Retrieve

func (as *AlertsService) Retrieve(id int) (*Alert, error)

Retrieve returns the Alert identified by the parameter

func (*AlertsService) Status

func (as *AlertsService) Status(id int) (*AlertStatus, error)

Status returns the Alert's status

func (*AlertsService) Update

func (as *AlertsService) Update(a *AlertRequest) error

Update updates the Alert

type AnnotationEvent

type AnnotationEvent struct {
	ID          int              `json:"id"`
	Title       string           `json:"title"`
	Source      string           `json:"source,omitempty"`
	Description string           `json:"description,omitempty"`
	Links       []AnnotationLink `json:"links,omitempty"`
	StartTime   int64            `json:"start_time,omitempty"`
	EndTime     int64            `json:"end_time,omitempty"`
}

AnnotationEvent is the main data structure for the Annotations API

type AnnotationLink struct {
	Rel   string `json:"rel"`
	Href  string `json:"href"`
	Label string `json:"label,omitempty"`
}

AnnotationLink represents the Link metadata for on the AnnotationEvent

type AnnotationStream

type AnnotationStream struct {
	Name        string                         `json:"name"`
	DisplayName string                         `json:"display_name,omitempty"`
	Events      []map[string][]AnnotationEvent `json:"events,omitempty"` // keys are Source names
}

AnnotationStream is a group of AnnotationEvents with a common name, representing a timeseries of occurrences of similar events

type AnnotationsCommunicator

type AnnotationsCommunicator interface {
	List(*string) (*ListAnnotationsResponse, error)
	Retrieve(*RetrieveAnnotationsRequest) (*AnnotationStream, error)
	RetrieveEvent(string, int) (*AnnotationEvent, error)
	Create(*AnnotationEvent, string) (*AnnotationEvent, error)
	UpdateStream(string, string) error
	UpdateEvent(string, int, *AnnotationLink) (*AnnotationLink, error)
	Delete(string) error
}

AnnotationsCommunicator provides an interface to the Annotations API from AppOptics

type AnnotationsService

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

func NewAnnotationsService

func NewAnnotationsService(c *Client) *AnnotationsService

func (*AnnotationsService) Create

func (as *AnnotationsService) Create(event *AnnotationEvent, streamName string) (*AnnotationEvent, error)

Create makes an AnnotationEvent on the stream with the given name

func (*AnnotationsService) Delete

func (as *AnnotationsService) Delete(streamName string) error

Delete deletes the annotation stream matching the provided name

func (*AnnotationsService) List

func (as *AnnotationsService) List(streamNameSearch *string) (*ListAnnotationsResponse, error)

List retrieves paginated AnnotationEvents for all streams with name LIKE argument string

func (*AnnotationsService) Retrieve

Retrieve fetches all AnnotationEvents matching the provided sources

func (*AnnotationsService) RetrieveEvent

func (as *AnnotationsService) RetrieveEvent(streamName string, id int) (*AnnotationEvent, error)

RetrieveEvent returns a single event identified by an integer ID from a given stream

func (*AnnotationsService) UpdateEvent

func (as *AnnotationsService) UpdateEvent(streamName string, id int, link *AnnotationLink) (*AnnotationLink, error)

UpdateEvent adds a link to an annotation Event

func (*AnnotationsService) UpdateStream

func (as *AnnotationsService) UpdateStream(streamName, displayName string) error

UpdateStream updates the display name of the stream

type ApiToken

type ApiToken struct {
	ID     *int    `json:"id,omitempty"`
	Active *bool   `json:"active,omitempty"`
	Name   *string `json:"name,omitempty"`
	Role   *string `json:"role,omitempty"`
	Token  *string `json:"token,omitempty"`
}

type ApiTokensCommunicator

type ApiTokensCommunicator interface {
	List() (*ApiTokensResponse, error)
	Retrieve(string) (*ApiTokensResponse, error)
	Create(*ApiToken) (*ApiToken, error)
	Update(*ApiToken) (*ApiToken, error)
	Delete(int) error
}

type ApiTokensResponse

type ApiTokensResponse struct {
	Query     QueryInfo   `json:"query,omitempty"`
	ApiTokens []*ApiToken `json:"api_tokens,omitempty"`
}

type ApiTokensService

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

func NewApiTokensService

func NewApiTokensService(c *Client) *ApiTokensService

func (*ApiTokensService) Create

func (ts *ApiTokensService) Create(at *ApiToken) (*ApiToken, error)

Create creates the ApiToken

func (*ApiTokensService) Delete

func (ts *ApiTokensService) Delete(id int) error

Delete deletes the ApiToken

func (*ApiTokensService) List

func (ts *ApiTokensService) List() (*ApiTokensResponse, error)

List retrieves all ApiTokens

func (*ApiTokensService) Retrieve

func (ts *ApiTokensService) Retrieve(name string) (*ApiTokensResponse, error)

Retrieve returns the ApiToken identified by the parameter

func (*ApiTokensService) Update

func (ts *ApiTokensService) Update(at *ApiToken) (*ApiToken, error)

Update updates the ApiToken

type BatchPersister

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

BatchPersister implements persistence to AppOptics and enforces error limits

func NewBatchPersister

func NewBatchPersister(mc MeasurementsCommunicator, sendStats bool) *BatchPersister

NewBatchPersister sets up a new instance of batched persistence capabilities using the provided MeasurementsCommunicator

func (*BatchPersister) BatchAndPersistMeasurementsForever

func (bp *BatchPersister) BatchAndPersistMeasurementsForever()

BatchAndPersistMeasurementsForever continually packages up Measurements from the channel returned by MeasurementSink() and persists them to AppOptics.

func (*BatchPersister) MaximumPushInterval

func (bp *BatchPersister) MaximumPushInterval() int

MaxiumumPushIntervalMilliseconds returns the number of milliseconds the system will wait before pushing any accumulated Measurements to AppOptics

func (*BatchPersister) MeasurementsErrorChannel

func (bp *BatchPersister) MeasurementsErrorChannel() chan<- error

MeasurementsErrorChannel gives calling code write-only access to the Measurements error channel

func (*BatchPersister) MeasurementsSink

func (bp *BatchPersister) MeasurementsSink() chan<- []Measurement

MeasurementsSink gives calling code write-only access to the Measurements prep channel

func (*BatchPersister) MeasurementsStopBatchingChannel

func (bp *BatchPersister) MeasurementsStopBatchingChannel() chan<- struct{}

MeasurementsStopBatchingChannel gives calling code write-only access to the Measurements batching control channel

func (*BatchPersister) SetMaximumPushInterval

func (bp *BatchPersister) SetMaximumPushInterval(ms int)

SetMaximumPushInterval sets the number of milliseconds the system will wait before pushing any accumulated Measurements to AppOptics

type Chart

type Chart struct {
	ID           int         `json:"id,omitempty"`
	Name         string      `json:"name,omitempty"`
	Type         string      `json:"type,omitempty"`
	Streams      []Stream    `json:"streams,omitempty"`
	Min          float64     `json:"min,omitempty"`
	Max          float64     `json:"max,omitempty"`
	Label        string      `json:"label,omitempty"`
	RelatedSpace int         `json:"related_space,omitempty"`
	Thresholds   []Threshold `json:"threshold,omitempty"`
}

type ChartsCommunicator

type ChartsCommunicator interface {
	List(int) ([]*Chart, error)
	Retrieve(int, int) (*Chart, error)
	Create(*Chart, int) (*Chart, error)
	Update(*Chart, int) (*Chart, error)
	Delete(int, int) error
}

type ChartsService

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

func NewChartsService

func NewChartsService(c *Client) *ChartsService

func (*ChartsService) Create

func (cs *ChartsService) Create(chart *Chart, spaceId int) (*Chart, error)

Create creates the Chart in the Space

func (*ChartsService) Delete

func (cs *ChartsService) Delete(chartId, spaceId int) error

Delete deletes the Chart from the Space

func (*ChartsService) List

func (cs *ChartsService) List(spaceId int) ([]*Chart, error)

List retrieves the Charts for the provided Space ID

func (*ChartsService) Retrieve

func (cs *ChartsService) Retrieve(chartId, spaceId int) (*Chart, error)

Retrieve finds the Chart identified by the provided parameters

func (*ChartsService) Update

func (cs *ChartsService) Update(existingChart *Chart, spaceId int) (*Chart, error)

Update takes a Chart representing requested changes to an existing Chart on the server and returns the altered Chart from the server.

type Client

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

Client implements ServiceAccessor

func NewClient

func NewClient(token string, opts ...func(*Client) error) *Client

NewClient returns a new AppOptics API client. Optional arguments UserAgentClientOption and BaseURLClientOption can be provided.

func (*Client) AlertsService

func (c *Client) AlertsService() AlertsCommunicator

AlertsService represents the subset of the API that deals with Alerts

func (*Client) AnnotationsService

func (c *Client) AnnotationsService() AnnotationsCommunicator

AnnotationsService represents the subset of the API that deals with Annotations

func (*Client) ApiTokensService

func (c *Client) ApiTokensService() ApiTokensCommunicator

func (*Client) ChartsService

func (c *Client) ChartsService() ChartsCommunicator

ChartsService represents the subset of the API that deals with Charts

func (*Client) DefaultPaginationParameters

func (c *Client) DefaultPaginationParameters(length int) *PaginationParameters

DefaultPaginationParameters provides a *PaginationParameters with minimum required fields

func (*Client) Do

func (c *Client) Do(req *http.Request, respData interface{}) (*http.Response, error)

Do performs the HTTP request on the wire, taking an optional second parameter for containing a response

func (*Client) JobsService

func (c *Client) JobsService() JobsCommunicator

JobsService represents the subset of the API that deals with Jobs

func (*Client) MeasurementsService

func (c *Client) MeasurementsService() MeasurementsCommunicator

MeasurementsService represents the subset of the API that deals with Measurements

func (*Client) MetricsService

func (c *Client) MetricsService() MetricsCommunicator

MetricsService represents the subset of the API that deals with Metrics

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, body interface{}) (*http.Request, error)

NewRequest standardizes the request being sent

func (*Client) ServicesService

func (c *Client) ServicesService() ServicesCommunicator

ServicesService represents the subset of the API that deals with Services

func (*Client) SnapshotsService

func (c *Client) SnapshotsService() SnapshotsCommunicator

SnapshotsService represents the subset of the API that deals with Snapshots

func (*Client) SpacesService

func (c *Client) SpacesService() SpacesCommunicator

SpacesService represents the subset of the API that deals with Spaces

type ClientOption

type ClientOption func(*Client) error

ClientOption provides functional option-setting behavior

func BaseURLClientOption

func BaseURLClientOption(urlString string) ClientOption

BaseURLClientOption is a config function allowing setting of the base URL the API is on

func SetDebugMode

func SetDebugMode() ClientOption

SetDebugMode sets the debugMode struct member to true

func SetHTTPClient

func SetHTTPClient(client *http.Client) ClientOption

SetHTTPClient allows the user to provide a custom http.Client configuration

func UserAgentClientOption

func UserAgentClientOption(userAgentString string) ClientOption

UserAgentClientOption is a config function allowing setting of the User-Agent header in requests

type ErrorResponse

type ErrorResponse struct {
	Errors   interface{} `json:"errors"`
	Status   string      `json:"status"`
	Response *http.Response
}

ErrorResponse represents the response body returned when the API reports an error

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

Error makes ErrorResponse satisfy the error interface and can be used to serialize error responses back to the httpClient

type Job

type Job struct {
	ID       int                 `json:"id"`
	State    string              `json:"state"`
	Progress float64             `json:"progress,omitempty"`
	Output   string              `json:"output,omitempty"`
	Errors   map[string][]string `json:"errors,omitempty"`
}

Job is the representation of a task happening in the AppOptics cloud

type JobsCommunicator

type JobsCommunicator interface {
	Retrieve(int) (*Job, error)
}

type JobsService

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

func NewJobsService

func NewJobsService(c *Client) *JobsService

func (*JobsService) Retrieve

func (js *JobsService) Retrieve(id int) (*Job, error)

Retrieve gets the Job identified by the provided ID

type LegacyClient

type LegacyClient interface {
	Post(batch *MeasurementsBatch) error
}

func NewLegacyClient

func NewLegacyClient(url, token string) LegacyClient

type ListAnnotationsResponse

type ListAnnotationsResponse struct {
	AnnotationStreams []*AnnotationStream `json:"annotations"`
	Query             QueryInfo           `json:"query"`
}

type ListServicesResponse

type ListServicesResponse struct {
	Query    QueryInfo  `json:"query,omitempty"`
	Services []*Service `json:"services,omitempty"`
}

type ListSpacesResponse

type ListSpacesResponse struct {
	Query  map[string]int `json:"query"`
	Spaces []*Space       `json:"spaces"`
}

ListSpacesResponse represents the returned data payload from Spaces API's List command (/spaces)

type Measurement

type Measurement struct {
	Name       string                 `json:"name"`
	Tags       map[string]string      `json:"tags,omitempty"`
	Value      interface{}            `json:"value,omitempty"`
	Time       int64                  `json:"time,omitempty"`
	Count      interface{}            `json:"count,omitempty"`
	Sum        interface{}            `json:"sum,omitempty"`
	Min        interface{}            `json:"min,omitempty"`
	Max        interface{}            `json:"max,omitempty"`
	Last       interface{}            `json:"last,omitempty"`
	Attributes map[string]interface{} `json:"attributes,omitempty"`
}

Measurement wraps the corresponding API construct: https://docs.appoptics.com/api/#measurements Each Measurement represents a single timeseries value for an associated Metric. If AppOptics receives a Measurement with a Name field that doesn't correspond to an existing Metric, a new Metric will be created.

func NewMeasurement

func NewMeasurement(name string) Measurement

NewMeasurement returns a Measurement with the given name and an empty attributes map

type MeasurementSet

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

MeasurementSet represents a map of SynchronizedCounters and SynchronizedAggregators. All functions of MeasurementSet are safe for concurrent use.

func NewMeasurementSet

func NewMeasurementSet() *MeasurementSet

NewMeasurementSet returns a new empty MeasurementSet

func (*MeasurementSet) Add

func (s *MeasurementSet) Add(key string, delta int64)

Add is a convenience function to get the specified Counter and call Add on it. See Counter.Add.

func (*MeasurementSet) AddInt

func (s *MeasurementSet) AddInt(key string, delta int)

AddInt is a convenience function to get the specified Counter and call AddInt on it. See Counter.AddInt.

func (*MeasurementSet) GetAggregator

func (s *MeasurementSet) GetAggregator(key string) *SynchronizedAggregator

GetAggregator returns a SynchronizedAggregator assigned to the specified key, creating a new one if necessary.

func (*MeasurementSet) GetCounter

func (s *MeasurementSet) GetCounter(key string) *SynchronizedCounter

GetCounter returns a SynchronizedCounter assigned to the specified key, creating a new one if necessary.

func (*MeasurementSet) Incr

func (s *MeasurementSet) Incr(key string)

Incr is a convenience function to get the specified Counter and call Incr on it. See Counter.Incr.

func (*MeasurementSet) Merge

func (s *MeasurementSet) Merge(report *MeasurementSetReport)

Merge takes a MeasurementSetReport and merges all of it Counters and Aggregators into this MeasurementSet. This in turn calls Counter.Add for each Counter in the report, and Aggregator.Update for each Aggregator in the report. Any keys that do not exist in this MeasurementSet will be created.

func (*MeasurementSet) Reset

Reset generates a MeasurementSetReport with a copy of the state of each of the non-zero Counters and Aggregators in this MeasurementSet. Counters with a value of 0 and Aggregators with a count of 0 are omitted. All Counters and Aggregators are reset to the zero/nil state but are never removed from this MeasurementSet, so they can continue be used indefinitely.

func (*MeasurementSet) UpdateAggregator

func (s *MeasurementSet) UpdateAggregator(key string, other Aggregator)

UpdateAggregator is a convenience to get the specified Aggregator and call Update on it. See Aggregator.Update.

func (*MeasurementSet) UpdateAggregatorValue

func (s *MeasurementSet) UpdateAggregatorValue(key string, val float64)

UpdateAggregatorValue is a convenience to get the specified Aggregator and call UpdateValue on it. See Aggregator.UpdateValue.

type MeasurementSetReport

type MeasurementSetReport struct {
	Counts      map[string]int64
	Aggregators map[string]Aggregator
}

func NewMeasurementSetReport

func NewMeasurementSetReport() *MeasurementSetReport

type MeasurementsBatch

type MeasurementsBatch struct {
	// Measurements is the collection of timeseries entries being sent to the server
	Measurements []Measurement `json:"measurements,omitempty"`
	// Period is a slice of time measured in seconds, used in service-side aggregation
	Period int64 `json:"period,omitempty"`
	// Time is a Unix epoch timestamp used to align a group of Measurements on a time boundary
	Time int64 `json:"time"`
	// Tags are key-value identifiers that will be applied to all Measurements in the batch
	Tags *map[string]string `json:"tags,omitempty"`
}

MeasurementsBatch is a collection of Measurements persisted to the API at the same time. It can optionally have tags that are applied to all contained Measurements.

func NewMeasurementsBatch

func NewMeasurementsBatch(m []Measurement, tags *map[string]string) *MeasurementsBatch

type MeasurementsCommunicator

type MeasurementsCommunicator interface {
	Create(*MeasurementsBatch) (*http.Response, error)
}

MeasurementsCommunicator defines an interface for communicating with the Measurements portion of the AppOptics API

type MeasurementsService

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

MeasurementsService implements MeasurementsCommunicator

func NewMeasurementsService

func NewMeasurementsService(c *Client) *MeasurementsService

func (*MeasurementsService) Create

func (ms *MeasurementsService) Create(batch *MeasurementsBatch) (*http.Response, error)

Create persists the given MeasurementCollection to AppOptics

type Metric

type Metric struct {
	Name        string           `json:"name"`
	Description string           `json:"description,omitempty"`
	Type        string           `json:"type"`
	Period      int              `json:"period,omitempty"`
	DisplayName string           `json:"display_name,omitempty"`
	Composite   string           `json:"composite,omitempty"`
	Attributes  MetricAttributes `json:"attributes,omitempty"`
}

Metric is an AppOptics Metric

type MetricAttributes

type MetricAttributes struct {
	Color             string      `json:"color,omitempty"`
	DisplayMax        interface{} `json:"display_max,omitempty"`
	DisplayMin        interface{} `json:"display_min,omitempty"`
	DisplayUnitsLong  string      `json:"display_units_long,omitempty"`
	DisplayUnitsShort string      `json:"display_units_short,omitempty"`
	DisplayStacked    bool        `json:"display_stacked,omitempty"`
	CreatedByUA       string      `json:"created_by_ua,omitempty"`
	GapDetection      bool        `json:"gap_detection,omitempty"`
	Aggregate         bool        `json:"aggregate,omitempty"`
	SummarizeFunction string      `json:"summarize_function,omitempty"`
}

MetricAttributes are key/value pairs of metadata about the Metric

type MetricUpdatePayload

type MetricUpdatePayload struct {
	Names      []string         `json:"names"`
	Attributes MetricAttributes `json:"attributes"`
}

MetricUpdatePayload will apply the state represented by Attributes to the Metrics identified by Names

type MetricsCommunicator

type MetricsCommunicator interface {
	List() (*MetricsResponse, error)
	Retrieve(string) (*Metric, error)
	Create(*Metric) (*Metric, error)
	Update(string, *Metric) error
	Delete(string) error
}

type MetricsResponse

type MetricsResponse struct {
	Query   QueryInfo `json:"query,omitempty"`
	Metrics []*Metric `json:"metrics,omitempty"`
}

type MetricsService

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

func NewMetricsService

func NewMetricsService(c *Client) *MetricsService

func (*MetricsService) Create

func (ms *MetricsService) Create(m *Metric) (*Metric, error)

Create creates the Metric in the organization identified by the AppOptics token

func (*MetricsService) Delete

func (ms *MetricsService) Delete(name string) error

Delete deletes the Metric matching the name argument

func (*MetricsService) List

func (ms *MetricsService) List() (*MetricsResponse, error)

List lists the Metrics in the organization identified by the AppOptics token

func (*MetricsService) Retrieve

func (ms *MetricsService) Retrieve(name string) (*Metric, error)

Retrieve fetches the Metric identified by the given name

func (*MetricsService) Update

func (ms *MetricsService) Update(originalName string, m *Metric) error

Update updates the Metric with the given name, setting it to match the Metric pointer argument

type MockMeasurementsService

type MockMeasurementsService struct {
	OnCreate func(batch *MeasurementsBatch) (*http.Response, error)
}

func (*MockMeasurementsService) Create

type MultiReporter

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

func NewMultiReporter

func NewMultiReporter(m *MeasurementSet, reporters []*Reporter) *MultiReporter

func (*MultiReporter) Start

func (m *MultiReporter) Start()

type PaginationParameters

type PaginationParameters struct {
	Offset  int
	Length  int
	Orderby string
	Sort    string
}

PaginationParameters holds pagination values https://docs.appoptics.com/api/?shell#request-parameters

func (*PaginationParameters) AddToRequest

func (rp *PaginationParameters) AddToRequest(req *http.Request)

AddToRequest mutates the provided http.Request with the PaginationParameters values Note that only valid values for Sort are "asc" and "desc" but the client does not enforce this.

type QueryInfo

type QueryInfo struct {
	Found  int `json:"found,omitempty"`
	Length int `json:"length,omitempty"`
	Offset int `json:"offset,omitempty"`
	Total  int `json:"total,omitempty"`
}

QueryInfo holds pagination information coming from list actions

type Reporter

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

Reporter provides a way to persist data from a set collection of Aggregators and Counters at a regular interval

func NewReporter

func NewReporter(measurementSet *MeasurementSet, communicator MeasurementsCommunicator, prefix string) *Reporter

NewReporter returns a reporter for a given MeasurementSet, providing a way to sync metric information to AppOptics for a collection of running metrics.

func (*Reporter) Start

func (r *Reporter) Start()

Start kicks off two goroutines that help batch and report metrics measurements to AppOptics.

type RetrieveAnnotationsRequest

type RetrieveAnnotationsRequest struct {
	Name      string
	StartTime time.Time
	EndTime   time.Time
	Sources   []string
}

type RetrieveSpaceResponse

type RetrieveSpaceResponse struct {
	Space
	Charts []map[string]int `json:"charts,omitempty"`
}

RetrieveSpaceResponse represents the returned data payload from Spaces API's Retrieve command (/spaces/:id)

type Service

type Service struct {
	ID       int               `json:"id,omitempty"`
	Type     string            `json:"type,omitempty"`
	Settings map[string]string `json:"settings,omitempty"`
	Title    string            `json:"title,omitempty"`
}

type ServiceAccessor

type ServiceAccessor interface {
	AlertsService() AlertsCommunicator
	AnnotationsService() AnnotationsCommunicator
	ApiTokensService() ApiTokensCommunicator
	ChartsService() ChartsCommunicator
	JobsService() JobsCommunicator
	MeasurementsService() MeasurementsCommunicator
	MetricsService() MetricsCommunicator
	ServicesService() ServicesCommunicator
	SnapshotsService() SnapshotsCommunicator
	SpacesService() SpacesCommunicator
}

ServiceAccessor defines an interface for talking to via domain-specific service constructs

type ServicesCommunicator

type ServicesCommunicator interface {
	List() (*ListServicesResponse, error)
	Retrieve(int) (*Service, error)
	Create(*Service) (*Service, error)
	Update(*Service) error
	Delete(int) error
}

type ServicesService

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

func NewServiceService

func NewServiceService(c *Client) *ServicesService

func (*ServicesService) Create

func (ss *ServicesService) Create(s *Service) (*Service, error)

Create creates the Service

func (*ServicesService) Delete

func (ss *ServicesService) Delete(id int) error

Delete deletes the Service

func (*ServicesService) List

List retrieves all Services

func (*ServicesService) Retrieve

func (ss *ServicesService) Retrieve(id int) (*Service, error)

Retrieve returns the Service identified by the parameter

func (*ServicesService) Update

func (ss *ServicesService) Update(s *Service) error

Update updates the Service

type SimpleClient

type SimpleClient struct {
	URL   string
	Token string
	// contains filtered or unexported fields
}

func (*SimpleClient) Post

func (c *SimpleClient) Post(batch *MeasurementsBatch) error

Used for the collector's internal metrics

type Snapshot

type Snapshot struct {
	Href      string                   `json:"href,omitempty"`
	JobHref   string                   `json:"job_href,omitempty"`
	ImageHref string                   `json:"image_href,omitempty"`
	Duration  int                      `json:"duration,omitempty"`
	EndTime   time.Time                `json:"end_time,omitempty"`
	CreatedAt time.Time                `json:"created_at,omitempty"`
	UpdatedAt time.Time                `json:"updated_at,omitempty"`
	Subject   map[string]SnapshotChart `json:"subject"`
}

Snapshot represents a portrait of a Chart at a specific point in time

type SnapshotChart

type SnapshotChart struct {
	ID      int      `json:"id"`
	Sources []string `json:"sources"`
	Type    string   `json:"type"`
}

SnapshotChart contains the metadata for the chart requested in the Snapshot

type SnapshotsCommunicator

type SnapshotsCommunicator interface {
	Create(*Snapshot) (*Snapshot, error)
	Retrieve(int) (*Snapshot, error)
}

type SnapshotsService

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

func NewSnapshotsService

func NewSnapshotsService(c *Client) *SnapshotsService

func (*SnapshotsService) Create

func (ss *SnapshotsService) Create(s *Snapshot) (*Snapshot, error)

Create requests the creation of a new Snapshot for later retrieval

func (*SnapshotsService) Retrieve

func (ss *SnapshotsService) Retrieve(id int) (*Snapshot, error)

Retrieve fetches data about a Snapshot, including a fully qualified URL for fetching the image asset itself

type Space

type Space struct {
	// ID is the unique identifier of the Space
	ID int `json:"id,omitempty"`
	// Name is the name of the Space
	Name string `json:"name,omitempty"`
}

Space represents a single AppOptics Space

type SpacesCommunicator

type SpacesCommunicator interface {
	Create(string) (*Space, error)
	List(*PaginationParameters) ([]*Space, error)
	Retrieve(int) (*RetrieveSpaceResponse, error)
	Update(int, string) error
	Delete(int) error
}

SpacesCommunicator defines the interface for the Spaces API

type SpacesService

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

func NewSpacesService

func NewSpacesService(c *Client) *SpacesService

func (*SpacesService) Create

func (s *SpacesService) Create(name string) (*Space, error)

Create creates the Space with the given name

func (*SpacesService) Delete

func (s *SpacesService) Delete(id int) error

Delete implements the Spaces API's Delete command

func (*SpacesService) List

func (s *SpacesService) List(rp *PaginationParameters) ([]*Space, error)

List implements the Spaces API's List command

func (*SpacesService) Retrieve

func (s *SpacesService) Retrieve(id int) (*RetrieveSpaceResponse, error)

Retrieve implements the Spaces API's Retrieve command

func (*SpacesService) Update

func (s *SpacesService) Update(id int, name string) error

Update implements the Spaces API's Update command

type Stream

type Stream struct {
	ID                 int    `json:"id,omitempty"`
	Name               string `json:"name,omitempty"`
	Metric             string `json:"metric,omitempty"`
	Composite          string `json:"composite,omitempty"`
	Type               string `json:"type,omitempty"`
	Tags               []Tag  `json:"tags,omitempty"`
	GroupFunction      string `json:"group_function,omitempty"` // valid: average, sum, min, max
	GroupBy            string `json:"group_by,omitempty"`
	SummaryFunction    string `json:"summary_function,omitempty"`    // valid: average, sum, min, max, count
	DownsampleFunction string `json:"downsample_function,omitempty"` // valid: average, min, max, sum, count
	Color              string `json:"color,omitempty"`
	UnitsShort         string `json:"units_short,omitempty"`
	UnitsLong          string `json:"units_long,omitempty"`
	TransformFunction  string `json:"transform_function,omitempty"`
	Period             int    `json:"period,omitempty"`
	Min                int    `json:"min,omitempty"`
	Max                int    `json:"max,omitempty"`
}

type SynchronizedAggregator

type SynchronizedAggregator struct {
	Aggregator
	// contains filtered or unexported fields
}

SynchronizedAggregator augments an Aggregator with a mutex to allow concurrent access from multiple goroutines.

func (*SynchronizedAggregator) Reset

Reset returns a copy the current Aggregator state and resets it back to its zero state.

func (*SynchronizedAggregator) Update

func (g *SynchronizedAggregator) Update(other Aggregator)

Update is a concurrent-safe wrapper around Aggregator.Update

func (*SynchronizedAggregator) UpdateValue

func (g *SynchronizedAggregator) UpdateValue(val float64)

UpdateValue is a concurrent-safe wrapper around Aggregator.UpdateValue

type SynchronizedCounter

type SynchronizedCounter int64

SynchronizedCounter wraps an int64 with functions to concurrently add/increment and to periodically query & reset the sum.

func NewCounter

func NewCounter() *SynchronizedCounter

NewCounter returns a new SynchronizedCounter initialized to 0.

func (*SynchronizedCounter) Add

func (c *SynchronizedCounter) Add(delta int64)

Add adds the specified delta to the counter.

func (*SynchronizedCounter) AddInt

func (c *SynchronizedCounter) AddInt(delta int)

AddInt is a convenience function to add delta to the counter, where delta is an int.

func (*SynchronizedCounter) Incr

func (c *SynchronizedCounter) Incr()

Incr adds 1 to the counter.

func (*SynchronizedCounter) Reset

func (c *SynchronizedCounter) Reset() int64

Reset returns the current value and resets the counter to zero

type Tag

type Tag struct {
	Name    string   `json:"name,omitempty"`
	Values  []string `json:"values,omitempty"`
	Grouped bool     `json:"grouped,omitempty"`
	Dynamic bool     `json:"dynamic,omitempty"`
}

Tag represents an AppOptics Tag, used in Measurements, Charts, etc

type TaggedMeasurementSet

type TaggedMeasurementSet struct {
	*MeasurementSet
	// contains filtered or unexported fields
}

func (*TaggedMeasurementSet) Add

func (s *TaggedMeasurementSet) Add(key string, delta int64)

Add is a convenience function to get the specified Counter and call Add on it. See Counter.Add.

func (*TaggedMeasurementSet) AddInt

func (s *TaggedMeasurementSet) AddInt(key string, delta int)

AddInt is a convenience function to get the specified Counter and call AddInt on it. See Counter.AddInt.

func (*TaggedMeasurementSet) GetAggregator

func (s *TaggedMeasurementSet) GetAggregator(key string) *SynchronizedAggregator

GetAggregator returns a SynchronizedAggregator assigned to the specified key with tags, creating a new one if necessary.

func (*TaggedMeasurementSet) GetCounter

func (s *TaggedMeasurementSet) GetCounter(key string) *SynchronizedCounter

GetCounter returns a SynchronizedCounter assigned to the specified key with tags, creating a new one if necessary.

func (*TaggedMeasurementSet) Incr

func (s *TaggedMeasurementSet) Incr(key string)

Incr is a convenience function to get the specified Counter and call Incr on it. See Counter.Incr.

func (*TaggedMeasurementSet) Merge

func (s *TaggedMeasurementSet) Merge(report *MeasurementSetReport)

Merge takes a MeasurementSetReport and merges all of it Counters and Aggregators into this MeasurementSet. This in turn calls Counter.Add for each Counter in the report, and Aggregator.Update for each Aggregator in the report. Any keys that do not exist in this MeasurementSet will be created.

func (*TaggedMeasurementSet) SetTags

func (s *TaggedMeasurementSet) SetTags(tags map[string]interface{})

SetTags sets the value of the tags map

func (*TaggedMeasurementSet) Tags

func (s *TaggedMeasurementSet) Tags() map[string]interface{}

Tags returns the tags map

func (*TaggedMeasurementSet) UpdateAggregator

func (s *TaggedMeasurementSet) UpdateAggregator(key string, other Aggregator)

UpdateAggregator is a convenience to get the specified Aggregator and call Update on it. See Aggregator.Update.

func (*TaggedMeasurementSet) UpdateAggregatorValue

func (s *TaggedMeasurementSet) UpdateAggregatorValue(key string, val float64)

UpdateAggregatorValue is a convenience to get the specified Aggregator and call UpdateValue on it. See Aggregator.UpdateValue.

type Threshold

type Threshold struct {
	Operator string  `json:"operator,omitempty"`
	Value    float64 `json:"value,omitempty"`
	Type     string  `json:"type,omitempty"`
}

Directories

Path Synopsis
contrib

Jump to

Keyboard shortcuts

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