Skip to content

Commit

Permalink
move dashboard creation funnction to grafana pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
hervenicol committed Jan 7, 2025
1 parent 92c0cfb commit fcbc619
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 1 addition & 6 deletions internal/controller/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"

grafanaAPI "github.com/grafana/grafana-openapi-client-go/client"
"github.com/grafana/grafana-openapi-client-go/models"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -251,11 +250,7 @@ func (r DashboardReconciler) configureDashboard(ctx context.Context, dashboardCM
}

// Create or update dashboard
_, err = r.GrafanaAPI.Dashboards.PostDashboard(&models.SaveDashboardCommand{
Dashboard: any(dashboard),
Message: "Added by observability-operator",
Overwrite: true, // allows dashboard to be updated by the same UID
})
err = grafana.PublishDashboard(r.GrafanaAPI, dashboard)
if err != nil {
logger.Info("Failed updating dashboard", "Error", err)
continue
Expand Down
11 changes: 11 additions & 0 deletions pkg/grafana/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,14 @@ func FindOrgByID(grafanaAPI *client.GrafanaHTTPAPI, orgID int64) (*Organization,
Name: organization.Payload.Name,
}, nil
}

// PublishDashboard creates or updates a dashboard in Grafana
func PublishDashboard(grafanaAPI *client.GrafanaHTTPAPI, dashboard map[string]any) error {
_, err := grafanaAPI.Dashboards.PostDashboard(&models.SaveDashboardCommand{
Dashboard: any(dashboard),
Message: "Added by observability-operator",
Overwrite: true, // allows dashboard to be updated by the same UID

})
return err
}

0 comments on commit fcbc619

Please sign in to comment.