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

Grafana folders support #72

Open
SebastianIoanPop opened this issue Jul 5, 2019 · 4 comments
Open

Grafana folders support #72

SebastianIoanPop opened this issue Jul 5, 2019 · 4 comments

Comments

@SebastianIoanPop
Copy link

Hello, is there a way currently to make use of the grafana folders feature?

See:
https://grafana.com/docs/reference/dashboard_folders/
and
https://grafana.com/docs/administration/provisioning/#dashboards

I've tried a few hacks to make this work, as currently providing the configuration for dashboards with a composite path currently is not supported.

As the only limitation seems to be creating multiple folders within the container and separating the dashboards into the appropriate folders, I've tried the following:

local volumeMounts =
        [
          storageVolumeMount,
          datasourcesVolumeMount,
          dashboardsVolumeMount,
        ] +
        [
          local splitName = std.splitLimit(name, '/', 1);
          local folderName = if std.length(splitName) > 1 then splitName[0] else "0";
          local dashboardName = if std.length(splitName) < 2 then std.strReplace(splitName[0], '.json', '') else std.strReplace(splitName[1], '.json', '');
          containerVolumeMount.new('grafana-dashboard-' + dashboardName, '/grafana-dashboard-definitions/' + folderName + '/' + dashboardName),
          for name in std.objectFields($._config.grafana.dashboards)
        ] +
        if std.length($._config.grafana.config) > 0 then [configVolumeMount] else [];

(apply this change anywhere where it's relevant)
Which allowed the following convention to be used:

grafanaDashboards+:: {
    'folder/example.json': (import 'configs/dashboards/example.json')
}

However due to changing the core vendor file, it would make keeping up to date difficult so I would prefer it if I didn't have extra maintenance should this repo be updated.

I've also faced multiple problems related to volume mounts while doing that.

My approach should be a non-breaking change, however I don't fully understand jsonnet, grafana or kubernetes so there may be implications I'm not aware of or a better and cleaner way of doing it.

Thanks!

@brancz
Copy link
Owner

brancz commented Jul 8, 2019

Does this actually organize the dashboards in Grafana folders? As I understand the folder needs to be specified at the provisioner level, not at the dashboard level https://grafana.com/docs/administration/provisioning/#dashboards.

@SebastianIoanPop
Copy link
Author

SebastianIoanPop commented Jul 8, 2019

It requires both, the provisioning configuration is used to tell grafana what directories it should look in for the dashboards.

However it is required that the dashboards are placed in specific directories for that configuration to take in effect.

For example current configuration is mounting the dashboards in a hardcoded directory:
(see grafana.libsonnet line 110)

 [
          local dashboardName = std.strReplace(name, '.json', '');
          containerVolumeMount.new('grafana-dashboard-' + dashboardName, '/grafana-dashboard-definitions/0/' + dashboardName)
          for name in std.objectFields($._config.grafana.dashboards)
        ]

The /grafana-dashboard-definitions/0/ part is configured in the provisioning file:

{
  apiVersion: 1,
  providers: [
    {
      name: '0',
      orgId: 1,
      folder: '',
      type: 'file',
      options: {
        path: '/grafana-dashboard-definitions/0',
      },
    },
  ],
}

Also we cannot pass through a composite path for the dashboard jsons as that will fail, so my hack would just allow for 1 level path to be passed through without it failing.

Alternatively the path can be changed to be a variable and made easier to pass through, however that might be a breaking change for the current version so I'm not sure if that's a viable option, in one attempt I've created a new configuration in which I would pass the folder and dashboards separately but that meant I would lose all dashboards that were not configured that way.

@brancz
Copy link
Owner

brancz commented Jul 11, 2019

This there is no out of the box experience for this today, that is correct. I'd be happy to see it become a reality though, if you figure out something elegant I'd be more than happy to review and merge it :)

@SebastianIoanPop
Copy link
Author

I've had some time to throw together the change today.

https://github.com/SebastianIoanPop/kubernetes-grafana/tree/grafana-folders/non-intrusive-attempt

I still have to test it in K8s and have some concerns to address before creating the PR.
I've ensured that generating the examples from master compared to my branch will create the same output using a basic diff tool so at least it's backwards compatible (except the new example added)

I will come back in a few days to test it and create the PR :)

toran414 added a commit to toran414/kubernetes-grafana that referenced this issue Mar 3, 2020
toran414 added a commit to toran414/kubernetes-grafana that referenced this issue Mar 3, 2020
toran414 added a commit to toran414/kubernetes-grafana that referenced this issue Mar 3, 2020
brancz added a commit that referenced this issue Mar 4, 2020
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

No branches or pull requests

2 participants