Skip to content

Commit

Permalink
provider/librato: Update based on Librato API changes (#15060)
Browse files Browse the repository at this point in the history
* Update the vendored librato client

* Update librato API endpoints

- update API methods
- fix a few lint errors
  • Loading branch information
wchrisjohnson authored and stack72 committed Jun 5, 2017
1 parent e4c0d85 commit 85bf9c3
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 71 deletions.
50 changes: 25 additions & 25 deletions resource_librato_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,74 +23,74 @@ func resourceLibratoAlert() *schema.Resource {
Delete: resourceLibratoAlertDelete,

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: false,
},
"description": &schema.Schema{
"description": {
Type: schema.TypeString,
Optional: true,
},
"active": &schema.Schema{
"active": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"rearm_seconds": &schema.Schema{
"rearm_seconds": {
Type: schema.TypeInt,
Optional: true,
Default: 600,
},
"services": &schema.Schema{
"services": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"condition": &schema.Schema{
"condition": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
},
"metric_name": &schema.Schema{
"metric_name": {
Type: schema.TypeString,
Required: true,
},
"source": &schema.Schema{
"source": {
Type: schema.TypeString,
Optional: true,
},
"detect_reset": &schema.Schema{
"detect_reset": {
Type: schema.TypeBool,
Optional: true,
},
"duration": &schema.Schema{
"duration": {
Type: schema.TypeInt,
Optional: true,
},
"threshold": &schema.Schema{
"threshold": {
Type: schema.TypeFloat,
Optional: true,
},
"summary_function": &schema.Schema{
"summary_function": {
Type: schema.TypeString,
Optional: true,
},
},
},
Set: resourceLibratoAlertConditionsHash,
},
"attributes": &schema.Schema{
"attributes": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"runbook_url": &schema.Schema{
"runbook_url": {
Type: schema.TypeString,
Optional: true,
},
Expand All @@ -112,9 +112,9 @@ func resourceLibratoAlertConditionsHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", source.(string)))
}

detect_reset, present := m["detect_reset"]
detectReset, present := m["detect_reset"]
if present {
buf.WriteString(fmt.Sprintf("%t-", detect_reset.(bool)))
buf.WriteString(fmt.Sprintf("%t-", detectReset.(bool)))
}

duration, present := m["duration"]
Expand All @@ -127,9 +127,9 @@ func resourceLibratoAlertConditionsHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%f-", threshold.(float64)))
}

summary_function, present := m["summary_function"]
summaryFunction, present := m["summary_function"]
if present {
buf.WriteString(fmt.Sprintf("%s-", summary_function.(string)))
buf.WriteString(fmt.Sprintf("%s-", summaryFunction.(string)))
}

return hashcode.String(buf.String())
Expand Down Expand Up @@ -413,9 +413,9 @@ func resourceLibratoAlertUpdate(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[INFO] Updating Librato alert: %s", alert)
_, err = client.Alerts.Edit(uint(alertID), alert)
if err != nil {
return fmt.Errorf("Error updating Librato alert: %s", err)
_, updErr := client.Alerts.Update(uint(alertID), alert)
if updErr != nil {
return fmt.Errorf("Error updating Librato alert: %s", updErr)
}

log.Printf("[INFO] Updated Librato alert %d", alertID)
Expand All @@ -429,9 +429,9 @@ func resourceLibratoAlertUpdate(d *schema.ResourceData, meta interface{}) error
ContinuousTargetOccurence: 5,
Refresh: func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking if Librato Alert %d was updated yet", alertID)
changedAlert, _, err := client.Alerts.Get(uint(alertID))
if err != nil {
return changedAlert, "", err
changedAlert, _, getErr := client.Alerts.Get(uint(alertID))
if getErr != nil {
return changedAlert, "", getErr
}
isEqual := reflect.DeepEqual(*fullAlert, *changedAlert)
log.Printf("[DEBUG] Updated Librato Alert %d match: %t", alertID, isEqual)
Expand Down
4 changes: 2 additions & 2 deletions resource_librato_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func resourceLibratoMetricCreate(d *schema.ResourceData, meta interface{}) error
metric.Attributes = attributes
}

_, err := client.Metrics.Edit(&metric)
_, err := client.Metrics.Update(&metric)
if err != nil {
log.Printf("[INFO] ERROR creating Metric: %s", err)
return fmt.Errorf("Error creating Librato metric: %s", err)
Expand Down Expand Up @@ -280,7 +280,7 @@ func resourceLibratoMetricUpdate(d *schema.ResourceData, meta interface{}) error

log.Printf("[INFO] Updating Librato metric: %v", structToString(metric))

_, err := client.Metrics.Edit(metric)
_, err := client.Metrics.Update(metric)
if err != nil {
return fmt.Errorf("Error updating Librato metric: %s", err)
}
Expand Down
32 changes: 16 additions & 16 deletions resource_librato_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ func resourceLibratoService() *schema.Resource {
Delete: resourceLibratoServiceDelete,

Schema: map[string]*schema.Schema{
"id": &schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"type": &schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"title": &schema.Schema{
"title": {
Type: schema.TypeString,
Required: true,
},
"settings": &schema.Schema{
"settings": {
Type: schema.TypeString,
Required: true,
StateFunc: normalizeJson,
StateFunc: normalizeJSON,
},
},
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func resourceLibratoServicesFlatten(settings map[string]string) (string, error)
return string(byteArray), nil
}

func normalizeJson(jsonString interface{}) string {
func normalizeJSON(jsonString interface{}) string {
if jsonString == nil || jsonString == "" {
return ""
}
Expand All @@ -91,9 +91,9 @@ func resourceLibratoServiceCreate(d *schema.ResourceData, meta interface{}) erro
service.Title = librato.String(v.(string))
}
if v, ok := d.GetOk("settings"); ok {
res, err := resourceLibratoServicesExpandSettings(normalizeJson(v.(string)))
if err != nil {
return fmt.Errorf("Error expanding Librato service settings: %s", err)
res, expandErr := resourceLibratoServicesExpandSettings(normalizeJSON(v.(string)))
if expandErr != nil {
return fmt.Errorf("Error expanding Librato service settings: %s", expandErr)
}
service.Settings = res
}
Expand Down Expand Up @@ -174,16 +174,16 @@ func resourceLibratoServiceUpdate(d *schema.ResourceData, meta interface{}) erro
fullService.Title = service.Title
}
if d.HasChange("settings") {
res, err := resourceLibratoServicesExpandSettings(normalizeJson(d.Get("settings").(string)))
if err != nil {
return fmt.Errorf("Error expanding Librato service settings: %s", err)
res, getErr := resourceLibratoServicesExpandSettings(normalizeJSON(d.Get("settings").(string)))
if getErr != nil {
return fmt.Errorf("Error expanding Librato service settings: %s", getErr)
}
service.Settings = res
fullService.Settings = res
}

log.Printf("[INFO] Updating Librato Service %d: %s", serviceID, service)
_, err = client.Services.Edit(uint(serviceID), service)
_, err = client.Services.Update(uint(serviceID), service)
if err != nil {
return fmt.Errorf("Error updating Librato service: %s", err)
}
Expand All @@ -198,9 +198,9 @@ func resourceLibratoServiceUpdate(d *schema.ResourceData, meta interface{}) erro
ContinuousTargetOccurence: 5,
Refresh: func() (interface{}, string, error) {
log.Printf("[DEBUG] Checking if Librato Service %d was updated yet", serviceID)
changedService, _, err := client.Services.Get(uint(serviceID))
if err != nil {
return changedService, "", err
changedService, _, getErr := client.Services.Get(uint(serviceID))
if getErr != nil {
return changedService, "", getErr
}
isEqual := reflect.DeepEqual(*fullService, *changedService)
log.Printf("[DEBUG] Updated Librato Service %d match: %t", serviceID, isEqual)
Expand Down
6 changes: 3 additions & 3 deletions resource_librato_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ func resourceLibratoSpace() *schema.Resource {
Delete: resourceLibratoSpaceDelete,

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: false,
},
"id": &schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
Expand Down Expand Up @@ -97,7 +97,7 @@ func resourceLibratoSpaceUpdate(d *schema.ResourceData, meta interface{}) error
if d.HasChange("name") {
newName := d.Get("name").(string)
log.Printf("[INFO] Modifying name space attribute for %d: %#v", id, newName)
if _, err = client.Spaces.Edit(uint(id), &librato.Space{Name: &newName}); err != nil {
if _, err = client.Spaces.Update(uint(id), &librato.Space{Name: &newName}); err != nil {
return err
}
}
Expand Down
Loading

0 comments on commit 85bf9c3

Please sign in to comment.