Skip to content

Commit 359e9e8

Browse files
authored
feat: add dashboard uuid to avoid duplication (#48)
* feat: add dashboard uuid to avoid duplication * fix linting
1 parent 74605fe commit 359e9e8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

grafana_dashboards/grafana/dashboard.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# under the License.
1414

1515
import json
16+
import uuid
1617

1718
from requests import exceptions
1819

@@ -40,6 +41,16 @@ def create(self, name, data, overwrite=False, folder_id=0):
4041
:raises Exception: if dashboard already exists
4142
4243
"""
44+
# Only set uid if it's not already present
45+
if "uid" not in data:
46+
# Generate deterministic UUID v5 using DNS namespace
47+
# Using grafana.com as the namespace
48+
namespace_uuid = uuid.uuid5(uuid.NAMESPACE_DNS, "grafana.com")
49+
# Generate a UUID v5 from the name in this namespace
50+
dashboard_uuid = uuid.uuid5(namespace_uuid, name)
51+
# Use first 8 characters of the UUID as Grafana prefers shorter UIDs
52+
data["uid"] = str(dashboard_uuid)
53+
4354
dashboard = {
4455
"dashboard": data,
4556
"folderId": folder_id,

0 commit comments

Comments
 (0)