charts icon indicating copy to clipboard operation
charts copied to clipboard

[stable/prometheus-operator] Can't override the prometheus-operator provided Grafana data source.

Open wirehead opened this issue 7 years ago • 16 comments

Is this a request for help?: No


Is this a BUG REPORT or FEATURE REQUEST? Feature Request, bordering on bug.

Version of Helm and Kubernetes: Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.0", GitCommit:"ddf47ac13c1a9483ea035a79cd7c10005ff21a6d", GitTreeState:"clean", BuildDate:"2018-12-03T21:04:45Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"windows/amd64"} Server Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.3", GitCommit:"435f92c719f279a3a67808c80521ea17d5715c66", GitTreeState:"clean", BuildDate:"2018-11-26T12:46:57Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"linux/amd64"}

Client: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"} Server: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}

Which chart: prometheus-operator

What happened: prometheus-operator provides a ConfigMap to configure Grafana's data sources. It also allows you to use a configmap with the right keys to configure Grafana's data sources. However, Grafana only accepts one datasources.yaml file, which means that if you happen to be a strange person like myself and wanted to screw with the Prometheus-Operator and Loki at the same time, I have to go in and manually configure Loki. (Also, Grafana persistence is broken)

What you expected to happen: I think that there needs to be a boolean flag in the Prometheus-operator to indicate that I want to configure my own Grafana data sources.

How to reproduce it (as minimally and precisely as possible):

  1. Install prometheus-operator chart with default values.
  2. Paste this yaml file into kube create because you can bet that a yaml file some Internet rando told you to paste into kube create is always going to be safe:
apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-datasource-loki
  labels:
    grafana_datasource: "1"
data:
  datasource.yaml: |-
    apiVersion: 1
    datasources:
    - name: Loki
      type: loki
      url: http://loki:3100/
      access: proxy
      isDefault: false
  1. kubectl port-forward svc/****-grafana 3000:80 where **** is replaced by the name of the created prometheus-operator chart.
  2. Log in (the default user is admin and password is prom-operator)
  3. Go to http://localhost:3000/datasources and observe that Loki probably lost, which may be a comic book spoiler.
  4. kubectl logs ***** grafana-sc-datasources where ***** is replaced by the name of your grafana pod. Observe that it probably looks something like this:
Starting config map collector
Config for cluster api loaded...
Working on configmap default/loki-promtail
Working on configmap default/rafting-blackbird-grafana
Working on configmap default/rafting-blackbird-promethe-grafana-dashboard-k8s-resources-pod
Working on configmap default/rafting-blackbird-grafana-config-dashboards
Working on configmap default/rafting-blackbird-promethe-grafana-dashboard-k8s-cluster-rsrc-u
Working on configmap default/rafting-blackbird-promethe-grafana-dashboard-k8s-node-rsrc-use
Working on configmap default/grafana-datasource-loki
Configmap with label found
File in configmap datasource.yaml ADDED
Working on configmap default/rafting-blackbird-promethe-grafana-datasource
Configmap with label found
File in configmap datasource.yaml ADDED
Working on configmap default/rafting-blackbird-promethe-grafana-coredns-k8s
Working on configmap default/rafting-blackbird-promethe-grafana-dashboard-etcd
Working on configmap default/rafting-blackbird-promethe-grafana-dashboard-k8s-resources-name
Working on configmap default/rafting-blackbird-promethe-grafana-dashboard-statefulset
Working on configmap default/incendiary-terrier-nginx-ingress-controller
Working on configmap default/rafting-blackbird-promethe-grafana-dashboard-k8s-resources-clus
Working on configmap default/loki
Working on configmap default/rafting-blackbird-promethe-grafana-dashboard-nodes
Working on configmap default/prometheus-rafting-blackbird-promethe-prometheus-rulefiles-0

showing that it did, in fact, load a datasource.yaml twice.

Anything else we need to know: I tried naming it something else to see if Grafana was a directory-friendly piece of software but that didn't help.

wirehead avatar Jan 06 '19 02:01 wirehead

It loads latest datasource.yaml it found, and only it. To add your own data source, please change file name so it will be added properly without fighting for name with original file.

paskal avatar Jan 10 '19 18:01 paskal

@paskal, i tried to create my own data source file, i see it on the grafana container in the provisioning folder but it is not loaded in the ui. What did i miss ?

PS: I did it for dashboards and it works like a charm

angegar avatar Jan 16 '19 17:01 angegar

BTW i tried to modify the prometheus operator datasource config with my datasource, but it failed too :(

data:
  datasource.yaml: |-
    apiVersion: 1
    datasources: 
      - name: myDataSource
        type: cloudwatch
        authType: arn
        assumeRoleArn: arn:aws:iam::<accountid>:role/grafana
        defaultRegion: us-east-1
        version: 1

angegar avatar Jan 16 '19 18:01 angegar

It should not be named datasource.yaml! Please name it something_else.yaml to be loaded.

paskal avatar Jan 16 '19 18:01 paskal

@paskal should i need to restart grafana or is the configuration automatically applied.

angegar avatar Jan 16 '19 19:01 angegar

Arffff it does not work at all even and i upgrade prom ops with --recreate-pods

angegar avatar Jan 16 '19 19:01 angegar

Okay, I finally poked at things some more.

The following ConfigMap should work with prom-operator 1.7.0:

apiVersion: v1
data:
  something_else.yaml: |-
    apiVersion: 1
    datasources:
    - name: myDataSource
      type: cloudwatch
      authType: arn
      assumeRoleArn: arn:aws:iam::<accountid>:role/grafana
      defaultRegion: us-east-1
      version: 1
kind: ConfigMap
metadata:
  labels:
    app: prometheus-operator-grafana
    grafana_datasource: "1"
  name: loki-datasource
  namespace: default

I'm confused because I'd thought that I'd tried this combination, but I clearly didn't.

After having poked at this for a bit, I think the "right" user story here is that we really ought to have a additionalDataSources key. I might take a swing at it over the weekend.

wirehead avatar Jan 17 '19 05:01 wirehead

I'd ask what is the status here? Anyone is working on it? Otherwise I could pick up it.

mazzy89 avatar Jan 31 '19 10:01 mazzy89

I'd expressed an intention to play with it, but haven't gotten around to it.

wirehead avatar Jan 31 '19 14:01 wirehead

Just in case this is any help, I've just come across a bug in the Grafana chart that causes the data sources to not load properly. It's actually just been fixed in the Grafana chart by https://github.com/helm/charts/pull/9842.

Basically what's happening is that the bit that picks up the datasources from ConfigMaps and puts them into /etc/grafana/provisioning/datasources was setup as a side-car container rather than an init container, but Grafana needs the files to exist before it starts up. So you end up with a race condition where sometimes it happens to load the data sources correct, but sometimes it doesn't. Very frustrating!

What I did was manually edited the Grafana deployment, and switched the datasource loader as per that PR, and it instantly started working correctly. Maybe try that with your Loki datasource, and if it fixes it it's possible that all that's needs to happen is for prometheus-operator to upgrade to the latest version of the Grafana chart.

Until that's sorted, I've worked around it by setting the grafana.replicas setting to 0, and replacing it with my own copy of the Deployment that has the right fix. Bit annoying, but it works.

adam-resdiary avatar Feb 14 '19 12:02 adam-resdiary

It looks like this may have been fixed by https://github.com/helm/charts/pull/11501.

adam-resdiary avatar Feb 28 '19 15:02 adam-resdiary

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any further update will cause the issue/pull request to no longer be considered stale. Thank you for your contributions.

stale[bot] avatar Mar 30 '19 15:03 stale[bot]

This issue is being automatically closed due to inactivity.

stale[bot] avatar Apr 13 '19 15:04 stale[bot]

Any solution for this? I would like to overwrite the default data source

c4m4 avatar Aug 04 '20 06:08 c4m4

No

VipulZopSmart avatar Aug 19 '21 09:08 VipulZopSmart

The solution is explained above. This should be working as expected. If you encounter any issue please check the Grafana pod for logs and the container grafana-sc-datasources.

Okay, I finally poked at things some more.

The following ConfigMap should work with prom-operator 1.7.0:

apiVersion: v1
data:
  something_else.yaml: |-
    apiVersion: 1
    datasources:
    - name: myDataSource
      type: cloudwatch
      authType: arn
      assumeRoleArn: arn:aws:iam::<accountid>:role/grafana
      defaultRegion: us-east-1
      version: 1
kind: ConfigMap
metadata:
  labels:
    app: prometheus-operator-grafana
    grafana_datasource: "1"
  name: loki-datasource
  namespace: default

I'm confused because I'd thought that I'd tried this combination, but I clearly didn't.

After having poked at this for a bit, I think the "right" user story here is that we really ought to have a additionalDataSources key. I might take a swing at it over the weekend.

If still needed can we move the discussion at https://github.com/prometheus-community/helm-charts? Since this is a deprecated repo.

marinflorin avatar Sep 09 '21 08:09 marinflorin