Change the grafana default Prometheus data source URL
What happened?
Hello ! I modified the Prometheus parameter routePrefix when using the Prometheus-operator
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
image: quay.io/prometheus/prometheus:v2.28.1
# add
routePrefix: /prometheus
When I tried to use Grafana, the default Prometheus data source did not work
I tried to change the URL address of the default data source and it didn't work, but I added the data source manually and it worked
So I went to the Yaml file about grafana
cat manifests/grafana-dashboardDatasources.yaml | grep "datasources.yaml" | cut -d " " -f 4 | base64 -d
{
"apiVersion": 1,
"datasources": [
{
"access": "proxy",
"editable": false,
"name": "prometheus",
"orgId": 1,
"type": "prometheus",
"url": "http://prometheus-k8s.monitoring.svc:9090",
"version": 1
}
]
}
I look for the Jsonnet file generated by this configuration
cat vendor/grafana/grafana.libsonnet
...
grafana+:: {
labels: {
'app.kubernetes.io/name': 'grafana',
'app.kubernetes.io/version': $._config.versions.grafana,
'app.kubernetes.io/component': 'grafana',
},
dashboards: {},
rawDashboards: {},
folderDashboards: {},
datasources: [{
name: 'prometheus',
type: 'prometheus',
access: 'proxy',
orgId: 1,
url: 'http://' + $._config.prometheus.serviceName + '.' + $._config.namespace + '.svc:9090',
version: 1,
editable: false,
}],
...
I wrote my example.jsonnet file and modified it with the following configuration to get what I wanted, but I didn't think it was ideal
example.jsonnet
local kp =
(import 'kube-prometheus/main.libsonnet') +
// Uncomment the following imports to enable its patches
// (import 'kube-prometheus/addons/anti-affinity.libsonnet') +
// (import 'kube-prometheus/addons/managed-cluster.libsonnet') +
// (import 'kube-prometheus/addons/node-ports.libsonnet') +
// (import 'kube-prometheus/addons/static-etcd.libsonnet') +
// (import 'kube-prometheus/addons/custom-metrics.libsonnet') +
// (import 'kube-prometheus/addons/external-metrics.libsonnet') +
{
values+:: {
common+: {
namespace: 'monitoring',
},
grafana+: {
datasources+:: [{
// url: grafana_value._config.grafana.datasources(self.url),
name: 'prometheus',
type: 'prometheus',
access: 'proxy',
orgId: 1,
url: "http://prometheus-k8s.monitoring.svc:9090/prometheus",
version: 1,
editable: false,
}],
},
},
};
Did you expect to see some different?
I want to change the value of datasources.url directly and leave the rest unchanged.
How should I write the example.jsonnet file correctly and effectively ?
How to reproduce it (as minimally and precisely as possible):
Environment
- Prometheus Operator version:
release-0.8
- Kubernetes version information:
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.8", GitCommit:"5575935422cc1cf5169dfc8847cb587aa47bac5a", GitTreeState:"clean", BuildDate:"2021-06-16T13:00:45Z", GoVersion:"go1.15.13", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.8", GitCommit:"5575935422cc1cf5169dfc8847cb587aa47bac5a", GitTreeState:"clean", BuildDate:"2021-06-16T12:53:07Z", GoVersion:"go1.15.13", Compiler:"gc", Platform:"linux/amd64"}
<!-- Replace the command with its output above -->
-
Kubernetes cluster kind:
insert how you created your cluster: kops, bootkube, tectonic-installer, etc.
-
Manifests:
insert manifests relevant to the issue
- Prometheus Operator Logs:
Insert Prometheus Operator logs relevant to the issue here
- Prometheus Logs:
Insert Prometheus logs relevant to the issue here
Anything else we need to know?:
Currently what you wrote is what is expected. Potentially after https://github.com/brancz/kubernetes-grafana/pull/117 is merged, we can make this simpler and allow modifying only one parameter.
This issue has been automatically marked as stale because it has not had any activity in the last 60 days. Thank you for your contributions.
This issue was closed because it has not had any activity in the last 120 days. Please reopen if you feel this is still valid.