Skip to content

Commit

Permalink
build: go 1.23
Browse files Browse the repository at this point in the history
  • Loading branch information
clambin committed Aug 16, 2024
1 parent a7d76c5 commit 45f411c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ permissions:

jobs:
test:
uses: clambin/workflows/.github/workflows/test.yaml@main
uses: clambin/workflows/.github/workflows/test.yaml@go1.23
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}
release:
needs:
- test
uses: clambin/workflows/.github/workflows/release.yaml@docker
uses: clambin/workflows/.github/workflows/release.yaml@go1.23
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
test:
uses: clambin/workflows/.github/workflows/test.yaml@main
uses: clambin/workflows/.github/workflows/test.yaml@go1.23
secrets:
codecov-token: ${{ secrets.CODECOV_TOKEN }}

2 changes: 1 addition & 1 deletion .github/workflows/vulnerabilities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ on:

jobs:
vulnerabilities:
uses: clambin/workflows/.github/workflows/vulnerabilities.yaml@main
uses: clambin/workflows/.github/workflows/vulnerabilities.yaml@go1.23
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/clambin/grope

go 1.22.1

toolchain go1.22.5
go 1.23

require (
github.com/clambin/go-common/charmer v0.2.0
Expand Down
38 changes: 24 additions & 14 deletions internal/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal
import (
"fmt"
gapi "github.com/grafana/grafana-api-golang-client"
"iter"
"log/slog"
)

Expand Down Expand Up @@ -30,27 +31,36 @@ func FetchDashboards(c DashboardClient, logger *slog.Logger, shouldExport func(g
}

dashboards := make(Dashboards, 0, len(foundBoards))
for _, board := range foundBoards {
for board := range dashboardsToExport(foundBoards, shouldExport) {
logger.Debug("dashboard found", "data", folderDashboard(board))

// Only process dashboards, not folders
// Only export if the dashboard meets the criteria
if board.Type == "dash-db" && shouldExport(board) {
rawBoard, err := c.DashboardByUID(board.UID)
if err != nil {
return nil, fmt.Errorf("grafana get board: %w", err)
}
dashboards = append(dashboards, Dashboard{
Folder: board.FolderTitle,
Title: board.Title,
Model: rawBoard.Model,
})
rawBoard, err := c.DashboardByUID(board.UID)
if err != nil {
return nil, fmt.Errorf("grafana get board: %w", err)
}
dashboards = append(dashboards, Dashboard{
Folder: board.FolderTitle,
Title: board.Title,
Model: rawBoard.Model,
})
}

return dashboards, nil
}

func dashboardsToExport(dashboards []gapi.FolderDashboardSearchResponse, shouldExport func(gapi.FolderDashboardSearchResponse) bool) iter.Seq[gapi.FolderDashboardSearchResponse] {
return func(yield func(gapi.FolderDashboardSearchResponse) bool) {
for _, board := range dashboards {
// Only process dashboards, not folders
// Only export if the dashboard meets the criteria
if board.Type == "dash-db" && shouldExport(board) {
if !yield(board) {
return
}
}
}
}
}

var _ slog.LogValuer = folderDashboard{}

type folderDashboard gapi.FolderDashboardSearchResponse
Expand Down
45 changes: 28 additions & 17 deletions internal/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
grafanav1beta1 "github.com/grafana/grafana-operator/v5/api/v1beta1"
"gopkg.in/yaml.v3"
"io"
"iter"
)

type Formatter struct {
Expand Down Expand Up @@ -75,23 +76,7 @@ func (f Formatter) FormatDashboard(w io.Writer, dashboard Dashboard) error {
}

func (f Formatter) FormatDataSources(w io.Writer, dataSources []*gapi.DataSource) error {
for _, dataSource := range dataSources {
cr := grafanaOperatorCustomResource{
APIVersion: grafanav1beta1.GroupVersion.String(),
Kind: "GrafanaDataSource",
Metadata: metadata{
Name: "datasource-" + slug.Make(dataSource.Name),
Namespace: f.Namespace,
},
Spec: grafanaOperatorCustomResourceSpec{
InstanceSelector: instanceSelector{
MatchLabels: map[string]string{
f.GrafanaLabelName: f.GrafanaLabelValue,
},
},
DataSource: dataSource,
},
}
for cr := range f.grafanaOperatorCustomResources(dataSources) {
_, _ = w.Write([]byte("---\n"))
yEnc := yaml.NewEncoder(w)
yEnc.SetIndent(2)
Expand All @@ -101,3 +86,29 @@ func (f Formatter) FormatDataSources(w io.Writer, dataSources []*gapi.DataSource
}
return nil
}

func (f Formatter) grafanaOperatorCustomResources(dataSources []*gapi.DataSource) iter.Seq[grafanaOperatorCustomResource] {
return func(yield func(grafanaOperatorCustomResource) bool) {
for _, dataSource := range dataSources {
cr := grafanaOperatorCustomResource{
APIVersion: grafanav1beta1.GroupVersion.String(),
Kind: "GrafanaDataSource",
Metadata: metadata{
Name: "datasource-" + slug.Make(dataSource.Name),
Namespace: f.Namespace,
},
Spec: grafanaOperatorCustomResourceSpec{
InstanceSelector: instanceSelector{
MatchLabels: map[string]string{
f.GrafanaLabelName: f.GrafanaLabelValue,
},
},
DataSource: dataSource,
},
}
if !yield(cr) {
return
}
}
}
}

0 comments on commit 45f411c

Please sign in to comment.