diff --git a/pkg/kapis/monitoring/v1alpha3/dashboard_template_test.sh b/pkg/kapis/monitoring/v1alpha3/dashboard_template_test.sh index 3dce2c5c6..d82823173 100644 --- a/pkg/kapis/monitoring/v1alpha3/dashboard_template_test.sh +++ b/pkg/kapis/monitoring/v1alpha3/dashboard_template_test.sh @@ -1,3 +1,3 @@ #! /bin/bash -curl -d '{"grafanaDashboardName":"test2","grafanaDashboardUrl":"https://grafana.com/api/dashboards/7362/revisions/5/download"}' -H "Content-Type: application/json" localhost:9090/kapis/monitoring.kubesphere.io/v1alpha3/dashboard/template \ No newline at end of file +curl -d '{"grafanaDashboardUrl":"https://grafana.com/api/dashboards/7362/revisions/5/download"}' -H "Content-Type: application/json" localhost:9090/kapis/monitoring.kubesphere.io/v1alpha3/clusterdashboard/test1/template \ No newline at end of file diff --git a/pkg/kapis/monitoring/v1alpha3/handler.go b/pkg/kapis/monitoring/v1alpha3/handler.go index 5933c082a..b3fa3f622 100644 --- a/pkg/kapis/monitoring/v1alpha3/handler.go +++ b/pkg/kapis/monitoring/v1alpha3/handler.go @@ -328,7 +328,9 @@ func (h handler) handleGrafanaDashboardImport(req *restful.Request, resp *restfu return } - if entity.GrafanaDashboardName == "" { + grafanaDashboardName := req.PathParameter("grafanaDashboardName") + + if grafanaDashboardName == "" { err := errors.New("the requested parameter grafanaDashboardName cannot be empty") api.HandleBadRequest(resp, nil, err) return @@ -375,7 +377,7 @@ func (h handler) handleGrafanaDashboardImport(req *restful.Request, resp *restfu } c := converter.NewConverter() - convertedDashboard, err := c.ConvertToDashboard(grafanaDashboardContent, true, "", entity.GrafanaDashboardName) + convertedDashboard, err := c.ConvertToDashboard(grafanaDashboardContent, true, "", grafanaDashboardName) if err != nil { api.HandleBadRequest(resp, nil, err) return @@ -406,7 +408,7 @@ func (h handler) handleGrafanaDashboardImport(req *restful.Request, resp *restfu DoRaw(ctx) if err == nil { - api.HandleBadRequest(resp, nil, errors.New("a dashboard with the same name already exists!")) + api.HandleBadRequest(resp, nil, errors.New("a dashboard with the same name already exists.")) return } diff --git a/pkg/kapis/monitoring/v1alpha3/register.go b/pkg/kapis/monitoring/v1alpha3/register.go index 2798d040a..eeddf8664 100644 --- a/pkg/kapis/monitoring/v1alpha3/register.go +++ b/pkg/kapis/monitoring/v1alpha3/register.go @@ -506,9 +506,10 @@ func AddToContainer(c *restful.Container, k8sClient kubernetes.Interface, monito Returns(http.StatusOK, respOK, monitoring.Metric{})). Produces(restful.MIME_JSON) - ws.Route(ws.POST("/dashboard/template"). + ws.Route(ws.POST("/clusterdashboard/{grafanaDashboardName}/template"). To(h.handleGrafanaDashboardImport). - Doc("Convert Grafana templates to KubeSphere dashboards."). + Doc("Convert Grafana templates to KubeSphere clusterdashboards."). + Param(ws.PathParameter("grafanaDashboardName", "The name of the Grafana template to be converted").DataType("string").Required(true)). Metadata(restfulspec.KeyOpenAPITags, []string{constants.DashboardTag}). Writes(monitoringdashboardv1alpha2.ClusterDashboard{}). Returns(http.StatusOK, respOK, monitoringdashboardv1alpha2.ClusterDashboard{})). diff --git a/pkg/simple/client/monitoring/types.go b/pkg/simple/client/monitoring/types.go index 6ad064cf1..936666f59 100644 --- a/pkg/simple/client/monitoring/types.go +++ b/pkg/simple/client/monitoring/types.go @@ -50,7 +50,6 @@ type MetricData struct { } type DashboardEntity struct { - GrafanaDashboardName string `json:"grafanaDashboardName"` GrafanaDashboardUrl string `json:"grafanaDashboardUrl,omitempty"` GrafanaDashboardContent string `json:"grafanaDashboardContent,omitempty"` }