Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to grafana-openapi-client-go #262

Merged
merged 7 commits into from
Nov 13, 2023
Merged

Conversation

mbarrien
Copy link
Contributor

@mbarrien mbarrien commented Oct 17, 2023

Switches datasource, dashboard, and folder resources to using the grafana-openapi-client-go instead of accessing the REST API's directly. This should supersede #260 (and possibly #257 since it adds a field to provider for the OpenAPI client)

There are some small issues:

  • The OpenAPI models JSON rendering has a lot of omitempty annotations, which results in many fields no longer being present in the next pull after you change to this code (especially for datasources).
  • Some tests not passing make test:
    • Some bugs in the OpenAPI spec
      • getDatasourceByName does not define a 404 response, so in Golang code had to fall back to runtime.APIError instead of an error specific to that function call.
      • postDashboard the id field is expected to be a string, but Grafana is return a number
    • Getting 409 and 412 errors on some tests which aren't expecting them.

Note that some of the functionality lost in #260 due to missing fields has been restored since grafana-openapi-client-go contains them all.

If you have previously run grizzly pull, then run grizzly pull again in the new code, you will get diffs like this on all previously pulled resources (anonymized from actual examples):

Datasources:

--- a/grafana/grizzly/datasources/datasource-Grafana Cloud k6.yaml
+++ b/grafana/grizzly/datasources/datasource-Grafana Cloud k6.yaml
@@ -4,11 +4,7 @@ metadata:
     name: Grafana Cloud k6
 spec:
     access: proxy
-    basicAuth: false
-    basicAuthUser: ""
-    database: ""
     id: 33
-    isDefault: false
     jsonData:
         backendUrl: https://k6.io
         environment: production
@@ -18,11 +14,8 @@ spec:
     name: Grafana Cloud k6
     orgId: 1
     readOnly: true
-    secureJsonFields: {}
     type: k6-datasource
     typeLogoUrl: /public/plugins/k6-app/img/logo.svg
     uid: Grafana Cloud k6
     url: proxy
-    user: ""
     version: 1
-    withCredentials: false

Dashboards:

--- a/grizzly/dashboards/example-folder/dashboard-bazqux.yaml
+++ b/grizzly/dashboards/example-folder/dashboard-bazqux.yaml
@@ -23,6 +23,7 @@ spec:
     editable: true
     fiscalYearStartMonth: 0
     graphTooltip: 0
+    id: 180
     links: []
     liveNow: false
     panels:
@@ -133,4 +134,5 @@ spec:
     timezone: ""
     title: Sample Dashboard
     uid: bazqux
+    version: 2
     weekStart: ""

Folders:

--- a/grafana/grizzly/folders/folder-foobar.yaml
+++ b/grafana/grizzly/folders/folder-foobar.yaml
@@ -3,17 +3,16 @@ kind: DashboardFolder
 metadata:
     name: da4SikgVk
 spec:
-    canAdmin: false
     canDelete: true
     canEdit: true
     canSave: true
-    created: "2022-07-14T12:11:57Z"
+    created: "2022-07-14T12:11:57.000Z"
     createdBy: Anonymous
-    hasAcl: false
     id: 3
+    parents: null
     title: GrafanaCloud
     uid: foobar
-    updated: "2022-07-14T12:11:57Z"
+    updated: "2022-07-14T12:11:57.000Z"
     updatedBy: Anonymous
     url: /dashboards/f/foobar/example
     version: 1

@mbarrien mbarrien changed the title Openapi Switch to grafana-openapi-client-go Oct 17, 2023
@joanlopez joanlopez self-requested a review October 18, 2023 10:07
@joanlopez joanlopez self-assigned this Oct 18, 2023
@joanlopez
Copy link
Contributor

joanlopez commented Oct 19, 2023

Hi there @mbarrien,

Thanks for your effort on helping to migrate to the new client. I think it'd be awesome to get this pull request ready to be merged. So, beyond an eventual code review, now I'm going over all the failing tests (the ones you mentioned), case by case, and trying to fix them (see for instance 👉🏻 grafana/grafana#76749).

Once ready, I'll create a PR against your branch, so hopefully you'll branch will be ready to be merged after that.

Once more, thanks for your contributions, I think we're getting closer to finally have the "good" client in place! 🙌🏻

@malcolmholmes malcolmholmes self-requested a review November 9, 2023 10:55
Copy link
Contributor

@malcolmholmes malcolmholmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, much appreciated. A few small comments/questions, but I think we can approve merge this quite soon.

if err != nil {
return nil, err
}
// Losing id, typeLogoUrl, version, withCredentials
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line needed? Or suggests something still needs doing?

pkg/grafana/dashboards.go Show resolved Hide resolved
}
return data, nil
}
// Losing a bunch of omitempty fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary comment?

pkg/grafana/utils.go Show resolved Hide resolved
@malcolmholmes malcolmholmes merged commit 8b3ce5e into grafana:master Nov 13, 2023
1 check passed
This was referenced Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants