Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard Builder Experiment #416

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- uses: ./.github/actions/setup-goversion

- name: Build
run: go build -v ./...

- name: Lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # 6.1.1
with:
version: v1.56

- name: Test
run: go test -v ./...
check-for-doc-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
- name: Install make
run: sudo apt-get update && sudo apt-get install -y make
shell: bash
- name: Regenerate Helm Docs
Pokom marked this conversation as resolved.
Show resolved Hide resolved
- name: Check for Dashboards Drift
run: |
make helm > /dev/null # we don't actually need to output, just the results
go run ./cloudcost-exporter-dashboards/main.go --mode=files > /dev/null
if ! git diff --exit-code; then
echo "Helm docs are out of date. Please run 'make -C deploy/helm docs' and commit the changes."
echo "Dashboards are out of sync. Please run 'make build-dashboards' and commit the changes."
exit 1
fi
shell: bash


6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ push: build test push-dev
helm:
helm template my-release ./deploy/helm/cloudcost-exporter --debug
docker run -v "$(PWD):/helm-docs" -u "$(id -u)" jnorwood/helm-docs:latest

grizzly-serve:
grr serve -p 8088 -w -S "go run ./cloudcost-exporter-dashboards/main.go"

build-dashboards:
go run ./cloudcost-exporter-dashboard/main.go --mode=file
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This container a set of Grafana Dashboards that are generated using the [Grafana
To generate the dashboards:

```shell
go run operations_dashboard.go > operations_dashboard.json
go run dashboards/operations_dashboard.go > operations_dashboard.json
```

To iteratively develop dashboards with live reload:
Expand Down
12 changes: 12 additions & 0 deletions cloudcost-exporter-dashboards/dashboards/dashboards.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dashboards

import (
"github.com/grafana/grafana-foundation-sdk/go/dashboard"
)

func BuildDashboards() []*dashboard.DashboardBuilder {
operationDashboard := OperationsDashboard()
return []*dashboard.DashboardBuilder{
operationDashboard,
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main
package dashboards

import (
"encoding/json"
"fmt"

"github.com/grafana/grafana-foundation-sdk/go/cog"
"github.com/grafana/grafana-foundation-sdk/go/common"
"github.com/grafana/grafana-foundation-sdk/go/dashboard"
Expand All @@ -12,22 +9,8 @@ import (
"github.com/grafana/grafana-foundation-sdk/go/timeseries"
)

func prometheusDatasourceRef() dashboard.DataSourceRef {
return dashboard.DataSourceRef{
Type: cog.ToPtr[string]("prometheus"),
Uid: cog.ToPtr[string]("${datasource}"),
}
}

func prometheusQuery(expression string, legendFormat string) *prometheus.DataqueryBuilder {
return prometheus.NewDataqueryBuilder().
Expr(expression).
Range().
LegendFormat(legendFormat)
}

func main() {
builder := dashboard.NewDashboardBuilder("CloudCost Exporter").
func OperationsDashboard() *dashboard.DashboardBuilder {
builder := dashboard.NewDashboardBuilder("CloudCost Exporter Operations Dashboard").
// leaving this for BC reasons, but a proper human-readable UID would be better.
Uid("1a9c0de366458599246184cf0ae8b468").
Editable().
Expand Down Expand Up @@ -68,17 +51,21 @@ func main() {
WithRow(dashboard.NewRowBuilder("GCP")).
WithPanel(gcpListBucketsRPSOverTime().Height(6).Span(12)).
WithPanel(gcpNextScrapeOverTime().Height(6).Span(12))
return builder
}

sampleDashboard, err := builder.Build()
if err != nil {
panic(err)
}
dashboardJson, err := json.MarshalIndent(sampleDashboard, "", " ")
if err != nil {
panic(err)
func prometheusDatasourceRef() dashboard.DataSourceRef {
return dashboard.DataSourceRef{
Type: cog.ToPtr[string]("prometheus"),
Uid: cog.ToPtr[string]("${datasource}"),
}
}

fmt.Println(string(dashboardJson))
func prometheusQuery(expression string, legendFormat string) *prometheus.DataqueryBuilder {
return prometheus.NewDataqueryBuilder().
Expr(expression).
Range().
LegendFormat(legendFormat)
}

func collectorScrapeDurationOverTime() *timeseries.PanelBuilder {
Expand Down
Loading