Grafana Provisioning Datasource Error — Quick Fix
In this tutorial, you'll learn about Grafana Provisioning Datasource Error. We cover key concepts, practical examples, and best practices.
The Problem
Grafana cannot load datasources configured in the provisioning directory. The datasources may not appear in the UI, or the provisioning system may report parse errors. The datasource names appear in the UI but connections fail.
Error example:
Failed to load provisioning config: yaml: unmarshal errors: line 10: field datasources not found
Failed to provision datasource 'Prometheus': cannot create datasource: datasource name already exists
Failed to create datasource 'Loki': missing URL
The Fix
Step 1: Validate the YAML syntax
WRONG — using incorrect indentation or structure:
# WRONG — incorrect structure
datasources:
- name: Prometheus
type: prometheus
RIGHT — use correct YAML structure:
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
Validate the YAML:
python3 -c "import yaml; yaml.safe_load(open('/etc/grafana/provisioning/datasources/prometheus.yaml'))"
Step 2: Check for API version and required fields
WRONG — omitting required fields like access or url:
# Missing required fields
datasources:
- name: Loki
type: loki
RIGHT — include all required fields:
apiVersion: 1
datasources:
- name: Loki
type: loki
access: proxy
url: http://loki:3100
jsonData:
maxLines: 1000
Use DodaTech's Datasource Provisioning Validator to check YAML syntax, required fields, and API version compatibility across all provisioning files.
Prevention Tips
- Always include
apiVersion: 1as the first line - Place provisioning files in
/etc/<a href="/devops/prometheus-grafana/">grafana</a>/provisioning/datasources/ - Use
deleteDatasourcesto handle name collisions - Test datasource connectivity in the Grafana UI after provisioning
- Use DodaTech's Grafana Config Auditor for automated provisioning validation
Common Mistakes with provision datasource
- Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists - Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
These mistakes appear frequently in real-world GRAFANA code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Related: DodaTech's Infrastructure-as-Code for Grafana guide provides Terraform and Ansible examples for automating datasource provisioning across environments.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro