client

package
v0.0.0-...-6d38953 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2016 License: MIT Imports: 8 Imported by: 35

Documentation

Overview

Example (RegistrationURL)

Example of getting a registration URL for a product

c := client.New("")
r := client.Registration{
	ClusterID:   "clus1",
	Product:     "chronograf",
	RedirectURL: "http://example.com",
}

s, _ := c.RegistrationURL(r)
fmt.Printf("s: %s\n", s)
// https://usage.influxdata.com/start?cluster_id=clus1&product=chronograf&redirect_url=http%3A%2F%2Fexample.com
Output:

Example (SaveServer)

Example of saving a server to the Usage API

c := client.New("token-goes-here")
// override the URL for testing
c.URL = "https://usage.staging.influxdata.com"

s := client.Server{
	ClusterID: "clus1",
	Host:      "example.com",
	Product:   "jambox",
	Version:   "1.0",
	ServerID:  "serv1",
}

res, err := c.Save(s)
fmt.Printf("err: %s\n", err)
b, _ := ioutil.ReadAll(res.Body)
fmt.Printf("b: %s\n", b)
Output:

Example (SaveStats)

Example of saving Stats data to Enterprise

c := client.New("token-goes-here")
// override the URL for testing
c.URL = "https://usage.staging.influxdata.com"

st := client.Stats{
	ClusterID: "clus1",
	ServerID:  "serv1",
	Product:   "influxdb",
	Data: []client.StatsData{
		client.StatsData{
			Name: "engine",
			Tags: client.Tags{
				"path":    "/home/philip/.influxdb/data/_internal/monitor/1",
				"version": "bz1",
			},
			Values: client.Values{
				"blks_write":          39,
				"blks_write_bytes":    2421,
				"blks_write_bytes_c":  2202,
				"points_write":        39,
				"points_write_dedupe": 39,
			},
		},
	},
}

res, err := c.Save(st)
fmt.Printf("err: %s\n", err)
b, _ := ioutil.ReadAll(res.Body)
fmt.Printf("b: %s\n", b)
Output:

Example (SaveUsage)

Example of saving Usage data to the Usage API

c := client.New("token-goes-here")
// override the URL for testing
c.URL = "https://usage.staging.influxdata.com"

u := client.Usage{
	Product: "influxdb",
	Data: []client.UsageData{
		{
			Tags: client.Tags{
				"version": "0.9.5",
				"arch":    "amd64",
				"os":      "linux",
			},
			Values: client.Values{
				"cluster_id":       "23423",
				"server_id":        "1",
				"num_databases":    3,
				"num_measurements": 2342,
				"num_series":       87232,
			},
		},
	},
}

res, err := c.Save(u)
fmt.Printf("err: %s\n", err)
b, _ := ioutil.ReadAll(res.Body)
fmt.Printf("b: %s\n", b)
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var URL = "https://usage.influxdata.com"

URL is the default URL for the host of the Usage API. This variable can be set globally or on a per Client instance.

Functions

This section is empty.

Types

type Client

type Client struct {
	URL   string // Defaults to `client.URL`
	Token string // OPTIONAL: The token of the customer making the request
}

Client handles all of the heavy lifting of talking to the Usage API for you.

func New

func New(token string) *Client

New returns a configured `Client`. The `token` is optional, but if you have it, you should pass it in.

func (*Client) RegistrationURL

func (c *Client) RegistrationURL(r Registration) (string, error)

RegistrationURL returns a URL based on the Registration data provided. The app can then use this URL to direct customers over to the Enterprise application to complete their registration.

func (*Client) Save

func (c *Client) Save(s Saveable) (*http.Response, error)

Save does all of the heavy lifting of saving a Saveable Type to the Usage API. This will take care of things like building the full path, setting the `token` on the request if one is available, etc... It will also check the status code of the response and handle non-successful responses by generating a proper `error` for them.

type Registration

type Registration struct {
	ClusterID string
	Product   string // influxdb, chronograf, telegraf, kapicator
	// OPTIONAL: Enterprise will redirect the customer back to the
	// RedirectURL if it is specified.
	RedirectURL string
}

Registration is used to collect data needed by Enterprise to properly start the registration Process.

func (Registration) IsValid

func (r Registration) IsValid() error

IsValid returns an error if the Registration is not valid. This is necessary since there is no server-side validation of this data.

type Saveable

type Saveable interface {
	// Path returns specific path to where this type should
	// be saved, that is everything in the path __after__ "/api/v1".
	Path() string
}

Saveable needs to be implemented for types that want to be able to be saved to the Usage API.

type Server

type Server struct {
	ClusterID string `json:"cluster_id"`
	ServerID  string `json:"server_id"`
	Host      string `json:"host"`
	Product   string `json:"product"`
	Version   string `json:"version"`
}

func (Server) Path

func (s Server) Path() string

type SimpleError

type SimpleError struct {
	Message string `json:"error"`
}

SimpleError wraps simple error messages that come from the Usage API, such as: {"error":"json: cannot unmarshal number into Go value of type string"}

func (SimpleError) Error

func (se SimpleError) Error() string

type Stats

type Stats struct {
	Product   string      `json:"-"`
	ClusterID string      `json:"cluster_id"`
	ServerID  string      `json:"server_id"`
	Data      []StatsData `json:"stats"`
}

func (Stats) Path

func (s Stats) Path() string

type StatsData

type StatsData struct {
	Name   string `json:"name"`
	Tags   Tags   `json:"tags"`
	Values Values `json:"values"`
}

type Tags

type Tags map[string]string

Tags is a mapping of key/values representing tags in an InfluxDB instance

type Usage

type Usage struct {
	Data    []UsageData
	Product string `json:"-"`
}

func (Usage) MarshalJSON

func (u Usage) MarshalJSON() ([]byte, error)

func (Usage) Path

func (u Usage) Path() string

type UsageData

type UsageData struct {
	Tags   Tags   `json:"tags"`
	Values Values `json:"values"`
}

type ValidationErrors

type ValidationErrors struct {
	Errors map[string][]string `json:"errors"`
}

ValidationErrors wraps more complex validation errors that the Usage API generates. These most usually come as the result of a 422 error.

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

type Values

type Values map[string]interface{}

Jump to

Keyboard shortcuts

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