| 1 |
package cloudapi |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
|
| 6 |
"github.com/joyent/gocommon/client" |
| 7 |
"github.com/joyent/gocommon/errors" |
| 8 |
) |
| 9 |
|
| 10 |
|
| 11 |
type Analytics struct { |
| 12 |
Modules map[string]interface{} |
| 13 |
Fields map[string]interface{} |
| 14 |
Types map[string]interface{} |
| 15 |
Metrics map[string]interface{} |
| 16 |
Transformations map[string]interface{} |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
type Instrumentation struct { |
| 22 |
Module string `json:"module"` |
| 23 |
Stat string `json:"stat"` |
| 24 |
Predicate string `json:"predicate"` |
| 25 |
Decomposition []string `json:"decomposition"` |
| 26 |
ValueDimension int `json:"value-dimenstion"` |
| 27 |
ValueArity string `json:"value-arity"` |
| 28 |
RetentionTime int `json:"retention-time"` |
| 29 |
Granularity int `json:"granularitiy"` |
| 30 |
IdleMax int `json:"idle-max"` |
| 31 |
Transformations []string `json:"transformations"` |
| 32 |
PersistData bool `json:"persist-data"` |
| 33 |
Crtime int `json:"crtime"` |
| 34 |
ValueScope string `json:"value-scope"` |
| 35 |
Id string `json:"id"` |
| 36 |
Uris []Uri `json:"uris"` |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
type Uri struct { |
| 41 |
Uri string |
| 42 |
Name string |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
type InstrumentationValue struct { |
| 47 |
Value interface{} |
| 48 |
Transformations map[string]interface{} |
| 49 |
StartTime int |
| 50 |
Duration int |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
type HeatmapOpts struct { |
| 56 |
Height int `json:"height"` |
| 57 |
Width int `json:"width"` |
| 58 |
Ymin int `json:"ymin"` |
| 59 |
Ymax int `json:"ymax"` |
| 60 |
Nbuckets int `json:"nbuckets"` |
| 61 |
Selected []string `json:"selected"` |
| 62 |
Isolate bool `json:"isolate"` |
| 63 |
Exclude bool `json:"exclude"` |
| 64 |
Hues []string `json:"hues"` |
| 65 |
DecomposeAll bool `json:"decompose_all"` |
| 66 |
X int `json:"x"` |
| 67 |
Y int `json:"y"` |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
type Heatmap struct { |
| 72 |
BucketTime int `json:"bucket_time"` |
| 73 |
BucketYmin int `json:"bucket_ymin"` |
| 74 |
BucketYmax int `json:"bucket_ymax"` |
| 75 |
Present map[string]interface{} `json:"present"` |
| 76 |
Total int `json:"total"` |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
type CreateInstrumentationOpts struct { |
| 82 |
Clone int `json:"clone"` |
| 83 |
Module string `json:"module"` |
| 84 |
Stat string `json:"stat"` |
| 85 |
Predicate string `json:"predicate"` |
| 86 |
Decomposition string `json:"decomposition"` |
| 87 |
Granularity int `json:"granularity"` |
| 88 |
RetentionTime int `json:"retention-time"` |
| 89 |
PersistData bool `json:"persist-data"` |
| 90 |
IdleMax int `json:"idle-max"` |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
func (c *Client) DescribeAnalytics() (*Analytics, error) { |
| 96 |
var resp Analytics |
| 97 |
req := request{ |
| 98 |
method: client.GET, |
| 99 |
url: apiAnalytics, |
| 100 |
resp: &resp, |
| 101 |
} |
| 102 |
if _, err := c.sendRequest(req); err != nil { |
| 103 |
return nil, errors.Newf(err, "failed to get analytics") |
| 104 |
} |
| 105 |
return &resp, nil |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
func (c *Client) ListInstrumentations() ([]Instrumentation, error) { |
| 111 |
var resp []Instrumentation |
| 112 |
req := request{ |
| 113 |
method: client.GET, |
| 114 |
url: makeURL(apiAnalytics, apiInstrumentations), |
| 115 |
resp: &resp, |
| 116 |
} |
| 117 |
if _, err := c.sendRequest(req); err != nil { |
| 118 |
return nil, errors.Newf(err, "failed to get instrumentations") |
| 119 |
} |
| 120 |
return resp, nil |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
func (c *Client) GetInstrumentation(instrumentationID string) (*Instrumentation, error) { |
| 126 |
var resp Instrumentation |
| 127 |
req := request{ |
| 128 |
method: client.GET, |
| 129 |
url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID), |
| 130 |
resp: &resp, |
| 131 |
} |
| 132 |
if _, err := c.sendRequest(req); err != nil { |
| 133 |
return nil, errors.Newf(err, "failed to get instrumentation with id %s", instrumentationID) |
| 134 |
} |
| 135 |
return &resp, nil |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
func (c *Client) GetInstrumentationValue(instrumentationID string) (*InstrumentationValue, error) { |
| 142 |
var resp InstrumentationValue |
| 143 |
req := request{ |
| 144 |
method: client.GET, |
| 145 |
url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID, apiInstrumentationsValue, apiInstrumentationsRaw), |
| 146 |
resp: &resp, |
| 147 |
} |
| 148 |
if _, err := c.sendRequest(req); err != nil { |
| 149 |
return nil, errors.Newf(err, "failed to get value for instrumentation with id %s", instrumentationID) |
| 150 |
} |
| 151 |
return &resp, nil |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
func (c *Client) GetInstrumentationHeatmap(instrumentationID string) (*Heatmap, error) { |
| 157 |
var resp Heatmap |
| 158 |
req := request{ |
| 159 |
method: client.GET, |
| 160 |
url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID, apiInstrumentationsValue, apiInstrumentationsHeatmap, apiInstrumentationsImage), |
| 161 |
resp: &resp, |
| 162 |
} |
| 163 |
if _, err := c.sendRequest(req); err != nil { |
| 164 |
return nil, errors.Newf(err, "failed to get heatmap image for instrumentation with id %s", instrumentationID) |
| 165 |
} |
| 166 |
return &resp, nil |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
func (c *Client) GetInstrumentationHeatmapDetails(instrumentationID string) (*Heatmap, error) { |
| 173 |
var resp Heatmap |
| 174 |
req := request{ |
| 175 |
method: client.GET, |
| 176 |
url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID, apiInstrumentationsValue, apiInstrumentationsHeatmap, apiInstrumentationsDetails), |
| 177 |
resp: &resp, |
| 178 |
} |
| 179 |
if _, err := c.sendRequest(req); err != nil { |
| 180 |
return nil, errors.Newf(err, "failed to get heatmap details for instrumentation with id %s", instrumentationID) |
| 181 |
} |
| 182 |
return &resp, nil |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
func (c *Client) CreateInstrumentation(opts CreateInstrumentationOpts) (*Instrumentation, error) { |
| 190 |
var resp Instrumentation |
| 191 |
req := request{ |
| 192 |
method: client.POST, |
| 193 |
url: makeURL(apiAnalytics, apiInstrumentations), |
| 194 |
reqValue: opts, |
| 195 |
resp: &resp, |
| 196 |
expectedStatus: http.StatusCreated, |
| 197 |
} |
| 198 |
if _, err := c.sendRequest(req); err != nil { |
| 199 |
return nil, errors.Newf(err, "failed to create instrumentation") |
| 200 |
} |
| 201 |
return &resp, nil |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
func (c *Client) DeleteInstrumentation(instrumentationID string) error { |
| 207 |
req := request{ |
| 208 |
method: client.DELETE, |
| 209 |
url: makeURL(apiAnalytics, apiInstrumentations, instrumentationID), |
| 210 |
expectedStatus: http.StatusNoContent, |
| 211 |
} |
| 212 |
if _, err := c.sendRequest(req); err != nil { |
| 213 |
return errors.Newf(err, "failed to delete instrumentation with id %s", instrumentationID) |
| 214 |
} |
| 215 |
return nil |
| 216 |
} |