Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.
Open
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
14 changes: 11 additions & 3 deletions pkg/grafana/alertgroup-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ func (c *alertRuleProxyConfigurator) ProxyURL(uid string) string {
return fmt.Sprintf("/alerting/grafana/%s/view", uid)
}

func (c *alertRuleProxyConfigurator) ProxyEditURL(uid string) string {
return fmt.Sprintf("/alerting/%s/edit", uid)
}

func (c *alertRuleProxyConfigurator) Endpoints(s grizzly.Server) []grizzly.HTTPEndpoint {
return []grizzly.HTTPEndpoint{
{
Method: http.MethodGet,
URL: "/alerting/grafana/{rule_uid}/view",
Handler: authenticateAndProxyHandler(s, c.provider),
},
{
Method: http.MethodGet,
URL: "/alerting/grafana/{rule_uid}/edit",
Handler: authenticateAndProxyHandler(s, c.provider),
},
{
Method: http.MethodGet,
URL: "/api/ruler/grafana/api/v1/rule/{rule_uid}",
Expand Down Expand Up @@ -64,7 +73,7 @@ func (c *alertRuleProxyConfigurator) alertRuleGroupJSONGetHandler(s grizzly.Serv
return
}

interval := time.Duration(ruleGroup.GetSpecValue("interval").(int)) * time.Second
interval := time.Duration(ruleGroup.GetSpecValue("interval").(float64)) * time.Second

rules := ruleGroup.GetSpecValue("rules").([]any)
formattedRules := make([]map[string]any, 0, len(rules))
Expand Down Expand Up @@ -114,8 +123,7 @@ func (c *alertRuleProxyConfigurator) alertRuleJSONGetHandler(s grizzly.Server) h
httputils.Error(w, fmt.Sprintf("Alert rule with UID %s not found", ruleUID), fmt.Errorf("rule group with UID %s not found", ruleUID), http.StatusNotFound)
return
}

interval := time.Duration(ruleGroup.GetSpecValue("interval").(int)) * time.Second
interval := time.Duration(ruleGroup.GetSpecValue("interval").(float64)) * time.Second

httputils.WriteJSON(w, toGrafanaAlert(rule, interval))
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/grafana/dashboard-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func (c *dashboardProxyConfigurator) ProxyURL(uid string) string {
return fmt.Sprintf("/d/%s/slug", uid)
}

func (c *dashboardProxyConfigurator) ProxyEditURL(uid string) string {
return c.ProxyURL(uid)
}

func (c *dashboardProxyConfigurator) Endpoints(s grizzly.Server) []grizzly.HTTPEndpoint {
return []grizzly.HTTPEndpoint{
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/grafana/datasource-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func (c *datasourceProxyConfigurator) ProxyURL(uid string) string {
return fmt.Sprintf("/connections/datasources/edit/%s", uid)
}

func (c *datasourceProxyConfigurator) ProxyEditURL(uid string) string {
return c.ProxyURL(uid)
}

func (c *datasourceProxyConfigurator) Endpoints(s grizzly.Server) []grizzly.HTTPEndpoint {
return []grizzly.HTTPEndpoint{
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/grafana/folder-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func (c *folderProxyConfigurator) ProxyURL(uid string) string {
return fmt.Sprintf("/dashboards/f/%s/", uid)
}

func (c *folderProxyConfigurator) ProxyEditURL(uid string) string {
return c.ProxyURL(uid)
}

func (c *folderProxyConfigurator) Endpoints(s grizzly.Server) []grizzly.HTTPEndpoint {
return []grizzly.HTTPEndpoint{
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/grafana/library-element-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func (c *libraryElementProxyConfigurator) ProxyURL(uid string) string {
return fmt.Sprintf("/api/library-elements/%s", uid)
}

func (c *libraryElementProxyConfigurator) ProxyEditURL(uid string) string {
return c.ProxyURL(uid)
}

func (c *libraryElementProxyConfigurator) Endpoints(s grizzly.Server) []grizzly.HTTPEndpoint {
return []grizzly.HTTPEndpoint{
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/grizzly/embed/templates/proxy/index.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{{ .Spec.title }}
<ul>
{{ range .Spec.rules }}
<li><a href="/grizzly/AlertRuleGroup/{{ .uid }}">{{ .title }}</a></li>
<li><a href="/grizzly/AlertRuleGroup/{{ .uid }}">{{ .title }}</a> (<a href="/grizzly/AlertRuleGroup/{{ .uid }}/edit">Edit</a>)</li>
{{ end }}
</ul>
</li>
Expand Down
3 changes: 3 additions & 0 deletions pkg/grizzly/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,8 @@ type ProxyConfigurator interface {
// ProxyURL returns a URL path for a resource on the proxy
ProxyURL(uid string) string

// ProxyEditURL returns a URL path for a resource on the proxy
ProxyEditURL(uid string) string

StaticEndpoints() StaticProxyConfig
}
8 changes: 7 additions & 1 deletion pkg/grizzly/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (s *Server) Start() error {

r.Get("/", s.rootHandler)
r.Get("/grizzly/{kind}/{name}", s.iframeHandler)
r.Get("/grizzly/{kind}/{name}/{action}", s.iframeHandler)
r.Get("/livereload", livereload.Handler(upgrader))

if s.watchScript != "" {
Expand Down Expand Up @@ -361,6 +362,7 @@ func (s *Server) ProxyRequestHandler(w http.ResponseWriter, r *http.Request) {
func (s *Server) iframeHandler(w http.ResponseWriter, r *http.Request) {
kind := chi.URLParam(r, "kind")
name := chi.URLParam(r, "name")
action := chi.URLParam(r, "action")
handler, err := s.Registry.GetHandler(kind)
if err != nil {
httputils.Error(w, fmt.Sprintf("Error getting handler for %s/%s", kind, name), err, http.StatusInternalServerError)
Expand All @@ -374,9 +376,13 @@ func (s *Server) iframeHandler(w http.ResponseWriter, r *http.Request) {
}

proxyConfig := proxyConfigProvider.ProxyConfigurator()
proxyURL := proxyConfig.ProxyURL(name)
if action == "edit" {
proxyURL = proxyConfig.ProxyEditURL(name)
}
templateVars := map[string]any{
"Port": s.port,
"IframeURL": proxyConfig.ProxyURL(name),
"IframeURL": proxyURL,
"CurrentContext": s.CurrentContext,
}

Expand Down