grafana / helm-charts

Apache License 2.0
1.66k stars 2.28k forks source link

how to rename existing datasource from the datasource configmap? #98

Open shay-berman opened 3 years ago

shay-berman commented 3 years ago

I tried to change the datasource name in my configmap and then reload grafana (using kube-prometheus-stack helm) but then it just added another datasource with the new name.

Is it posible to rename datasource in grafana via the configmap?


kubectl get cm prom-kube-prometheus-stack-grafana-datasource -o yaml
apiVersion: v1
data:
  datasource.yaml: |-
    apiVersion: 1
    datasources:
    - access: proxy
      editable: false
      name: prometheus1
      type: prometheus
      url: http://prometheus:9090
kind: ConfigMap
metadata:
  annotations:
    meta.helm.sh/release-name: prom
    meta.helm.sh/release-namespace: prometheus
  labels:
    app: kube-prometheus-stack-grafana
    app.kubernetes.io/managed-by: Helm
    chart: kube-prometheus-stack-11.1.1
    grafana_datasource: "1"
    heritage: Helm
    release: prom
  name: prom-kube-prometheus-stack-grafana-datasource
  namespace: prometheus

but if I kubectl edit this configmap and change the name from prometheus1 -> prometheusX, it will not actually rename the datasource on grafana, it will add another one.

is it posible to rename grafana datasource in k8s? (reminder when using datasource as configmap its not posible to edit the datasource from the Grafana UI)

shay-berman commented 3 years ago

anyone?

also opened in kube-prometheus-stack https://github.com/prometheus-community/helm-charts/issues/443

GMartinez-Sisti commented 3 years ago

@shay-berman is this helpful: https://github.com/grafana/helm-charts/blob/main/charts/grafana/README.md#sidecar-for-datasources ?

Adding this to your datasource definition could fix you problem:

# list of datasources that should be deleted from the database
    deleteDatasources:
      - name: Prometheus
        orgId: 1
GMartinez-Sisti commented 3 years ago

Forget what I mentioned above. I think you want this:

https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml#L629

Ghazgkull commented 3 years ago

@GMartinez-Sisti Looking for the same information and I found this issue. Unfortunately, it looks like your link to the values.yaml file includes a line number instead of a permalink. That line in the values file doesn't appear relevant to this discussion. Would you mind sharing a permalink to the content you had in mind as the solution to this issue? Or share an example of how to rename the default "Prometheus" datasource?

GMartinez-Sisti commented 3 years ago

@Ghazgkull you are right. My bad, sorry!

I don’t remember the entire context, but at that date this was the state of the file and it makes sense:

https://github.com/prometheus-community/helm-charts/blob/06960b9eefcf7dd571a5212deb2bd7c485e5f784/charts/kube-prometheus-stack/values.yaml#L629

trexx commented 9 months ago

For anyone coming here: As part of provisioning the datasource, you can specify a unique ID rather than have Grafana generate one automatically by using the uid field. Hardcoding this ensures any panels referencing this data source will continue to work. Unfortunately we run in to another problem where the sidecar detects duplicate uid's and fails. There you have to use the "deleteDatasources" to have the sidecar delete and recreate the data sources as unfortunately the sidecar has no overwriting facility.

      - name: Some JSON datasource
        uid: b2aa4114-c29c-4402-bb7f-2b4b4f251184
        type: marcusolsson-json-datasource
        url: https://localhost