Skip to content

Commit

Permalink
Merge pull request #65 from K-Phoen/strackdriver-target
Browse files Browse the repository at this point in the history
Strackdriver target
  • Loading branch information
K-Phoen authored Apr 21, 2020
2 parents 9c84017 + 58e1b0d commit 84eb643
Show file tree
Hide file tree
Showing 21 changed files with 1,275 additions and 25 deletions.
18 changes: 18 additions & 0 deletions cmd/yaml/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ rows:
thresholds: ["26000000", "28000000"]
color: ["value"]

- name: Stackdriver
panels:
- graph:
title: Pubsub Ack msg count
datasource: voi-stage-stackdriver
targets:
- stackdriver:
ref: A
legend: Ack-ed messages
type: delta
metric: pubsub.googleapis.com/subscription/ack_message_count
aggregation: mean
alignment: {method: delta, period: stackdriver-auto}
filters:
eq:
resource.label.subscription_id: "awesome_subscription_id"
resource.type: pubsub_subscription

- name: "Some text, because it might be useful"
panels:
- text:
Expand Down
317 changes: 317 additions & 0 deletions decoder/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestUnmarshalYAML(t *testing.T) {
graphPanel(),
singleStatPanel(),
tablePanel(),
graphPanelWithStackdriverTarget(),
}

for _, testCase := range testCases {
Expand Down Expand Up @@ -257,6 +258,48 @@ rows:
require.Equal(t, ErrInvalidAlertValueFunc, err)
}

func TestUnmarshalYAMLWithInvalidStackdriverAggregation(t *testing.T) {
payload := `
rows:
- name: Test row
panels:
- graph:
title: Pubsub Ack msg count
datasource: stackdriver-default
targets:
- stackdriver:
type: delta
metric: pubsub.googleapis.com/subscription/ack_message_count
aggregation: invalid
`

_, err := UnmarshalYAML(bytes.NewBufferString(payload))

require.Error(t, err)
require.Equal(t, ErrInvalidStackdriverAggregation, err)
}

func TestUnmarshalYAMLWithInvalidStackdriverAlignmentMethod(t *testing.T) {
payload := `
rows:
- name: Test row
panels:
- graph:
title: Pubsub Ack msg count
datasource: stackdriver-default
targets:
- stackdriver:
type: delta
metric: pubsub.googleapis.com/subscription/ack_message_count
alignment: {method: invalid, period: stackdriver-auto}
`

_, err := UnmarshalYAML(bytes.NewBufferString(payload))

require.Error(t, err)
require.Equal(t, ErrInvalidStackdriverAlignment, err)
}

func generalOptions() testCase {
yaml := `title: Awesome dashboard
Expand Down Expand Up @@ -803,6 +846,280 @@ rows:
}
}

func graphPanelWithStackdriverTarget() testCase {
yaml := `title: Awesome dashboard
rows:
- name: Test row
panels:
- graph:
title: Pubsub Ack msg count
datasource: voi-stage-stackdriver
targets:
- stackdriver:
ref: A
legend: Ack-ed messages
type: delta
metric: pubsub.googleapis.com/subscription/ack_message_count
aggregation: mean
alignment: {method: delta, period: stackdriver-auto}
filters:
eq:
resource.type: pubsub_subscription
`
json := `{
"slug": "",
"title": "Awesome dashboard",
"originalTitle": "",
"tags": null,
"style": "dark",
"timezone": "",
"editable": false,
"hideControls": false,
"sharedCrosshair": false,
"templating": {"list": null},
"annotations": {"list": null},
"links": null,
"panels": null,
"rows": [
{
"title": "Test row",
"collapse": false,
"editable": true,
"height": "250px",
"repeat": null,
"showTitle": true,
"panels": [
{
"type": "graph",
"datasource": "voi-stage-stackdriver",
"editable": true,
"error": false,
"gridPos": {},
"id": 6,
"isNew": false,
"renderer": "flot",
"span": 6,
"fill": 1,
"title": "Pubsub Ack msg count",
"aliasColors": {},
"bars": false,
"points": false,
"stack": false,
"steppedLine": false,
"lines": true,
"linewidth": 1,
"pointradius": 5,
"percentage": false,
"nullPointMode": "null as zero",
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"hideEmpty": true,
"hideZero": true,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": false
},
"targets": [
{
"aliasBy": "Ack-ed messages",
"alignOptions": [
{
"expanded": true,
"label": "Alignment options",
"options": [
{
"label": "delta",
"metricKinds": [
"CUMULATIVE",
"DELTA"
],
"text": "delta",
"value": "ALIGN_DELTA",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY",
"DISTRIBUTION"
]
},
{
"label": "rate",
"metricKinds": [
"CUMULATIVE",
"DELTA"
],
"text": "rate",
"value": "ALIGN_RATE",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY"
]
},
{
"label": "min",
"metricKinds": [
"GAUGE",
"DELTA"
],
"text": "min",
"value": "ALIGN_MIN",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY"
]
},
{
"label": "max",
"metricKinds": [
"GAUGE",
"DELTA"
],
"text": "max",
"value": "ALIGN_MAX",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY"
]
},
{
"label": "mean",
"metricKinds": [
"GAUGE",
"DELTA"
],
"text": "mean",
"value": "ALIGN_MEAN",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY"
]
},
{
"label": "count",
"metricKinds": [
"GAUGE",
"DELTA"
],
"text": "count",
"value": "ALIGN_COUNT",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY",
"BOOL"
]
},
{
"label": "sum",
"metricKinds": [
"GAUGE",
"DELTA"
],
"text": "sum",
"value": "ALIGN_SUM",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY",
"DISTRIBUTION"
]
},
{
"label": "stddev",
"metricKinds": [
"GAUGE",
"DELTA"
],
"text": "stddev",
"value": "ALIGN_STDDEV",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY"
]
},
{
"label": "percent change",
"metricKinds": [
"GAUGE",
"DELTA"
],
"text": "percent change",
"value": "ALIGN_PERCENT_CHANGE",
"valueTypes": [
"INT64",
"DOUBLE",
"MONEY"
]
}
]
}
],
"refId": "A",
"metricKind": "DELTA",
"metricType": "pubsub.googleapis.com/subscription/ack_message_count",
"perSeriesAligner": "ALIGN_DELTA",
"alignmentPeriod": "stackdriver-auto",
"crossSeriesReducer": "REDUCE_MEAN",
"filters": ["resource.type", "=", "pubsub_subscription"],
"valueType": "INT64"
}
],
"tooltip": {
"shared": true,
"value_type": "",
"sort": 2
},
"x-axis": true,
"y-axis": true,
"xaxis": {
"format": "time",
"logBase": 1,
"show": true
},
"yaxes": [
{
"format": "short",
"logBase": 1,
"show": true
},
{
"format": "short",
"logBase": 1,
"show": false
}
],
"transparent": false
}
]
}
],
"time": {"from": "now-3h", "to": "now"},
"timepicker": {
"refresh_intervals": ["5s","10s","30s","1m","5m","15m","30m","1h","2h","1d"],
"time_options": ["5m","15m","1h","6h","12h","24h","2d","7d","30d"]
},
"schemaVersion": 0,
"version": 0
}`

return testCase{
name: "single row with single graph panel and stackdriver target",
yaml: yaml,
expectedGrafanaJSON: json,
}
}

func singleStatPanel() testCase {
yaml := `title: Awesome dashboard
Expand Down
8 changes: 8 additions & 0 deletions decoder/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ func (graphPanel *DashboardGraph) target(t Target) (graph.Option, error) {
if t.Prometheus != nil {
return graph.WithPrometheusTarget(t.Prometheus.Query, t.Prometheus.toOptions()...), nil
}
if t.Stackdriver != nil {
stackdriverTarget, err := t.Stackdriver.toTarget()
if err != nil {
return nil, err
}

return graph.WithStackdriverTarget(stackdriverTarget), nil
}

return nil, ErrTargetNotConfigured
}
Expand Down
Loading

0 comments on commit 84eb643

Please sign in to comment.