From bc83cae0e46cbe3ff6d507cf8244a3680c9196d8 Mon Sep 17 00:00:00 2001 From: Roman Laguta Date: Mon, 5 Jun 2017 14:47:15 +0300 Subject: [PATCH] fixed tests. should fail (#14878) * fixed tests. should fail * fixed dd monitor evaluation_delay parameter * updated go-datadog-api.v2 * updated vendor.json --- .../datadog/resource_datadog_monitor.go | 6 +- .../datadog/resource_datadog_monitor_test.go | 10 +-- .../zorkian/go-datadog-api.v2/README.md | 4 +- .../zorkian/go-datadog-api.v2/dashboards.go | 2 +- .../go-datadog-api.v2/datadog-accessors.go | 62 +++++++++++++++++++ .../zorkian/go-datadog-api.v2/downtimes.go | 1 + .../zorkian/go-datadog-api.v2/monitors.go | 1 + .../zorkian/go-datadog-api.v2/request.go | 14 +++++ vendor/vendor.json | 6 +- 9 files changed, 92 insertions(+), 14 deletions(-) diff --git a/builtin/providers/datadog/resource_datadog_monitor.go b/builtin/providers/datadog/resource_datadog_monitor.go index 4aeb0d637d..61b871ca1e 100644 --- a/builtin/providers/datadog/resource_datadog_monitor.go +++ b/builtin/providers/datadog/resource_datadog_monitor.go @@ -169,7 +169,7 @@ func buildMonitorStruct(d *schema.ResourceData) *datadog.Monitor { o.SetNewHostDelay(attr.(int)) } if attr, ok := d.GetOk("evaluation_delay"); ok { - o.SetNewHostDelay(attr.(int)) + o.SetEvaluationDelay(attr.(int)) } if attr, ok := d.GetOk("no_data_timeframe"); ok { o.NoDataTimeframe = datadog.NoDataTimeframe(attr.(int)) @@ -282,7 +282,7 @@ func resourceDatadogMonitorRead(d *schema.ResourceData, meta interface{}) error d.Set("thresholds", thresholds) d.Set("new_host_delay", m.Options.GetNewHostDelay()) - d.Set("evaluation_delay", m.Options.GetNewHostDelay()) + d.Set("evaluation_delay", m.Options.GetEvaluationDelay()) d.Set("notify_no_data", m.Options.GetNotifyNoData()) d.Set("no_data_timeframe", m.Options.NoDataTimeframe) d.Set("renotify_interval", m.Options.GetRenotifyInterval()) @@ -350,7 +350,7 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro o.SetNewHostDelay(attr.(int)) } if attr, ok := d.GetOk("evaluation_delay"); ok { - o.SetNewHostDelay(attr.(int)) + o.SetEvaluationDelay(attr.(int)) } if attr, ok := d.GetOk("no_data_timeframe"); ok { o.NoDataTimeframe = datadog.NoDataTimeframe(attr.(int)) diff --git a/builtin/providers/datadog/resource_datadog_monitor_test.go b/builtin/providers/datadog/resource_datadog_monitor_test.go index f2cce05fb9..d7608a16be 100644 --- a/builtin/providers/datadog/resource_datadog_monitor_test.go +++ b/builtin/providers/datadog/resource_datadog_monitor_test.go @@ -34,7 +34,7 @@ func TestAccDatadogMonitor_Basic(t *testing.T) { resource.TestCheckResourceAttr( "datadog_monitor.foo", "new_host_delay", "600"), resource.TestCheckResourceAttr( - "datadog_monitor.foo", "evaluation_delay", "600"), + "datadog_monitor.foo", "evaluation_delay", "700"), resource.TestCheckResourceAttr( "datadog_monitor.foo", "renotify_interval", "60"), resource.TestCheckResourceAttr( @@ -116,7 +116,7 @@ func TestAccDatadogMonitor_Updated(t *testing.T) { resource.TestCheckResourceAttr( "datadog_monitor.foo", "new_host_delay", "600"), resource.TestCheckResourceAttr( - "datadog_monitor.foo", "evaluation_delay", "600"), + "datadog_monitor.foo", "evaluation_delay", "700"), resource.TestCheckResourceAttr( "datadog_monitor.foo", "renotify_interval", "60"), resource.TestCheckResourceAttr( @@ -158,7 +158,7 @@ func TestAccDatadogMonitor_Updated(t *testing.T) { resource.TestCheckResourceAttr( "datadog_monitor.foo", "new_host_delay", "900"), resource.TestCheckResourceAttr( - "datadog_monitor.foo", "evaluation_delay", "900"), + "datadog_monitor.foo", "evaluation_delay", "800"), resource.TestCheckResourceAttr( "datadog_monitor.foo", "no_data_timeframe", "20"), resource.TestCheckResourceAttr( @@ -294,7 +294,7 @@ resource "datadog_monitor" "foo" { notify_audit = false timeout_h = 60 new_host_delay = 600 - evaluation_delay = 600 + evaluation_delay = 700 include_tags = true require_full_window = true locked = false @@ -393,7 +393,7 @@ resource "datadog_monitor" "foo" { notify_no_data = true new_host_delay = 900 - evaluation_delay = 900 + evaluation_delay = 800 no_data_timeframe = 20 renotify_interval = 40 escalation_message = "the situation has escalated! @pagerduty" diff --git a/vendor/gopkg.in/zorkian/go-datadog-api.v2/README.md b/vendor/gopkg.in/zorkian/go-datadog-api.v2/README.md index 23a746612b..4ba71c085d 100644 --- a/vendor/gopkg.in/zorkian/go-datadog-api.v2/README.md +++ b/vendor/gopkg.in/zorkian/go-datadog-api.v2/README.md @@ -4,7 +4,7 @@ status](https://travis-ci.org/zorkian/go-datadog-api.svg)](https://travis-ci.org # Datadog API in Go -**This is the v2.0 version of the API, and has breaking changes. Use the main or v1.0 branch if you need +**This is the v2.0 version of the API, and has breaking changes. Use the v1.0 branch if you need legacy code to be supported.** A Go wrapper for the Datadog API. Use this library if you need to interact @@ -115,4 +115,4 @@ make generate Please see the LICENSE file for the included license information. -Copyright 2017 by authors and contributors. +Copyright 2013-2017 by authors and contributors. diff --git a/vendor/gopkg.in/zorkian/go-datadog-api.v2/dashboards.go b/vendor/gopkg.in/zorkian/go-datadog-api.v2/dashboards.go index 5f64fbbdfc..6c1d146286 100644 --- a/vendor/gopkg.in/zorkian/go-datadog-api.v2/dashboards.go +++ b/vendor/gopkg.in/zorkian/go-datadog-api.v2/dashboards.go @@ -72,7 +72,7 @@ type GraphDefinition struct { Yaxis Yaxis `json:"yaxis,omitempty"` // For query value type graphs - Autoscale *bool `json:"austoscale,omitempty"` + Autoscale *bool `json:"autoscale,omitempty"` TextAlign *string `json:"text_align,omitempty"` Precision *string `json:"precision,omitempty"` CustomUnit *string `json:"custom_unit,omitempty"` diff --git a/vendor/gopkg.in/zorkian/go-datadog-api.v2/datadog-accessors.go b/vendor/gopkg.in/zorkian/go-datadog-api.v2/datadog-accessors.go index 6c4b8feb48..28e038a070 100644 --- a/vendor/gopkg.in/zorkian/go-datadog-api.v2/datadog-accessors.go +++ b/vendor/gopkg.in/zorkian/go-datadog-api.v2/datadog-accessors.go @@ -3175,6 +3175,37 @@ func (d *Downtime) SetMessage(v string) { d.Message = &v } +// GetMonitorId returns the MonitorId field if non-nil, zero value otherwise. +func (d *Downtime) GetMonitorId() int { + if d == nil || d.MonitorId == nil { + return 0 + } + return *d.MonitorId +} + +// GetOkMonitorId returns a tuple with the MonitorId field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (d *Downtime) GetMonitorIdOk() (int, bool) { + if d == nil || d.MonitorId == nil { + return 0, false + } + return *d.MonitorId, true +} + +// HasMonitorId returns a boolean if a field has been set. +func (d *Downtime) HasMonitorId() bool { + if d != nil && d.MonitorId != nil { + return true + } + + return false +} + +// GetMonitorId allocates a new d.MonitorId and returns the pointer to it. +func (d *Downtime) SetMonitorId(v int) { + d.MonitorId = &v +} + // GetRecurrence returns the Recurrence field if non-nil, zero value otherwise. func (d *Downtime) GetRecurrence() Recurrence { if d == nil || d.Recurrence == nil { @@ -7980,6 +8011,37 @@ func (o *Options) SetEscalationMessage(v string) { o.EscalationMessage = &v } +// GetEvaluationDelay returns the EvaluationDelay field if non-nil, zero value otherwise. +func (o *Options) GetEvaluationDelay() int { + if o == nil || o.EvaluationDelay == nil { + return 0 + } + return *o.EvaluationDelay +} + +// GetOkEvaluationDelay returns a tuple with the EvaluationDelay field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (o *Options) GetEvaluationDelayOk() (int, bool) { + if o == nil || o.EvaluationDelay == nil { + return 0, false + } + return *o.EvaluationDelay, true +} + +// HasEvaluationDelay returns a boolean if a field has been set. +func (o *Options) HasEvaluationDelay() bool { + if o != nil && o.EvaluationDelay != nil { + return true + } + + return false +} + +// GetEvaluationDelay allocates a new o.EvaluationDelay and returns the pointer to it. +func (o *Options) SetEvaluationDelay(v int) { + o.EvaluationDelay = &v +} + // GetIncludeTags returns the IncludeTags field if non-nil, zero value otherwise. func (o *Options) GetIncludeTags() bool { if o == nil || o.IncludeTags == nil { diff --git a/vendor/gopkg.in/zorkian/go-datadog-api.v2/downtimes.go b/vendor/gopkg.in/zorkian/go-datadog-api.v2/downtimes.go index 833264da3a..0e11b57a57 100644 --- a/vendor/gopkg.in/zorkian/go-datadog-api.v2/downtimes.go +++ b/vendor/gopkg.in/zorkian/go-datadog-api.v2/downtimes.go @@ -26,6 +26,7 @@ type Downtime struct { Disabled *bool `json:"disabled,omitempty"` End *int `json:"end,omitempty"` Id *int `json:"id,omitempty"` + MonitorId *int `json:"monitor_id,omitempty"` Message *string `json:"message,omitempty"` Recurrence *Recurrence `json:"recurrence,omitempty"` Scope []string `json:"scope,omitempty"` diff --git a/vendor/gopkg.in/zorkian/go-datadog-api.v2/monitors.go b/vendor/gopkg.in/zorkian/go-datadog-api.v2/monitors.go index 3d22e6adca..51db7792a6 100644 --- a/vendor/gopkg.in/zorkian/go-datadog-api.v2/monitors.go +++ b/vendor/gopkg.in/zorkian/go-datadog-api.v2/monitors.go @@ -44,6 +44,7 @@ type Options struct { NotifyNoData *bool `json:"notify_no_data,omitempty"` RenotifyInterval *int `json:"renotify_interval,omitempty"` NewHostDelay *int `json:"new_host_delay,omitempty"` + EvaluationDelay *int `json:"evaluation_delay,omitempty"` Silenced map[string]int `json:"silenced,omitempty"` TimeoutH *int `json:"timeout_h,omitempty"` EscalationMessage *string `json:"escalation_message,omitempty"` diff --git a/vendor/gopkg.in/zorkian/go-datadog-api.v2/request.go b/vendor/gopkg.in/zorkian/go-datadog-api.v2/request.go index a810334498..cccd414fb6 100644 --- a/vendor/gopkg.in/zorkian/go-datadog-api.v2/request.go +++ b/vendor/gopkg.in/zorkian/go-datadog-api.v2/request.go @@ -110,11 +110,25 @@ func (client *Client) doRequestWithRetries(req *http.Request, maxTime time.Durat err error resp *http.Response bo = backoff.NewExponentialBackOff() + body []byte ) bo.MaxElapsedTime = maxTime + // Save the body for retries + if req.Body != nil { + body, err = ioutil.ReadAll(req.Body) + if err != nil { + return resp, err + } + } + operation := func() error { + if body != nil { + r := bytes.NewReader(body) + req.Body = ioutil.NopCloser(r) + } + resp, err = client.HttpClient.Do(req) if err != nil { return err diff --git a/vendor/vendor.json b/vendor/vendor.json index c3a83ffa38..a06cd3b598 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -3671,10 +3671,10 @@ "revisionTime": "2017-04-07T17:21:22Z" }, { - "checksumSHA1": "OcJdNALtPXoFOieAZjznhm7ufuU=", + "checksumSHA1": "WI/b3b5dn9P+yWQRHd1gOebLxbw=", "path": "gopkg.in/zorkian/go-datadog-api.v2", - "revision": "f005bb24262365e93726b94d89e6cd8a26a7455e", - "revisionTime": "2017-02-20T05:26:33Z" + "revision": "7069eb831c018b4c3f224e42edcad7d9ae3bbeea", + "revisionTime": "2017-05-15T05:26:33Z" }, { "checksumSHA1": "ULdgobdOiXg/nZoZ/gxfU2DBiOk=",