Skip to content

Commit

Permalink
dash reworking
Browse files Browse the repository at this point in the history
Signed-off-by: Owen Diehl <[email protected]>
  • Loading branch information
owen-d committed Oct 9, 2024
1 parent 9023951 commit 1e671d8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
18 changes: 18 additions & 0 deletions cmd/dashboards/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"fmt"

"github.com/grafana/dskit/server"
"github.com/grafana/loki/v3/pkg/dash"
"github.com/grafana/loki/v3/pkg/util/constants"
)

func main() {
metrics := server.NewServerMetrics(server.Config{MetricsNamespace: constants.Loki})
dashboardLoader, err := dash.NewDashboardLoader(metrics)
if err != nil {
panic(err)
}
fmt.Println(string(dashboardLoader.WritesDashboard()))
}
28 changes: 21 additions & 7 deletions pkg/dash/dash.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"text/template"

"github.com/grafana/dskit/server"
"github.com/grafana/grafana-foundation-sdk/go/cog"
"github.com/grafana/grafana-foundation-sdk/go/common"
"github.com/grafana/grafana-foundation-sdk/go/dashboard"
"github.com/grafana/grafana-foundation-sdk/go/prometheus"
Expand Down Expand Up @@ -43,11 +44,15 @@ func NewDashboardLoader(server *server.Metrics) (*DashboardLoader, error) {
}, nil
}

func (l *DashboardLoader) WritesDashboard() []byte {
return l.writes
}

func (l *DashboardLoader) Writes() http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Check warning on line 52 in pkg/dash/dash.go

View workflow job for this annotation

GitHub Actions / check / golangciLint

unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
// TODO(owen-d): versioning
w.Header().Set("Content-Type", "application/json")
w.Write(l.writes)
w.Write(l.WritesDashboard())

Check failure on line 55 in pkg/dash/dash.go

View workflow job for this annotation

GitHub Actions / check / golangciLint

Error return value of `w.Write` is not checked (errcheck)
})
}

Expand Down Expand Up @@ -86,7 +91,7 @@ func WritesDashboard(requestDuration *prom.HistogramVec) (dashboard.Dashboard, e
distributorRED,
ingesterRED,
} {
builder = builder.WithRow(red.Row())
red.Build(builder)
}

return builder.Build()
Expand Down Expand Up @@ -250,7 +255,7 @@ func (b *RedMethodBuilder) QPSPanel() *timeseries.PanelBuilder {
WithTarget(qry)
}

func (b *RedMethodBuilder) LatencyPanels() (res []*timeseries.PanelBuilder) {
func (b *RedMethodBuilder) LatencyPanels() (res []cog.Builder[dashboard.Panel]) {
rounds := []TemplateArgs{
b.TemplateArgs(),
}
Expand Down Expand Up @@ -319,9 +324,18 @@ func (b *RedMethodBuilder) LatencyPanels() (res []*timeseries.PanelBuilder) {
}

func (b *RedMethodBuilder) Row() *dashboard.RowBuilder {
row := dashboard.NewRowBuilder(b.title).WithPanel(b.QPSPanel())
for _, p := range b.LatencyPanels() {
row = row.WithPanel(p)
return dashboard.NewRowBuilder(b.title)
}

func (b *RedMethodBuilder) Panels() []cog.Builder[dashboard.Panel] {
return append([]cog.Builder[dashboard.Panel]{
b.QPSPanel(),
}, b.LatencyPanels()...)
}

func (b *RedMethodBuilder) Build(builder *dashboard.DashboardBuilder) {
builder.WithRow(b.Row())
for _, panel := range b.Panels() {
builder.WithPanel(panel)
}
return row
}

0 comments on commit 1e671d8

Please sign in to comment.