[stable/prometheus-operator] Can't override the prometheus-operator provided Grafana data source.
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):
- Install prometheus-operator chart with default values.
- 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
kubectl port-forward svc/****-grafana 3000:80where **** is replaced by the name of the created prometheus-operator chart.- Log in (the default user is admin and password is prom-operator)
- Go to http://localhost:3000/datasources and observe that Loki probably lost, which may be a comic book spoiler.
kubectl logs ***** grafana-sc-datasourceswhere ***** 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.
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, 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
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
It should not be named datasource.yaml! Please name it something_else.yaml to be loaded.
@paskal should i need to restart grafana or is the configuration automatically applied.
Arffff it does not work at all even and i upgrade prom ops with --recreate-pods
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.
I'd ask what is the status here? Anyone is working on it? Otherwise I could pick up it.
I'd expressed an intention to play with it, but haven't gotten around to it.
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.
It looks like this may have been fixed by https://github.com/helm/charts/pull/11501.
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.
This issue is being automatically closed due to inactivity.
Any solution for this? I would like to overwrite the default data source
No
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: defaultI'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
additionalDataSourceskey. 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.