sdc

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sdc is the Sysdig Cloud API client for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

Types

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// User agent for client.
	UserAgent string

	// Security API token.
	Token string

	// Services used for communicating with the API.
	Data DataService
	// contains filtered or unexported fields
}

Client manages communication with Sysdig Cloud API.

func New

func New(httpClient *http.Client, token string, opts ...ClientOpt) (*Client, error)

New returns a new Sysdig Cloud API client instance.

func NewClient

func NewClient(httpClient *http.Client, token string) *Client

NewClient returns a new Sysdig Monitor API client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

type ClientOpt

type ClientOpt func(*Client) error

ClientOpt are options for New.

func SetBaseURL

func SetBaseURL(bu string) ClientOpt

SetBaseURL is a client option for setting the base URL.

func SetUserAgent

func SetUserAgent(ua string) ClientOpt

SetUserAgent is a client option for setting the user agent.

type DataService

type DataService interface {
	Get(context.Context, *GetDataRequest) (*GetDataResponse, *Response, error)
	Metrics(context.Context) (Metrics, *Response, error)
}

type DataServiceOp

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

DataServiceOp handles communication with Data methods of the Sysdig Cloud API.

func (*DataServiceOp) Get

func (*DataServiceOp) Metrics

func (s *DataServiceOp) Metrics(ctx context.Context) (Metrics, *Response, error)

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string `json:"message"`

	// RequestID returned from the API, useful to contact support.
	RequestID string `json:"request_id"`
}

An ErrorResponse reports the error caused by an API request.

TODO: I made this up, it needs to be structured matching actual API responses.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type GetDataRequest

type GetDataRequest struct {
	Metrics        []Metric `json:"metrics"`
	DataSourceType string   `json:"dataSourceType,omitempty"`
	Start          int      `json:"start,omitempty"`
	End            int      `json:"end,omitempty"`
	Last           int      `json:"last,omitempty"`
	Filter         string   `json:"filter,omitempty"`
	Paging         string   `json:"paging,omitempty"`
	Sampling       int      `json:"sampling,omitempty"`
}

func (*GetDataRequest) WithFilter

func (gdr *GetDataRequest) WithFilter(filter string) *GetDataRequest

func (*GetDataRequest) WithMetric

func (gdr *GetDataRequest) WithMetric(id string, aggregation *MetricAggregation) *GetDataRequest

type GetDataResponse

type GetDataResponse struct {
	// A list of time samples.
	Samples []TimeSample `json:"data"`
	Start   Timestamp    `json:"start"`
	End     Timestamp    `json:"end"`
}

func (*GetDataResponse) FirstValue

func (gdr *GetDataResponse) FirstValue() (json.RawMessage, error)

type Metric

type Metric struct {
	ID           string            `json:"id"`
	Aggregations MetricAggregation `json:"aggregations,omitempty"`
}

type MetricAggregation

type MetricAggregation struct {
	Time  string `json:"time"`
	Group string `json:"group"`
}

type MetricDefinition

type MetricDefinition struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	CanMonitor  bool     `json:"canMonitor"`
	Hidden      bool     `json:"hidden"`
	GroupBy     []string `json:"groupBy"`
	Namespaces  []string `json:"namespaces"`

	// Possible values:
	// - "%" (percentage)
	// - "byte"
	// - "date"
	// - "double"
	// - "int"
	// - "number"
	// - "relativeTime"
	// - "string"
	Type string `json:"type"`

	// Possible values:
	// - "counter"
	// - "gauge"
	// - "none", e.g.: id=kubernetes.service.name
	// - "segmentBy", e.g.: id=host, id=port
	MetricType string `json:"metricType"`
}

type Metrics

type Metrics map[string]*MetricDefinition

type Response

type Response struct {
	*http.Response
}

Response is a Sysdig Cloud response. This wraps the standard http.Response returned from Sysdig Cloud.

type TimeSample

type TimeSample struct {
	Time   Timestamp         `json:"t"`
	Values []json.RawMessage `json:"d"`
}

type Timestamp

type Timestamp time.Time

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) String

func (t *Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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