Fixup bad rebase

This commit is contained in:
Chris Johnson 2017-05-17 11:33:44 -04:00
parent 002c9985d3
commit 52040c69a4
4 changed files with 33 additions and 11 deletions

View File

@ -28,6 +28,7 @@ func Provider() terraform.ResourceProvider {
ResourcesMap: map[string]*schema.Resource{
"librato_space": resourceLibratoSpace(),
"librato_space_chart": resourceLibratoSpaceChart(),
"librato_metric": resourceLibratoMetric(),
"librato_alert": resourceLibratoAlert(),
"librato_service": resourceLibratoService(),
},

View File

@ -1,6 +1,7 @@
package librato
import (
"encoding/json"
"fmt"
"log"
"reflect"
@ -166,6 +167,7 @@ func resourceLibratoMetricCreate(d *schema.ResourceData, meta interface{}) error
_, err := client.Metrics.Edit(metric)
if err != nil {
log.Printf("[INFO] ERROR creating Metric: %s", err)
return fmt.Errorf("Error creating Librato service: %s", err)
}
@ -259,7 +261,8 @@ func resourceLibratoMetricRead(d *schema.ResourceData, meta interface{}) error {
}
return fmt.Errorf("Error reading Librato Metric %s: %s", id, err)
}
log.Printf("[INFO] Received Librato Metric: %+v", *metric)
log.Printf("[INFO] Read Librato Metric: %s", structToString(metric))
return resourceLibratoMetricReadResult(d, metric)
}
@ -400,7 +403,7 @@ func resourceLibratoMetricDelete(d *schema.ResourceData, meta interface{}) error
if errResp, ok := err.(*librato.ErrorResponse); ok && errResp.Response.StatusCode == 404 {
return nil
}
log.Printf("[DEBUG] unknown error attempting to Get metric: %s", err)
log.Printf("[INFO] non-retryable error attempting to Get metric: %s", err)
return resource.NonRetryableError(err)
}
return resource.RetryableError(fmt.Errorf("metric still exists"))
@ -409,3 +412,8 @@ func resourceLibratoMetricDelete(d *schema.ResourceData, meta interface{}) error
d.SetId("")
return nil
}
func structToString(i interface{}) string {
s, _ := json.Marshal(i)
return string(s)
}

View File

@ -14,28 +14,37 @@ type MetricsService struct {
// Metric represents a Librato Metric.
type Metric struct {
Name *string `json:"name"`
Description *string `json:"description,omitempty"`
Type *string `json:"type"`
Period *uint `json:"period,omitempty"`
DisplayName *string `json:"display_name,omitempty"`
Composite *string `json:"composite,omitempty"`
Attributes *MetricAttributes `json:"attributes,omitempty"`
}
// MetricAttributes are named attributes as key:value pairs.
type MetricAttributes struct {
Color *string `json:"color"`
// These are interface{} because sometimes the Librato API
// returns strings, and sometimes it returns integers
DisplayMax interface{} `json:"display_max"`
DisplayMin interface{} `json:"display_min"`
DisplayUnitsLong string `json:"display_units_long"`
DisplayUnitsShort string `json:"display_units_short"`
DisplayStacked bool `json:"display_stacked"`
DisplayTransform string `json:"display_transform"`
CreatedByUA string `json:"created_by_ua,omitempty"`
GapDetection bool `json:"gap_detection,omitempty"`
Aggregate bool `json:"aggregate,omitempty"`
}
// ListMetricsOptions are used to coordinate paging of metrics.
type ListMetricsOptions struct {
*PaginationMeta
Name string `url:"name,omitempty"`
}
// Advance to the specified page in result set, while retaining
// AdvancePage advances to the specified page in result set, while retaining
// the filtering options.
func (l *ListMetricsOptions) AdvancePage(next *PaginationMeta) ListMetricsOptions {
return ListMetricsOptions{
@ -44,6 +53,7 @@ func (l *ListMetricsOptions) AdvancePage(next *PaginationMeta) ListMetricsOption
}
}
// ListMetricsResponse represents the response of a List call against the metrics service.
type ListMetricsResponse struct {
ThisPage *PaginationResponseMeta
NextPage *PaginationMeta
@ -51,7 +61,7 @@ type ListMetricsResponse struct {
// List metrics using the provided options.
//
// Librato API docs: https://www.librato.com/docs/api/#retrieve-metrics
// Librato API docs: https://www.librato.com/docs/api/#list-a-subset-of-metrics
func (m *MetricsService) List(opts *ListMetricsOptions) ([]Metric, *ListMetricsResponse, error) {
u, err := urlWithOptions("metrics", opts)
if err != nil {
@ -83,7 +93,7 @@ func (m *MetricsService) List(opts *ListMetricsOptions) ([]Metric, *ListMetricsR
// Get a metric by name
//
// Librato API docs: https://www.librato.com/docs/api/#retrieve-metric-by-name
// Librato API docs: https://www.librato.com/docs/api/#retrieve-a-metric-by-name
func (m *MetricsService) Get(name string) (*Metric, *http.Response, error) {
u := fmt.Sprintf("metrics/%s", name)
req, err := m.client.NewRequest("GET", u, nil)
@ -100,6 +110,7 @@ func (m *MetricsService) Get(name string) (*Metric, *http.Response, error) {
return metric, resp, err
}
// MeasurementSubmission represents the payload to submit/create a metric.
type MeasurementSubmission struct {
MeasureTime *uint `json:"measure_time,omitempty"`
Source *string `json:"source,omitempty"`
@ -107,6 +118,7 @@ type MeasurementSubmission struct {
Counters []*Measurement `json:"counters,omitempty"`
}
// Measurement represents a Librato Measurement.
type Measurement struct {
Name string `json:"name"`
Value *float64 `json:"value,omitempty"`
@ -114,6 +126,7 @@ type Measurement struct {
Source *string `json:"source,omitempty"`
}
// GaugeMeasurement represents a Librato measurement gauge.
type GaugeMeasurement struct {
*Measurement
Count *uint `json:"count,omitempty"`
@ -125,7 +138,7 @@ type GaugeMeasurement struct {
// Submit metrics
//
// Librato API docs: https://www.librato.com/docs/api/#submit-metrics
// Librato API docs: https://www.librato.com/docs/api/#create-a-measurement
func (m *MetricsService) Submit(measurements *MeasurementSubmission) (*http.Response, error) {
req, err := m.client.NewRequest("POST", "/metrics", measurements)
if err != nil {
@ -137,7 +150,7 @@ func (m *MetricsService) Submit(measurements *MeasurementSubmission) (*http.Resp
// Edit a metric.
//
// Librato API docs: https://www.librato.com/docs/api/#update-metric-by-name
// Librato API docs: https://www.librato.com/docs/api/#update-a-metric-by-name
func (m *MetricsService) Edit(metric *Metric) (*http.Response, error) {
u := fmt.Sprintf("metrics/%s", *metric.Name)
@ -151,7 +164,7 @@ func (m *MetricsService) Edit(metric *Metric) (*http.Response, error) {
// Delete a metric.
//
// Librato API docs: https://www.librato.com/docs/api/#delete-metric-by-name
// Librato API docs: https://www.librato.com/docs/api/#delete-a-metric-by-name
func (m *MetricsService) Delete(name string) (*http.Response, error) {
u := fmt.Sprintf("metrics/%s", name)
req, err := m.client.NewRequest("DELETE", u, nil)

6
vendor/vendor.json vendored
View File

@ -2248,10 +2248,10 @@
"revisionTime": "2016-07-20T23:31:40Z"
},
{
"checksumSHA1": "jq2E42bB0kwKaerHXwJslUea4eM=",
"checksumSHA1": "HtxHX0u0oN+aiTN1Pd67Y4ilMdI=",
"path": "github.com/henrikhodne/go-librato/librato",
"revision": "6e9aa4b1a8a8b735ad14b4f1c9542ef183e82dc2",
"revisionTime": "2016-08-11T07:26:26Z"
"revision": "1bca649ee479cdfcf2e19f30ecb74b6f23345e5a",
"revisionTime": "2017-05-13T14:06:44Z"
},
{
"checksumSHA1": "K6exl2ouL7d8cR2i378EzZOdRVI=",