From 982a0658637de6ce154d1e9063522239eb86e8cb Mon Sep 17 00:00:00 2001 From: Colin Saliceti Date: Tue, 4 Oct 2016 16:46:13 +0100 Subject: [PATCH 1/4] Update go-datadog-api vendored dependency --- .../zorkian/go-datadog-api/.gitignore | 2 -- .../zorkian/go-datadog-api/.travis.yml | 21 ------------------ .../zorkian/go-datadog-api/README.md | 3 ++- .../zorkian/go-datadog-api/checks_test.go | 22 ------------------- .../zorkian/go-datadog-api/dashboards.go | 21 ++++++++++++------ .../zorkian/go-datadog-api/users.go | 19 ++++++++++++++++ vendor/vendor.json | 4 +++- 7 files changed, 38 insertions(+), 54 deletions(-) delete mode 100644 vendor/github.com/zorkian/go-datadog-api/.gitignore delete mode 100644 vendor/github.com/zorkian/go-datadog-api/.travis.yml delete mode 100644 vendor/github.com/zorkian/go-datadog-api/checks_test.go diff --git a/vendor/github.com/zorkian/go-datadog-api/.gitignore b/vendor/github.com/zorkian/go-datadog-api/.gitignore deleted file mode 100644 index d2631dc6b..000000000 --- a/vendor/github.com/zorkian/go-datadog-api/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.sublime* -cmd diff --git a/vendor/github.com/zorkian/go-datadog-api/.travis.yml b/vendor/github.com/zorkian/go-datadog-api/.travis.yml deleted file mode 100644 index 09e2201d4..000000000 --- a/vendor/github.com/zorkian/go-datadog-api/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: go - -go: - - 1.5 - - 1.6 - - tip - -env: - - "PATH=/home/travis/gopath/bin:$PATH" -script: - - go get -u github.com/golang/lint/golint - - golint ./... - - test `gofmt -l . | wc -l` = 0 - - make test - -install: - - go get -v -t . && make updatedeps - -matrix: - allow_failures: - - go: tip diff --git a/vendor/github.com/zorkian/go-datadog-api/README.md b/vendor/github.com/zorkian/go-datadog-api/README.md index 89cd20d10..d3d95d29e 100644 --- a/vendor/github.com/zorkian/go-datadog-api/README.md +++ b/vendor/github.com/zorkian/go-datadog-api/README.md @@ -12,6 +12,7 @@ mostly used for automating dashboards/alerting and retrieving data (events, etc) The source API documentation is here: + ## USAGE To use this project, include it in your code like: @@ -24,7 +25,7 @@ Then, you can work with it: ``` go client := datadog.NewClient("api key", "application key") - + dash, err := client.GetDashboard(10880) if err != nil { log.Fatalf("fatal: %s\n", err) diff --git a/vendor/github.com/zorkian/go-datadog-api/checks_test.go b/vendor/github.com/zorkian/go-datadog-api/checks_test.go deleted file mode 100644 index 135ee5def..000000000 --- a/vendor/github.com/zorkian/go-datadog-api/checks_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package datadog_test - -import ( - "testing" - - "github.com/zorkian/go-datadog-api" -) - -func TestCheckStatus(T *testing.T) { - if datadog.OK != 0 { - T.Error("status OK must be 0 to satisfy Datadog's API") - } - if datadog.WARNING != 1 { - T.Error("status WARNING must be 1 to satisfy Datadog's API") - } - if datadog.CRITICAL != 2 { - T.Error("status CRITICAL must be 2 to satisfy Datadog's API") - } - if datadog.UNKNOWN != 3 { - T.Error("status UNKNOWN must be 3 to satisfy Datadog's API") - } -} diff --git a/vendor/github.com/zorkian/go-datadog-api/dashboards.go b/vendor/github.com/zorkian/go-datadog-api/dashboards.go index 25985ba20..5da7332cf 100644 --- a/vendor/github.com/zorkian/go-datadog-api/dashboards.go +++ b/vendor/github.com/zorkian/go-datadog-api/dashboards.go @@ -12,18 +12,25 @@ import ( "fmt" ) +// GraphDefinitionRequest represents the requests passed into each graph. +type GraphDefinitionRequest struct { + Query string `json:"q"` + Stacked bool `json:"stacked"` + Aggregator string + ConditionalFormats []DashboardConditionalFormat `json:"conditional_formats,omitempty"` + Type string `json:"type,omitempty"` + Style struct { + Palette string `json:"palette,omitempty"` + } `json:"style,omitempty"` +} + // Graph represents a graph that might exist on a dashboard. type Graph struct { Title string `json:"title"` Events []struct{} `json:"events"` Definition struct { - Viz string `json:"viz"` - Requests []struct { - Query string `json:"q"` - Stacked bool `json:"stacked"` - Aggregator string - ConditionalFormats []DashboardConditionalFormat `json:"conditional_formats,omitempty"` - } `json:"requests"` + Viz string `json:"viz"` + Requests []GraphDefinitionRequest `json:"requests"` } `json:"definition"` } diff --git a/vendor/github.com/zorkian/go-datadog-api/users.go b/vendor/github.com/zorkian/go-datadog-api/users.go index 76b4da573..ba7f69571 100644 --- a/vendor/github.com/zorkian/go-datadog-api/users.go +++ b/vendor/github.com/zorkian/go-datadog-api/users.go @@ -29,6 +29,25 @@ func (self *Client) InviteUsers(emails []string) error { reqInviteUsers{Emails: emails}, nil) } +// CreateUser creates an user account for an email address +func (self *Client) CreateUser(handle, name string) (*User, error) { + in := struct { + Handle string `json:"handle"` + Name string `json:"name"` + }{ + Handle: handle, + Name: name, + } + + out := struct { + *User `json:"user"` + }{} + if err := self.doJsonRequest("POST", "/v1/user", in, &out); err != nil { + return nil, err + } + return out.User, nil +} + // internal type to retrieve users from the api type usersData struct { Users []User `json:"users"` diff --git a/vendor/vendor.json b/vendor/vendor.json index 4767aaaa9..0c8389337 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1951,8 +1951,10 @@ "revision": "75ce5fbba34b1912a3641adbd58cf317d7315821" }, { + "checksumSHA1": "jBiNbkwHKwnuGfkaccnLc/1rzto=", "path": "github.com/zorkian/go-datadog-api", - "revision": "af9919d4fd020eba6daada1cbba9310f5d7b44a8" + "revision": "f9f89391f35f5c8eafed4b75b5797b9b23851908", + "revisionTime": "2016-10-04T18:54:04Z" }, { "path": "golang.org/x/crypto/curve25519", From b53d7a7b493033cf5c8bee0f4d86892c56719ce2 Mon Sep 17 00:00:00 2001 From: Colin Saliceti Date: Mon, 3 Oct 2016 12:15:01 +0100 Subject: [PATCH 2/4] Use new Datadog GraphDefinitionRequest struct This new struct avoids requiring to repeat the struct definition in this code here. It avoids duplication and makes it more flexible so more options can be added to the struct without breaking the code here. --- builtin/providers/datadog/resource_datadog_timeboard.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/builtin/providers/datadog/resource_datadog_timeboard.go b/builtin/providers/datadog/resource_datadog_timeboard.go index d7e726745..e39c918f0 100644 --- a/builtin/providers/datadog/resource_datadog_timeboard.go +++ b/builtin/providers/datadog/resource_datadog_timeboard.go @@ -119,12 +119,9 @@ func buildTemplateVariables(terraformTemplateVariables *[]interface{}) *[]datado func appendRequests(datadogGraph *datadog.Graph, terraformRequests *[]interface{}) { for _, t_ := range *terraformRequests { t := t_.(map[string]interface{}) - d := struct { - Query string `json:"q"` - Stacked bool `json:"stacked"` - Aggregator string - ConditionalFormats []datadog.DashboardConditionalFormat `json:"conditional_formats,omitempty"` - }{Query: t["q"].(string)} + d := datadog.GraphDefinitionRequest{ + Query: t["q"].(string), + } if stacked, ok := t["stacked"]; ok { d.Stacked = stacked.(bool) } From cae5d8bbb9483aea0bad016d231c2a936ef979c5 Mon Sep 17 00:00:00 2001 From: Colin Saliceti Date: Mon, 3 Oct 2016 16:18:18 +0100 Subject: [PATCH 3/4] Add type and styles to datadog timeboard graphs Create the resources for title and styles and add them to the acceptance test. Styles currently only support "palette". --- .../datadog/resource_datadog_timeboard.go | 16 ++++++++++++++++ .../datadog/resource_datadog_timeboard_test.go | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/builtin/providers/datadog/resource_datadog_timeboard.go b/builtin/providers/datadog/resource_datadog_timeboard.go index e39c918f0..0597365e5 100644 --- a/builtin/providers/datadog/resource_datadog_timeboard.go +++ b/builtin/providers/datadog/resource_datadog_timeboard.go @@ -26,6 +26,15 @@ func resourceDatadogTimeboard() *schema.Resource { Optional: true, Default: false, }, + "type": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Default: "line", + }, + "style": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + }, }, }, } @@ -121,10 +130,17 @@ func appendRequests(datadogGraph *datadog.Graph, terraformRequests *[]interface{ t := t_.(map[string]interface{}) d := datadog.GraphDefinitionRequest{ Query: t["q"].(string), + Type: t["type"].(string), } if stacked, ok := t["stacked"]; ok { d.Stacked = stacked.(bool) } + if style, ok := t["style"]; ok { + s, _ := style.(map[string]interface{}) + if palette, ok := s["palette"]; ok { + d.Style.Palette = palette.(string) + } + } datadogGraph.Definition.Requests = append(datadogGraph.Definition.Requests, d) } } diff --git a/builtin/providers/datadog/resource_datadog_timeboard_test.go b/builtin/providers/datadog/resource_datadog_timeboard_test.go index e64de47cb..bd2dc7246 100644 --- a/builtin/providers/datadog/resource_datadog_timeboard_test.go +++ b/builtin/providers/datadog/resource_datadog_timeboard_test.go @@ -47,6 +47,13 @@ resource "datadog_timeboard" "acceptance_test" { request { q = "avg:redis.mem.rss{$host}" } + request { + q = "avg:redis.mem.rss{$host}" + type = "bars" + style { + palette = "warm" + } + } } template_variable { name = "host" @@ -86,6 +93,8 @@ func TestAccDatadogTimeboard_update(t *testing.T) { resource.TestCheckResourceAttr("datadog_timeboard.acceptance_test", "graph.1.request.1.q", "avg:redis.mem.rss{$host}"), resource.TestCheckResourceAttr("datadog_timeboard.acceptance_test", "template_variable.0.name", "host"), resource.TestCheckResourceAttr("datadog_timeboard.acceptance_test", "template_variable.0.prefix", "host"), + resource.TestCheckResourceAttr("datadog_timeboard.acceptance_test", "graph.1.request.2.type", "bars"), + resource.TestCheckResourceAttr("datadog_timeboard.acceptance_test", "graph.1.request.2.style.palette", "warm"), ), } From b36318f1840a0b91ff83a66f2d9cbd8cbeaa51af Mon Sep 17 00:00:00 2001 From: Colin Saliceti Date: Tue, 4 Oct 2016 11:17:23 +0100 Subject: [PATCH 4/4] Document datadog style and palette options --- .../docs/providers/datadog/r/timeboard.html.markdown | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/website/source/docs/providers/datadog/r/timeboard.html.markdown b/website/source/docs/providers/datadog/r/timeboard.html.markdown index 054f78fc5..d4b4b90a6 100644 --- a/website/source/docs/providers/datadog/r/timeboard.html.markdown +++ b/website/source/docs/providers/datadog/r/timeboard.html.markdown @@ -25,6 +25,7 @@ resource "datadog_timeboard" "redis" { viz = "timeseries" request { q = "avg:redis.info.latency_ms{$host}" + type = "bars" } } @@ -37,6 +38,9 @@ resource "datadog_timeboard" "redis" { } request { q = "avg:redis.mem.rss{$host}" + style { + palette = "warm" + } } } @@ -79,6 +83,14 @@ Nested `graph` `request` blocks have the following structure: * `q` - (Required) The query of the request. Pro tip: Use the JSON tab inside the Datadog UI to help build you query strings. * `stacked` - (Optional) Boolean value to determin if this is this a stacked area graph. Default: false (line chart). +* `type` - (Optional) Choose how to draw the graph. For example: "lines", "bars" or "areas". Default: "lines". +* `style` - (Optional) Nested block to customize the graph style. + +### Nested `style` block + +The nested `style` blocks has the following structure (only `palette` is supported right now): + +* `palette` - (Optional) Color of the line drawn. For example: "classic", "cool", "warm", "purple", "orange" or "gray". Default: "classic". ### Nested `template_variable` blocks