refactor(grafana): replace dashboard info with import compatible layout
This commit is contained in:
parent
4aad919153
commit
577f821b9d
8 changed files with 173 additions and 110 deletions
|
@ -51,12 +51,7 @@ func (c *DashboardVersionClient) GetByID(
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
dashboards, resp, err := c.get(ctx, dashboardVersionURL, params...)
|
||||
if err != nil || len(dashboards) < 1 {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return dashboards[0], resp, nil
|
||||
return c.get(ctx, dashboardVersionURL, params...)
|
||||
}
|
||||
|
||||
func (c *DashboardVersionClient) GetByUID(
|
||||
|
@ -65,17 +60,12 @@ func (c *DashboardVersionClient) GetByUID(
|
|||
version uint,
|
||||
params ...DashboardVersionParam,
|
||||
) (*DashboardVersion, *Response, error) {
|
||||
dashboardVersionURL, err := url.Parse(fmt.Sprintf("/dashboards/id/%s/versions/%d", uid, version))
|
||||
dashboardVersionURL, err := url.Parse(fmt.Sprintf("/dashboards/uid/%s/versions/%d", uid, version))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
dashboards, resp, err := c.get(ctx, dashboardVersionURL, params...)
|
||||
if err != nil || len(dashboards) < 1 {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return dashboards[0], resp, nil
|
||||
return c.get(ctx, dashboardVersionURL, params...)
|
||||
}
|
||||
|
||||
func (c *DashboardVersionClient) Get(
|
||||
|
@ -100,7 +90,7 @@ func (c *DashboardVersionClient) ListByID(
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
return c.get(ctx, dashboardVersionURL, params...)
|
||||
return c.list(ctx, dashboardVersionURL, params...)
|
||||
}
|
||||
|
||||
func (c *DashboardVersionClient) ListByUID(
|
||||
|
@ -113,7 +103,7 @@ func (c *DashboardVersionClient) ListByUID(
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
return c.get(ctx, dashboardVersionURL, params...)
|
||||
return c.list(ctx, dashboardVersionURL, params...)
|
||||
}
|
||||
|
||||
func (c *DashboardVersionClient) List(
|
||||
|
@ -131,6 +121,36 @@ func (c *DashboardVersionClient) get(
|
|||
ctx context.Context,
|
||||
dashboardVersionURL *url.URL,
|
||||
params ...DashboardVersionParam,
|
||||
) (*DashboardVersion, *Response, error) {
|
||||
if len(params) > 0 {
|
||||
query := dashboardVersionURL.Query()
|
||||
|
||||
for _, param := range params {
|
||||
param(&query)
|
||||
}
|
||||
|
||||
dashboardVersionURL.RawQuery = query.Encode()
|
||||
}
|
||||
|
||||
req, err := c.client.newRequest(ctx, "GET", dashboardVersionURL.String(), nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var body schema.DashboardVersion
|
||||
|
||||
resp, err := c.client.do(req, &body)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return DashboardVersionFromSchema(body), resp, nil
|
||||
}
|
||||
|
||||
func (c *DashboardVersionClient) list(
|
||||
ctx context.Context,
|
||||
dashboardVersionURL *url.URL,
|
||||
params ...DashboardVersionParam,
|
||||
) ([]*DashboardVersion, *Response, error) {
|
||||
if len(params) > 0 {
|
||||
query := dashboardVersionURL.Query()
|
||||
|
@ -142,20 +162,20 @@ func (c *DashboardVersionClient) get(
|
|||
dashboardVersionURL.RawQuery = query.Encode()
|
||||
}
|
||||
|
||||
req, err := c.client.NewRequest(ctx, "GET", dashboardVersionURL.String(), nil)
|
||||
req, err := c.client.newRequest(ctx, "GET", dashboardVersionURL.String(), nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var body schema.DashboardVersionListResponse
|
||||
|
||||
resp, err := c.client.Do(req, &body)
|
||||
resp, err := c.client.do(req, &body)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
dashboardVersions := make([]*DashboardVersion, 0, len(body.DashboardVersions))
|
||||
for _, dashboardVersion := range body.DashboardVersions {
|
||||
dashboardVersions := make([]*DashboardVersion, 0, len(body))
|
||||
for _, dashboardVersion := range body {
|
||||
dashboardVersions = append(dashboardVersions, DashboardVersionFromSchema(dashboardVersion))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue