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

Set organization homeDashboardUID through the grafana operator #896

Closed
nhti opened this issue Feb 16, 2023 · 20 comments · Fixed by #1301
Closed

Set organization homeDashboardUID through the grafana operator #896

nhti opened this issue Feb 16, 2023 · 20 comments · Fixed by #1301
Labels
enhancement New feature or request help wanted Extra attention is needed triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@nhti
Copy link

nhti commented Feb 16, 2023

Is your feature request related to a problem? Please describe.
With the way that the grafanadashboard resource is used, there is no direct reference to a physical file of our grafana dashboard. Therefore, we cannot define a default_home_dashboard_path from the grafana operator.

(If applicable)If your feature request solves a bug please provide a link to the community issue
N/A

Describe the solution you'd like
Grafana has the Update Current Org Prefs which accepts a homeDashboardUID to set as the default home dashboard. So it would be preferable to be able to set a default home dashboard via this API by referencing a dashboard UID from the grafana operator configuration.

Describe alternatives you've considered
Or it would also be beneficial to have a physical file of our defined dashboard inside the grafana pod such that it can be referenced via default_home_dashboard_path

Additional context
N/A

Existing solutions
N/A

@nhti nhti added enhancement New feature or request needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 16, 2023
@nhti nhti changed the title Set organization homeDashboardId through the grafana operator Set organization homeDashboardUID through the grafana operator Feb 16, 2023
@ntx-ben
Copy link

ntx-ben commented Feb 20, 2023

Running into the same issue. Although, it is possible to change the default home dashboard via the GUI, so I am wondering how that works?

As the OP mentioned, the dashboards declared in the Grafana Operator CR as not saved to files in the default folder location, /etc/grafana/provisioning/dashboards/, whereas the DataSources are.

@github-actions
Copy link

This issue hasn't been updated for a while, marking as stale, please respond within the next 7 days to remove this label

@github-actions github-actions bot added the stale label Mar 22, 2023
@ninkaninus
Copy link

This is still an issue.

@github-actions github-actions bot removed the stale label Mar 22, 2023
@HVBE
Copy link
Collaborator

HVBE commented Mar 28, 2023

Hi @nhti , thanks for filing the issue, Can you describe how you would imagine this working for your use case?

Do you need more than one organization that you want to set homeDashboardUID for?

Also, seems like according to this blogpost: https://grafana.com/blog/2022/03/14/how-to-best-organize-your-teams-and-resources-in-grafana/

upstream grafana is discouraging the use of organizations in favor of teams. Are you intending o use Orgs or Teams?

@HVBE HVBE added triage/needs-information Indicates an issue needs more information in order to work on it. and removed needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 28, 2023
@nhti
Copy link
Author

nhti commented Mar 30, 2023

Hi @HubertStefanski, thank you for the reply,

Can you describe how you would imagine this working for your use case?

Preferably, this would be a configuration inside the values.yaml where we can input a dashboard UID and have it as the default home dashboard

Do you need more than one organization that you want to set homeDashboardUID for?

At the moment, we only use one org, but options would be good

Are you intending to use Orgs or Teams?

At the moment we are using Orgs, but no plans on closing down on either of them

@NissesSenap
Copy link
Collaborator

@nhti can you please create a design document that describes how this feature would be implemented as a CRD?
In short, how the CRD look like?
Please create a PR, you can find an example of a design document here: https://github.com/grafana-operator/grafana-operator/blob/master/docs/docs/proposals/001%20external%20grafana%20instance.md

@github-actions
Copy link

github-actions bot commented May 1, 2023

This issue hasn't been updated for a while, marking as stale, please respond within the next 7 days to remove this label

@github-actions github-actions bot added the stale label May 1, 2023
@nhti
Copy link
Author

nhti commented May 8, 2023

unstale!

This is still needed, but for the design, it's still a WIP

@github-actions github-actions bot removed the stale label May 8, 2023
@github-actions
Copy link

github-actions bot commented Jun 7, 2023

This issue hasn't been updated for a while, marking as stale, please respond within the next 7 days to remove this label

@github-actions github-actions bot added the stale label Jun 7, 2023
@ninkaninus
Copy link

This is still an needed.

@NissesSenap NissesSenap added triage/accepted Indicates an issue or PR is ready to be actively worked on. help wanted Extra attention is needed and removed triage/needs-information Indicates an issue needs more information in order to work on it. stale labels Jun 9, 2023
@NissesSenap
Copy link
Collaborator

I will put it as accepted, but before any implementation starts we will need a design proposal as defined in https://github.com/grafana-operator/grafana-operator/blob/master/docs/docs/proposals/001%20external%20grafana%20instance.md.
I don't think any maintainer have time for this in the close future. But if anyone else is up for it, please take a stab at it.

@senare
Copy link

senare commented Oct 9, 2023

I am just going to leave a note and add that there are 3 ways to define home dashboard

  1. server (default for everyone)
  2. org
  3. team

that according to my understanding atleast !

@ninkaninus
Copy link

I found a related issue in the Grafana Helm repo:
grafana/grafana#54574

@jaehnri
Copy link
Contributor

jaehnri commented Nov 1, 2023

Hi! I have the same need to set the home dashboard. We used to have a fork of v4 that implemented something that solved this issue. We had a boolean attribute UseAsHomeDashboard in the GrafanaDashboardSpec that would trigger a request to Grafana's Preferences API upon the dashboard reconciliation (here's the implementation).

I understand there could be a better approach, as this allows users to set multiple home dashboards wrongly and also doesn't allow different defaults for teams/orgs/etc.

I'm open to discussion and, upon a better solution, I'd be glad to contribute it.

@jhawksley-intergral
Copy link

I've got half a vague idea that it might be possible to launch a sort of short-lived 'startup container' along with the Grafana pod (by describing this in the CRD yaml) which does the appropriate API call to set the home dashboard when the Grafana container comes up.

This is still very much half-baked though (I don't know if there is such a call, or how the container would work, or how to get an API username/password set up etc.etc.) and I'd much prefer a simple value in the CRD (Home dashboard UID or path in the hierarchy).

@NissesSenap
Copy link
Collaborator

@jaehnri yeah if we allow, setting it in GrafanaDashboardSpec I feel that we would also need to implement some kind of CEL or webhook auth to make sure that you can only set it in one dashboard. This of course becomes even harder when you are having multiple grafana instances.

My feeling around this is that it's easiest if we just implement the preferences API as a new CRD even though it feels a bit silly. https://grafana.com/docs/grafana/latest/developers/http_api/preferences/

I assume all logic for which homeDashboard will be set is handled in grafana so if we start to support teams I guess we only need to add the homeDashboard and part of that spec.
https://grafana.com/docs/grafana/latest/developers/http_api/team/

We don't plan to ever support multiple orgs, so we don't have to worry about that.

@jaehnri if you can describe how that CRD could look like, I think that could be a great start. Unless you think this should be solved some other way. We are open to suggestions.

I think the CRD would be rather simple, but if you feel like it, feel free to create a design document, https://github.com/grafana-operator/grafana-operator/blob/master/docs/docs/proposals/001%20external%20grafana%20instance.md.
Else, you can probably describe it in this issue.

Sound like a good start?

@weisdd
Copy link
Collaborator

weisdd commented Nov 2, 2023

@NissesSenap I think we should consider making it part of Grafana resource. - There are not too many settings and just one org to support, so we can try to add a field that is similar to what we have for Grafana config - arbitrary data that will be just marshalled into JSON and sent to Grafana API. - If Grafana does not reject unknown uids in homeDashboardUID, then we can make that API call before provisioning dashboards. It should be super simple then :)

@NissesSenap
Copy link
Collaborator

Sounds like a good idea @weisdd , let's go with that instead

@weisdd
Copy link
Collaborator

weisdd commented Nov 2, 2023

I see that Grafana responds with 404 when unknown homeDashboardUID is passed (at the same time, it accepts any homeDashboardId):

{
  "message": "Dashboard not found",
  "traceID": ""
}

So, it's a bit trickier than I thought. Potentially, we can have a workaround:

  • check which dashboards are present, if the target one is missing, nullify homeDashboardUID ("homeDashboardUID": "") before updating org preferences;
  • nullify the value only if the error is hit.
    In both cases, it'll be eventual consistency (next reconciliation cycle of Grafana).

Not as good as hoped, but still a way to go.

@jaehnri
Copy link
Contributor

jaehnri commented Nov 7, 2023

I'm thinking of adding something like this in the GrafanaSpec:

spec:
  preferences:
    homeDashboardUid: "foobar"

And then, in the dashboard reconcile, after creating the dashboard, we can compare the homeDashboardUid to the current dashboard UID. If it is equal, we call the preferences API to update it:

https://github.com/grafana-operator/grafana-operator/blob/6d19d89492e910d38aff41aa4bdfa5541a0f3a1f/controllers/dashboard_controller.go#L254-L259

if uid == grafana.Spec.Preferences.HomeDashboardUID {
    ...
    err = r.UpdateHomeDashboard(...)
    ...
}

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants