Merge ~tcuthbert/charm-grafana:master into charm-grafana:master

Proposed by Thomas Cuthbert
Status: Merged
Approved by: Xav Paice
Approved revision: d31cbc771473ccf8748ef680c8f79e9550e1f0a2
Merged at revision: 0eb6f0de35c7076946e0b82da8e20a292555bc8f
Proposed branch: ~tcuthbert/charm-grafana:master
Merge into: charm-grafana:master
Diff against target: 23 lines (+12/-0)
1 file modified
reactive/grafana.py (+12/-0)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Alvaro Uria (community) Needs Fixing
Adam Dyess (community) Approve
Joel Sing (community) +1 Approve
Review via email: mp+387275@code.launchpad.net

Commit message

Newer versions of Grafana require a unique uid for each datasource

Description of the change

As per, https://rt.admin.canonical.com/Ticket/Display.html?id=126670#txn-2984750, we need to ensure that each Grafana Data Source has a unique uid, per organisation.

The way I have implemented this is to just hash the datasource URL, which is unique, and converting it to a 32bit integer as SQLite3 overflows with Python's 64bit ints.

unit-grafana-2: 05:26:06 DEBUG unit.grafana/2.grafana-source-relation-changed OverflowError: Python int too large to convert to SQLite INTEGER

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Joel Sing (jsing) wrote :

LGTM, but see comments inline.

review: Approve (+1)
Revision history for this message
Adam Dyess (addyess) wrote :

LGTM also

review: Approve
Revision history for this message
Alvaro Uria (aluria) wrote :

In general, change looks good. However, functional tests fail because bionic-snap and focal-snap gate tests specify "snap_channel: 6/stable". I think that line should be removed and use the default (7/stable).

Several comments:
* Change in Grafana v7 was added here [1]
* data_source table schemas for v6 and v7 show that v7 has "uid" (see [2])
* Default APT package is v7
* Default snap_channel is 7/stable

This change will break install_method=snap and snap_channel=6/edge or snap_channel=stable (which is latest/stable and currently points to 6/stable revision).

The path forward will be to:
* merge and release (once the func tests that use install_method=snap are fixed) in cs:~llama-charmers/grafana
* For stable/20.08 release, we will make latest/stable match 7/stable (otherwise, this fix would need to track which version of grafana is in use, and if it is v6, then skip adding "uid" in generate_query function)

1. https://github.com/grafana/grafana/pull/23585
2. https://pastebin.ubuntu.com/p/jGb72gDzzZ/

review: Needs Fixing
Revision history for this message
Alvaro Uria (aluria) wrote :

I've reviewed the change and it lgtm. However, we still need to support Grafana v6, which is available via snap. I've suggested a MP to merge against your repo [1]

OTOH, once it is merged (if you agree), I would recommend rebasing from master as I see conflicts with the main branch. I did so locally and also had to add an extra relation in base.yaml, and all tests passed (see [2]).

Let me know what you think. With these changes, I think it would be ready to merge.

Thank you.

1. https://code.launchpad.net/~aluria/charm-grafana/+git/grafana-charm-1/+merge/387944
2. https://pastebin.ubuntu.com/p/zRCPjGp7NH/

review: Needs Fixing
Revision history for this message
Xav Paice (xavpaice) wrote :

Known issue is causing test failure:

2020-07-28 17:42:36 [INFO] ======================================================================
2020-07-28 17:42:36 [INFO] FAIL: test_11_dashboard_upgrade (tests.test_grafana.CharmOperationTest)
2020-07-28 17:42:36 [INFO] Test upgraded dashboards are imported.
2020-07-28 17:42:36 [INFO] ----------------------------------------------------------------------
2020-07-28 17:42:36 [INFO] Traceback (most recent call last):
2020-07-28 17:42:36 [INFO] File "./tests/test_grafana.py", line 156, in test_11_dashboard_upgrade
2020-07-28 17:42:36 [INFO] self.assertTrue(chk(dashes))
2020-07-28 17:42:36 [INFO] AssertionError: False is not true
2020-07-28 17:42:36 [INFO] ----------------------------------------------------------------------

This issue is unrelated to this change, mentioning here just for completeness.

LGTM, +1

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 0eb6f0de35c7076946e0b82da8e20a292555bc8f

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/grafana.py b/reactive/grafana.py
2index 4434b17..502d7c8 100644
3--- a/reactive/grafana.py
4+++ b/reactive/grafana.py
5@@ -934,6 +934,18 @@ def generate_query(ds, is_default, id=None, org_id=1):
6 dtime,
7 ]
8
9+ config = hookenv.config()
10+ if config["install_method"] == "apt" or config[
11+ "snap_channel"
12+ ].startswith("7/"):
13+ fields.append("uid")
14+ # Grafana's SQLite3 database has a unique constraint on the org_id
15+ # and uid field, so generate one based on a hash of the data source
16+ # url which is unique.
17+ # The 32 bit mask is necessary because Python's 64 bit ints are too
18+ # large for SQLite3.
19+ values.append(hash(ds["url"]) & 0xFFFFFFFF)
20+
21 # Used in connecting a mysql source
22 if "database" in ds:
23 hookenv.log("Adding fields for the database")

Subscribers

People subscribed via source and target branches

to all changes: