Skip to content

Commit

Permalink
Merge pull request #241 from bkabrda/dashboards-add-metadata
Browse files Browse the repository at this point in the history
Add possibility to get/set metadata of graph requests on screenboards and timeboards
  • Loading branch information
Slavek Kabrda authored May 17, 2019
2 parents 17da6ea + 1c30292 commit 7ae8c23
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 16 deletions.
15 changes: 9 additions & 6 deletions dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ type GraphDefinitionRequest struct {
Style *GraphDefinitionRequestStyle `json:"style,omitempty"`

// For change type graphs
ChangeType *string `json:"change_type,omitempty"`
OrderDirection *string `json:"order_dir,omitempty"`
CompareTo *string `json:"compare_to,omitempty"`
IncreaseGood *bool `json:"increase_good,omitempty"`
OrderBy *string `json:"order_by,omitempty"`
ExtraCol *string `json:"extra_col,omitempty"`
ChangeType *string `json:"change_type,omitempty"`
OrderDirection *string `json:"order_dir,omitempty"`
CompareTo *string `json:"compare_to,omitempty"`
IncreaseGood *bool `json:"increase_good,omitempty"`
OrderBy *string `json:"order_by,omitempty"`
ExtraCol *string `json:"extra_col,omitempty"`
Metadata map[string]GraphDefinitionMetadata `json:"metadata,omitempty"`
}

type GraphDefinitionMetadata TileDefMetadata

type GraphDefinitionMarker struct {
Type *string `json:"type,omitempty"`
Value *string `json:"value,omitempty"`
Expand Down
31 changes: 31 additions & 0 deletions datadog-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15824,6 +15824,37 @@ func (t *TileDefMarker) SetValue(v string) {
t.Value = &v
}

// GetAlias returns the Alias field if non-nil, zero value otherwise.
func (t *TileDefMetadata) GetAlias() string {
if t == nil || t.Alias == nil {
return ""
}
return *t.Alias
}

// GetAliasOk returns a tuple with the Alias field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (t *TileDefMetadata) GetAliasOk() (string, bool) {
if t == nil || t.Alias == nil {
return "", false
}
return *t.Alias, true
}

// HasAlias returns a boolean if a field has been set.
func (t *TileDefMetadata) HasAlias() bool {
if t != nil && t.Alias != nil {
return true
}

return false
}

// SetAlias allocates a new t.Alias and returns the pointer to it.
func (t *TileDefMetadata) SetAlias(v string) {
t.Alias = &v
}

// GetAggregator returns the Aggregator field if non-nil, zero value otherwise.
func (t *TileDefRequest) GetAggregator() string {
if t == nil || t.Aggregator == nil {
Expand Down
7 changes: 6 additions & 1 deletion integration/dashboards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,18 @@ func createAdvancedTimeseriesGraph() []datadog.Graph {

func createCustomGraph() []datadog.Graph {
gd := &datadog.GraphDefinition{}
gd.SetViz("query_value")
gd.SetViz("timeseries")

r := gd.Requests
gd.Requests = append(r, datadog.GraphDefinitionRequest{
Query: datadog.String("( sum:system.mem.used{*} / sum:system.mem.free{*} ) * 100"),
Stacked: datadog.Bool(false),
Aggregator: datadog.String("avg"),
Metadata: map[string]datadog.GraphDefinitionMetadata{
"(sum:system.mem.used{*}/sum:system.mem.free{*})*100": {
Alias: datadog.String("mem_used_ratio"),
},
},
ConditionalFormats: []datadog.DashboardConditionalFormat{
{
Comparator: datadog.String(">"),
Expand Down
5 changes: 5 additions & 0 deletions integration/screen_widgets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func TestWidgets(t *testing.T) {
Type: datadog.String("dashed"),
Width: datadog.String("thin"),
},
Metadata: map[string]datadog.TileDefMetadata{
"avg:system.cpu.user{*}": {
Alias: datadog.String("avg_cpu"),
},
},
}},
Markers: []datadog.TileDefMarker{{
Label: datadog.String("test marker"),
Expand Down
23 changes: 14 additions & 9 deletions screen_widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ type TileDefRequest struct {
TagFilters []*string `json:"tag_filters"`
Limit *int `json:"limit,omitempty"`

ConditionalFormats []ConditionalFormat `json:"conditional_formats,omitempty"`
Style *TileDefRequestStyle `json:"style,omitempty"`
Aggregator *string `json:"aggregator,omitempty"`
CompareTo *string `json:"compare_to,omitempty"`
ChangeType *string `json:"change_type,omitempty"`
OrderBy *string `json:"order_by,omitempty"`
OrderDir *string `json:"order_dir,omitempty"`
ExtraCol *string `json:"extra_col,omitempty"`
IncreaseGood *bool `json:"increase_good,omitempty"`
ConditionalFormats []ConditionalFormat `json:"conditional_formats,omitempty"`
Style *TileDefRequestStyle `json:"style,omitempty"`
Aggregator *string `json:"aggregator,omitempty"`
CompareTo *string `json:"compare_to,omitempty"`
ChangeType *string `json:"change_type,omitempty"`
OrderBy *string `json:"order_by,omitempty"`
OrderDir *string `json:"order_dir,omitempty"`
ExtraCol *string `json:"extra_col,omitempty"`
IncreaseGood *bool `json:"increase_good,omitempty"`
Metadata map[string]TileDefMetadata `json:"metadata,omitempty"`
}

type TileDefMetadata struct {
Alias *string `json:"alias,omitempty"`
}

type ConditionalFormat struct {
Expand Down

0 comments on commit 7ae8c23

Please sign in to comment.