Aller au contenu

Manage Grafana Datasources#

Manage industrialized Grafana-mutualized datasource (NGOT)#

Grafana parameters are defined in envs-ng in zones/ngot_zones/client-<CLIENT>.cue file.

This example illustrates several use-cases:

"svc-grafana-client-devteam01": {
    let shortname = "devteam01"
    let connected_zones = "10000:1:test04,test06"
    type:               "service"
    subtype:            "grafana-client"
    parent_zone_name:   "kub-10010"
    contract_zone_name: "obs-\(shortname)"
    parameters: {
        _thanos_query_connected_services_mutualized: "\(connected_zones)": _
        thanos_query_connected_services: _thanos_query_connected_services_mutualized[connected_zones]

        _datasource_thanos: "\(shortname)":            _
        _mutualized_datasource_alertmanager: "test04": _
        _mutualized_datasource_alertmanager: "test06": _

        datasources: {
            _datasource_thanos[shortname]
            thanos: jsonData: manageAlerts: false
            _mutualized_datasource_alertmanager["test04"]
            _mutualized_datasource_alertmanager["test06"]
        }
        expose_thanos_query: true
    }
}

Note

This should work for all Grafanas, not only Grafana-mutualized. However, other Grafanas use default parameters and setting similar parameters has not been tested.

Step 1 : Edit the Grafana zone parameters#

Here is what you can do:

  • Add or remove an Alertmanager datasource:
    • Goal: add (or remove) a datasource in Grafana in Alerting -> Active notifications
    • The lines to add or remove for an Alertmanager datasource are:
      _mutualized_datasource_alertmanager: "xxxx": _
      ...
      datasources: {
              ...
              _mutualized_datasource_alertmanager["xxxx"]
      
    • To add or remove an Alertmanager datasource, add or remove the 2 lines above for any target Alertmanager.
  • Enable or disable management of PrometheusRules in Grafana
    • Goal: enable or remove the visibility on PrometheusRules in Grafana in Alerting -> Alert Rules
    • To disable the visibility, add this line (see the example above):
      thanos: jsonData: manageAlerts: false
      
    • To enable the visibility, find the line above and remove it.

Step 2 : Regenerate the static zone files#

generate-static-zones-files

Step 3 : Redeploy datasources#

Warning

Do not forget to follow the Changes Workflow (MR, validation, CAASCHR...)

trackbone apply -c grafana -z <zone>

Connect to Grafana and control that the datasources are the expected ones. This important, do not bypass this step!

Step 4 : Remove cached datasources#

This step is necessary only if a datasource was removed and still appears in Grafana.

  1. Edit the Grafana configuration:

    kswitch <zone>
    kubectl -n grafana-client-obs-<CLIENT> edit cm grafana-obs-<CLIENT>
    

    You should find a section data -> datasources.yaml -> deleteDatasources. In this section, you should notice that the datasource that you removed is missing (this is expected).

  2. Add the datasource in the deleteDatasources section. Example:

    data:
      datasource.yaml:
        apiVersion: 1
        datasources:
          ...
        deleteDatasources:
        - name: thanos
          orgId: 1
        - name: <the datasource to delete>
          orgId: 1
        ...
    

  3. Then restart Grafana (delete the pod).

  4. In Grafana, control that the datasource has disappeared.
  5. Run trackbone apply ... (from step 3) again to restore the configmaps (and remove the datasource in deleteDatasources section.
  6. Restart Grafana again.
  7. In Grafana, control again that the datasource has disappeared.

Add/update/remove non-industrialized Grafana datasource#

Method 1: using configmaps#

Use this method for permanent datasources : they will remain across pod deletion/restarts

Add datasource#

Step 1: Identify the datasource label#

This information is referenced by grafana.sidecar.datasources.label in envs-ng grafana configurations (in file grafana.cue).

Datasources label:

  • datasources_label: "grafana-datasource-caascad"
  • grafana_datasource: "1"

For more information regarding datasource label:

Step 2 : Create datasource configuration section in grafana envs-ng#

In envs-ng grafana.cue file, append the datasource to existing datasources.

Step 3 : Deploy datasources#

Caascad (contexts/caascad)

  • trackbone apply -c grafana-cloud-caascad -z <zone>

  • trackbone apply -c grafana-infra-caascad -z <zone>

  • trackbone apply -c grafana-cloud-client -z <zone>

NGOT (contexts/ngot)

trackbone apply -c grafana -z <zone>

Update datasource#

Edit grafana.cue, redeploy with Trackbone. Then restart the pod if it has not restarted automatically.

Delete datasource#

Edit grafana.cue, redeploy with Trackbone. Then restart the pod if it has not restarted automatically.

Method 2: using graphical interface#

Use this method for temporary datasources : they will NOT remain across pod deletion/restarts. They are useful only for debugging.

To have access to Grafana datasources, you need to connect to Grafana interface as admin user.

For more information regarding the retrieval of admin password for Grafana see Manage Administrator account for Grafana documentation.

Add datasource#

Once authenticated in Grafana web interface, in the left side menu, select Configuration > Data Sources.

Click on the button + Add data source in the top header.

Select the plugin that fits your datasource and fill down Name and URL mandatory fields.

Click on the button Save and test.

Update datasource#

Once authenticated in Grafana web interface, in the left side menu, select Configuration > Data Sources.

Select the datasource that you want to modify, make desired modifications and click Save and test button.

Delete datasource#

Once authenticated in Grafana web interface, in the left side menu, select Configuration > Data Sources.

Select the datasource that you want to delete and click on the button Delete.