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

Manage the default datasource #113

Open
ludzzz opened this issue Mar 4, 2021 · 3 comments
Open

Manage the default datasource #113

ludzzz opened this issue Mar 4, 2021 · 3 comments

Comments

@ludzzz
Copy link

ludzzz commented Mar 4, 2021

Hi,

Is there a way to interact with the default datasource (the one named prometheus)?

Specifically, I would like to rename it through config/jsonnet.
Or completely disable it and to add it myself in the _config.grafana+.datasources+

Thank you

@brancz
Copy link
Owner

brancz commented Mar 4, 2021

Yes you can do this. As you noted you can find it in _config.grafana.datasources. An example modifying it could be:

local grafana = import 'grafana/grafana.libsonnet';

{
  local basic =
    (grafana {
       _config+:: {
         namespace: 'monitoring-grafana',
         grafana+:: {
           datasources: [{
             name: 'prometheus',
             type: 'prometheus',
             access: 'proxy',
             orgId: 1,
             url: 'http://my-prometheus:1234',
             version: 1,
             editable: false,
           }],
         },
       },
     }).grafana,

  apiVersion: 'v1',
  kind: 'List',
  items:
    basic.dashboardDefinitions +
    [
      basic.dashboardSources,
      basic.dashboardDatasources,
      basic.deployment,
      basic.serviceAccount,
      basic.service {
        spec+: { ports: [
          port {
            nodePort: 30910,
          }
          for port in super.ports
        ] },
      },
    ],
}

Does that help?

@ludzzz
Copy link
Author

ludzzz commented Mar 9, 2021

It did help!

first I am sorry, I didn't give you the full picture.
I am using the Kube-Prometheus stack, I am not directly using this library, But since my question was related to this library I thought it would be a good place to ask.
I am a layer upper. So I am using the kube-prometheus stack on one of my clusters with grafana included and it will connect to other Prometheus instances on other clusters.

But overall, thanks to your answer, I got the mechanism and I understood the main issue was my knowledge of the jsonnet.

Here with what I came up with:
If you reading this careful I am using it on the kube-prometheus stack

local kp =
  (import 'kube-prometheus/kube-prometheus.libsonnet') +
  {
    _config+:: {
      grafana+: {
        datasources: [
                       if x.name == 'prometheus'
                       then x { name: 'cluster1-prometheus', url: 'http://prometheus.cluster1:9090' }
                       else x
                       for x in super.datasources
                     ] +
                     [
                       {
                         name: 'cluster2-prometheus',
                         type: 'prometheus',
                         org_id: 2,
                         url: 'http://prometheus.cluster2:9090',
                         version: 1,
                         editable: true,
                       },
                     ],
      },
    },
  };
{ ['grafana-' + name]: kp._config.grafana[name] for name in std.filter((function(name) name == 'datasources'), std.objectFields(kp._config.grafana)) }

Do you think I need to post it on kube-prometheus for knowledge sharing?

@brancz
Copy link
Owner

brancz commented Mar 10, 2021

I think it's absolutely worth adding a documentation page for this in the kube-prometheus project!

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