diff --git a/vendor/github.com/spaceapegames/go-wavefront/Makefile b/vendor/github.com/spaceapegames/go-wavefront/Makefile index 4d29c6f..2794af0 100644 --- a/vendor/github.com/spaceapegames/go-wavefront/Makefile +++ b/vendor/github.com/spaceapegames/go-wavefront/Makefile @@ -1,5 +1,6 @@ TEST?=$$(go list ./... |grep -v 'vendor'|grep -v 'examples') GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor) +VERSION=$$(cat version) default: test @@ -25,3 +26,9 @@ test: fmtcheck go test -i $(TEST) || exit 1 echo $(TEST) | \ xargs -t -n4 go test -v $(TESTARGS) -timeout=30s -parallel=4 +.PHONY: test + +release: + git tag -a $(VERSION) -m "Release version $(VERSION)" + git push --tags +.PHONY: release diff --git a/vendor/github.com/spaceapegames/go-wavefront/alert.go b/vendor/github.com/spaceapegames/go-wavefront/alert.go index 9489740..367dc6b 100644 --- a/vendor/github.com/spaceapegames/go-wavefront/alert.go +++ b/vendor/github.com/spaceapegames/go-wavefront/alert.go @@ -88,6 +88,16 @@ func (c *Client) Alerts() *Alerts { return &Alerts{client: c} } +// Get is used to retrieve an existing Alert by ID. +// The ID field must be provided +func (a Alerts) Get(alert *Alert) error { + if *alert.ID == "" { + return fmt.Errorf("Alert id field is not set") + } + + return a.crudAlert("GET", fmt.Sprintf("%s/%s", baseAlertPath, *alert.ID), alert) +} + // Find returns all alerts filtered by the given search conditions. // If filter is nil, all alerts are returned. func (a Alerts) Find(filter []*SearchCondition) ([]*Alert, error) { diff --git a/vendor/github.com/spaceapegames/go-wavefront/query.go b/vendor/github.com/spaceapegames/go-wavefront/query.go index 2fb7540..3824a3f 100644 --- a/vendor/github.com/spaceapegames/go-wavefront/query.go +++ b/vendor/github.com/spaceapegames/go-wavefront/query.go @@ -77,6 +77,7 @@ type QueryResponse struct { Name string `json:"name"` Granularity int `json:"granularity"` Hosts []string `json:"hostsUsed"` + Warnings string `json:"warnings"` } // DataPoint represents a single timestamp/value data point as returned @@ -85,9 +86,10 @@ type DataPoint []float64 // TimeSeries represents a single TimeSeries as returned by Wavefront type TimeSeries struct { - DataPoints []DataPoint `json:"data"` - Label string `json:"label"` - Host string `json:"host"` + DataPoints []DataPoint `json:"data"` + Label string `json:"label"` + Host string `json:"host"` + Tags map[string]string `json:"tags"` } const ( @@ -204,12 +206,20 @@ func (qr *QueryResponse) UnmarshalJSON(data []byte) error { // in a human-readable format func (qr QueryResponse) String() string { var out string + if qr.Warnings != "" { + out += fmt.Sprintf("Warnings : %s\n", qr.Warnings) + } for _, t := range qr.TimeSeries { if t.Host != "" { out += fmt.Sprintf("%s : %s\n", t.Label, t.Host) } else { out += fmt.Sprintf("%s\n", t.Label) } + if t.Tags != nil { + for k, v := range t.Tags { + out += fmt.Sprintf("%s : %s\n", k, v) + } + } for _, d := range t.DataPoints { out += fmt.Sprintf("%d %f\n", int64(d[0]), d[1]) } diff --git a/vendor/github.com/spaceapegames/go-wavefront/target.go b/vendor/github.com/spaceapegames/go-wavefront/target.go index 702060e..ab81848 100644 --- a/vendor/github.com/spaceapegames/go-wavefront/target.go +++ b/vendor/github.com/spaceapegames/go-wavefront/target.go @@ -62,6 +62,16 @@ func (c *Client) Targets() *Targets { return &Targets{client: c} } +// Get is used to retrieve an existing Target by ID. +// The ID field must be provided +func (t Targets) Get(target *Target) error { + if *target.ID == "" { + return fmt.Errorf("Target id field is not set") + } + + return t.crudTarget("GET", fmt.Sprintf("%s/%s", baseTargetPath, *target.ID), target) +} + // Find returns all targets filtered by the given search conditions. // If filter is nil, all targets are returned. func (t Targets) Find(filter []*SearchCondition) ([]*Target, error) { diff --git a/vendor/vendor.json b/vendor/vendor.json index 0583c70..f14c2d8 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -519,10 +519,10 @@ "revisionTime": "2017-08-08T15:38:46Z" }, { - "checksumSHA1": "9AmOrvtMgYViY18t8BiBPC9oZRY=", + "checksumSHA1": "RfNML/mJrWS8QjuIsN7AWr4lqV4=", "path": "github.com/spaceapegames/go-wavefront", - "revision": "eadca219c8d92f2ebf3badcca3c507c4dce91b4d", - "revisionTime": "2017-12-28T18:24:44Z" + "revision": "53792d0ec4bf66c0f9479499c985442aa2059357", + "revisionTime": "2018-02-23T13:18:49Z" }, { "checksumSHA1": "vE43s37+4CJ2CDU6TlOUOYE0K9c=", diff --git a/wavefront/resource_alert.go b/wavefront/resource_alert.go index ca7e45a..10eda42 100644 --- a/wavefront/resource_alert.go +++ b/wavefront/resource_alert.go @@ -101,35 +101,25 @@ func resourceAlertCreate(d *schema.ResourceData, m interface{}) error { func resourceAlertRead(d *schema.ResourceData, m interface{}) error { alerts := m.(*wavefrontClient).client.Alerts() - // search for an alert with our id. We should recieve 1 (Exact Match) or 0 (No Match) - results, err := alerts.Find( - []*wavefront.SearchCondition{ - { - Key: "id", - Value: d.Id(), - MatchingMethod: "EXACT", - }, - }) + alertID := d.Id() + tmpAlert := wavefront.Alert{ID: &alertID} + err := alerts.Get(&tmpAlert) if err != nil { - return fmt.Errorf("Error finding Wavefront Alert %s. %s", d.Id(), err) - } - // resource has been deleted out of band. So unset ID - if len(results) != 1 { d.SetId("") - return nil + return fmt.Errorf("Error finding Wavefront Alert %s. %s", d.Id(), err) } // Use the Wavefront ID as the Terraform ID - d.SetId(*results[0].ID) - d.Set("name", results[0].Name) - d.Set("target", results[0].Target) - d.Set("condition", results[0].Condition) - d.Set("additional_information", results[0].AdditionalInfo) - d.Set("display_expression", results[0].DisplayExpression) - d.Set("minutes", results[0].Minutes) - d.Set("resolve_after_minutes", results[0].ResolveAfterMinutes) - d.Set("severity", results[0].Severity) - d.Set("tags", results[0].Tags) + d.SetId(*tmpAlert.ID) + d.Set("name", tmpAlert.Name) + d.Set("target", tmpAlert.Target) + d.Set("condition", tmpAlert.Condition) + d.Set("additional_information", tmpAlert.AdditionalInfo) + d.Set("display_expression", tmpAlert.DisplayExpression) + d.Set("minutes", tmpAlert.Minutes) + d.Set("resolve_after_minutes", tmpAlert.ResolveAfterMinutes) + d.Set("severity", tmpAlert.Severity) + d.Set("tags", tmpAlert.Tags) return nil } @@ -137,14 +127,9 @@ func resourceAlertRead(d *schema.ResourceData, m interface{}) error { func resourceAlertUpdate(d *schema.ResourceData, m interface{}) error { alerts := m.(*wavefrontClient).client.Alerts() - results, err := alerts.Find( - []*wavefront.SearchCondition{ - { - Key: "id", - Value: d.Id(), - MatchingMethod: "EXACT", - }, - }) + alertID := d.Id() + tmpAlert := wavefront.Alert{ID: &alertID} + err := alerts.Get(&tmpAlert) if err != nil { return fmt.Errorf("Error finding Wavefront Alert %s. %s", d.Id(), err) } @@ -154,7 +139,7 @@ func resourceAlertUpdate(d *schema.ResourceData, m interface{}) error { tags = append(tags, tag.(string)) } - a := results[0] + a := tmpAlert a.Name = d.Get("name").(string) a.Target = d.Get("target").(string) a.Condition = d.Get("condition").(string) @@ -166,7 +151,7 @@ func resourceAlertUpdate(d *schema.ResourceData, m interface{}) error { a.Tags = tags // Update the alert on Wavefront - err = alerts.Update(a) + err = alerts.Update(&a) if err != nil { return fmt.Errorf("Error Updating Alert %s. %s", d.Get("name"), err) } @@ -176,21 +161,16 @@ func resourceAlertUpdate(d *schema.ResourceData, m interface{}) error { func resourceAlertDelete(d *schema.ResourceData, m interface{}) error { alerts := m.(*wavefrontClient).client.Alerts() - results, err := alerts.Find( - []*wavefront.SearchCondition{ - &wavefront.SearchCondition{ - Key: "id", - Value: d.Id(), - MatchingMethod: "EXACT", - }, - }) + alertID := d.Id() + tmpAlert := wavefront.Alert{ID: &alertID} + err := alerts.Get(&tmpAlert) if err != nil { return fmt.Errorf("Error finding Wavefront Alert %s. %s", d.Id(), err) } - a := results[0] + a := tmpAlert // Delete the Alert - err = alerts.Delete(a) + err = alerts.Delete(&a) if err != nil { return fmt.Errorf("Failed to delete Alert %s. %s", d.Id(), err) } diff --git a/wavefront/resource_alert_target.go b/wavefront/resource_alert_target.go index f0a072d..5864436 100644 --- a/wavefront/resource_alert_target.go +++ b/wavefront/resource_alert_target.go @@ -102,35 +102,24 @@ func resourceTargetCreate(d *schema.ResourceData, m interface{}) error { func resourceTargetRead(d *schema.ResourceData, m interface{}) error { targets := m.(*wavefrontClient).client.Targets() - // search for a Target with our id. We should recieve 1 (Exact Match) or 0 (No Match) - results, err := targets.Find( - []*wavefront.SearchCondition{ - { - Key: "id", - Value: d.Id(), - MatchingMethod: "EXACT", - }, - }) + targetID := d.Id() + tmpTarget := wavefront.Target{ID: &targetID} + err := targets.Get(&tmpTarget) if err != nil { return fmt.Errorf("Error finding Wavefront Target %s. %s", d.Id(), err) } - // resource has been deleted out of band. So unset ID - if len(results) != 1 { - d.SetId("") - return nil - } // Use the Wavefront ID as the Terraform ID - d.SetId(*results[0].ID) - d.Set("name", results[0].Title) - d.Set("description", results[0].Description) - d.Set("triggers", results[0].Triggers) - d.Set("template", results[0].Template) - d.Set("method", results[0].Method) - d.Set("recipient", results[0].Recipient) - d.Set("email_subject", results[0].EmailSubject) - d.Set("content_type", results[0].ContentType) - d.Set("custom_headers", results[0].CustomHeaders) + d.SetId(*tmpTarget.ID) + d.Set("name", tmpTarget.Title) + d.Set("description", tmpTarget.Description) + d.Set("triggers", tmpTarget.Triggers) + d.Set("template", tmpTarget.Template) + d.Set("method", tmpTarget.Method) + d.Set("recipient", tmpTarget.Recipient) + d.Set("email_subject", tmpTarget.EmailSubject) + d.Set("content_type", tmpTarget.ContentType) + d.Set("custom_headers", tmpTarget.CustomHeaders) return nil } diff --git a/wavefront/resource_alert_test.go b/wavefront/resource_alert_test.go index c4af3cf..25bbca0 100644 --- a/wavefront/resource_alert_test.go +++ b/wavefront/resource_alert_test.go @@ -41,11 +41,17 @@ func TestAccWavefrontAlert_Basic(t *testing.T) { resource.TestCheckResourceAttr( "wavefront_alert.test_alert", "severity", "WARN"), resource.TestCheckResourceAttr( - "wavefront_alert.test_alert", "tags.#", "2"), + "wavefront_alert.test_alert", "tags.#", "5"), resource.TestCheckResourceAttr( - "wavefront_alert.test_alert", "tags.0", "terraform"), + "wavefront_alert.test_alert", "tags.0", "b"), resource.TestCheckResourceAttr( - "wavefront_alert.test_alert", "tags.1", "test"), + "wavefront_alert.test_alert", "tags.1", "terraform"), + resource.TestCheckResourceAttr( + "wavefront_alert.test_alert", "tags.2", "c"), + resource.TestCheckResourceAttr( + "wavefront_alert.test_alert", "tags.3", "test"), + resource.TestCheckResourceAttr( + "wavefront_alert.test_alert", "tags.4", "a"), ), }, }, @@ -151,8 +157,6 @@ func TestAccWavefrontAlert_RemoveOptionalAttribute(t *testing.T) { }) } -//Fails due to Wavefront known issue - creating multiple tagged alerts causes a race condition. Only one will succeed. -//Uncomment when that is fixed. func TestAccWavefrontAlert_Multiple(t *testing.T) { var record wavefront.Alert @@ -187,18 +191,10 @@ func testAccCheckWavefrontAlertDestroy(s *terraform.State) error { continue } - results, err := alerts.Find( - []*wavefront.SearchCondition{ - { - Key: "id", - Value: rs.Primary.ID, - MatchingMethod: "EXACT", - }, - }) - if err != nil { - return fmt.Errorf("Error finding Wavefront Alert. %s", err) - } - if len(results) > 0 { + tmpAlert := wavefront.Alert{ID: &rs.Primary.ID} + + err := alerts.Get(&tmpAlert) + if err == nil { return fmt.Errorf("Alert still exists") } } @@ -263,27 +259,14 @@ func testAccCheckWavefrontAlertExists(n string, alert *wavefront.Alert) resource } alerts := testAccProvider.Meta().(*wavefrontClient).client.Alerts() + tmpAlert := wavefront.Alert{ID: &rs.Primary.ID} - results, err := alerts.Find( - []*wavefront.SearchCondition{ - { - Key: "id", - Value: rs.Primary.ID, - MatchingMethod: "EXACT", - }, - }) + err := alerts.Get(&tmpAlert) if err != nil { return fmt.Errorf("Error finding Wavefront Alert %s", err) } - // resource has been deleted out of band. So unset ID - if len(results) != 1 { - return fmt.Errorf("No Alerts Found") - } - if *results[0].ID != rs.Primary.ID { - return fmt.Errorf("Alert not found") - } - *alert = *results[0] + *alert = tmpAlert return nil } @@ -301,8 +284,11 @@ resource "wavefront_alert" "test_alert" { resolve_after_minutes = 5 severity = "WARN" tags = [ + "b", "terraform", - "test" + "c", + "test", + "a" ] } `) diff --git a/wavefront/resource_dashboard_test.go b/wavefront/resource_dashboard_test.go index 1364757..ee82107 100644 --- a/wavefront/resource_dashboard_test.go +++ b/wavefront/resource_dashboard_test.go @@ -309,11 +309,15 @@ func TestAccWavefrontDashboard_Basic(t *testing.T) { resource.TestCheckResourceAttr( "wavefront_dashboard.test_dashboard", "parameter_details.0.values_to_readable_strings.Label", "test"), resource.TestCheckResourceAttr( - "wavefront_dashboard.test_dashboard", "tags.#", "2"), + "wavefront_dashboard.test_dashboard", "tags.#", "4"), resource.TestCheckResourceAttr( - "wavefront_dashboard.test_dashboard", "tags.0", "terraform"), + "wavefront_dashboard.test_dashboard", "tags.0", "b"), resource.TestCheckResourceAttr( - "wavefront_dashboard.test_dashboard", "tags.1", "test"), + "wavefront_dashboard.test_dashboard", "tags.1", "terraform"), + resource.TestCheckResourceAttr( + "wavefront_dashboard.test_dashboard", "tags.2", "a"), + resource.TestCheckResourceAttr( + "wavefront_dashboard.test_dashboard", "tags.3", "test"), ), }, }, @@ -650,7 +654,9 @@ resource "wavefront_dashboard" "test_dashboard" { } } tags = [ + "b", "terraform", + "a", "test" ] } @@ -688,7 +694,9 @@ resource "wavefront_dashboard" "test_dashboard" { } } tags = [ + "b", "terraform", + "a", "test" ] }