Merge pull request #9228 from alphagov/datadog_dashboard_type_style

Datadog dashboard "type" and "style" options
This commit is contained in:
Paul Stack 2016-10-06 23:24:57 +01:00 committed by GitHub
commit 7bab7f44cb
10 changed files with 78 additions and 60 deletions

View File

@ -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,
},
},
},
}
@ -119,15 +128,19 @@ 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),
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)
}
}

View File

@ -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"),
),
}

View File

@ -1,2 +0,0 @@
*.sublime*
cmd

View File

@ -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

View File

@ -12,6 +12,7 @@ mostly used for automating dashboards/alerting and retrieving data (events, etc)
The source API documentation is here: <http://docs.datadoghq.com/api/>
## 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)

View File

@ -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")
}
}

View File

@ -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"`
}

View File

@ -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"`

4
vendor/vendor.json vendored
View File

@ -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",

View File

@ -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