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

Showcase integration with observability packages #228

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
73 changes: 73 additions & 0 deletions cmd/builder-with-polly-package-example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"fmt"
"os"

"github.com/K-Phoen/grabana/dashboard"
"github.com/K-Phoen/grabana/packages"
"github.com/K-Phoen/grabana/row"
"github.com/K-Phoen/grabana/target/prometheus"
"github.com/K-Phoen/grabana/timeseries"
)

func main() {
if len(os.Args) != 2 {
fmt.Fprint(os.Stderr, "Usage: go run main.go path-to-package\n")
os.Exit(1)
}

pkg, err := packages.LoadFile(os.Args[1])
if err != nil {
fmt.Fprint(os.Stderr, "could not load package: %w\n", err)
os.Exit(1)
}

builder, err := dashboard.New(
"Awesome MySQL dashboard",
dashboard.UID("test-packages-package"),
dashboard.AutoRefresh("30s"),
dashboard.Time("now-30m", "now"),
dashboard.Tags([]string{"generated", "packages", "package"}),

dashboard.Row(
"Some stuff",

// Complete panel taken from a package
row.WithPanelFromPackage(pkg, packages.PanelRef("mysql-open-tables")),

// Manually-defined panel, with a target taken from a package
row.WithTimeSeries(
"Tables definitions",
timeseries.Span(6),
timeseries.Height("400px"),
timeseries.DataSource("Prometheus"),
timeseries.WithTargetFromPackage(pkg, packages.TargetRef("mysql-table-definition-cache-2")),
),

// Completely manually-defined panel
row.WithTimeSeries(
"HTTP Rate",
timeseries.Span(6),
timeseries.Height("400px"),
timeseries.DataSource("Prometheus"),
timeseries.WithPrometheusTarget(
"sum(rate(promhttp_metric_handler_requests_total[$interval])) by (code)",
prometheus.Legend("{{ code }}"),
),
),
),
)
if err != nil {
fmt.Printf("Could not build dashboard: %s\n", err)
os.Exit(1)
}

dashboardJSON, err := builder.MarshalIndentJSON()
if err != nil {
fmt.Printf("Could not marshal dashboard: %s\n", err)
os.Exit(1)
}

fmt.Println(string(dashboardJSON))
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require (
github.com/K-Phoen/sdk v0.12.2
github.com/blang/semver v3.5.1+incompatible
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/common v0.39.0
github.com/rhysd/go-github-selfupdate v1.2.3
github.com/spf13/cobra v1.6.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
Expand Down
Loading
Loading