Merge ~vultaire/charm-grafana:cmr-app-dashboard-titles into charm-grafana:candidate/21.07

Proposed by Paul Goins
Status: Merged
Approved by: Xav Paice
Approved revision: 40b7d0e6a7a2848404775f3d88fa727a024e6d4d
Merged at revision: 40b7d0e6a7a2848404775f3d88fa727a024e6d4d
Proposed branch: ~vultaire/charm-grafana:cmr-app-dashboard-titles
Merge into: charm-grafana:candidate/21.07
Diff against target: 64 lines (+27/-7)
2 files modified
src/lib/charms/layer/grafana.py (+24/-7)
src/tests/unit/test_grafana.py (+3/-0)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Celia Wang Approve
🤖 prod-jenkaas-bootstack continuous-integration Approve
Review via email: mp+406051@code.launchpad.net

Commit message

Skip "remote-<hash>" remote app names on dashboards

To post a comment you must log in.
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

FAILED: Continuous integration, rev:7e533f6299998ac95ff02def43ad9fdb909229a4

No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want jenkins to rebuild you need to trigger it yourself):
https://code.launchpad.net/~vultaire/charm-grafana/+git/grafana-charm/+merge/406051/+edit-commit-message

https://jenkins.canonical.com/bootstack/job/lp-charm-grafana-ci/33/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/bootstack/job/lp-charm-test-unit-withcompiler/118/
    None: https://jenkins.canonical.com/bootstack/job/lp-update-mp/330/

Click here to trigger a rebuild:
https://jenkins.canonical.com/bootstack/job/lp-charm-grafana-ci/33//rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

FAILED: Continuous integration, rev:40b7d0e6a7a2848404775f3d88fa727a024e6d4d

No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want jenkins to rebuild you need to trigger it yourself):
https://code.launchpad.net/~vultaire/charm-grafana/+git/grafana-charm/+merge/406051/+edit-commit-message

https://jenkins.canonical.com/bootstack/job/lp-charm-grafana-ci/34/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/bootstack/job/lp-charm-test-unit-withcompiler/119/
    None: https://jenkins.canonical.com/bootstack/job/lp-update-mp/331/

Click here to trigger a rebuild:
https://jenkins.canonical.com/bootstack/job/lp-charm-grafana-ci/34//rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Celia Wang (ziyiwang) wrote :

lgtm

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

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/lib/charms/layer/grafana.py b/src/lib/charms/layer/grafana.py
2index 009c812..d8fc7b8 100644
3--- a/src/lib/charms/layer/grafana.py
4+++ b/src/lib/charms/layer/grafana.py
5@@ -43,21 +43,38 @@ def get_admin_password():
6
7
8 def compute_dash_title(title, remote_app=None):
9- """Compute title for dashboards."""
10+ """Compute title for dashboards.
11+
12+ The returned title will typically be of the form "[<prefix>-<appname>] <title>",
13+ although there are some exceptions where the header portion will be shortened or
14+ omitted.
15+
16+ """
17 if remote_app is None:
18 # "local" / backward compat case -- we don't have a remote app
19 return title or "Untitled"
20
21 if not title:
22 title = remote_app
23+
24+ prefix = "juju"
25+ # For titles with an embedded prefix (e.g. of form "[prefix] title"), extract the
26+ # components.
27 mat = TITLE_PAT.search(title)
28 if mat and len(mat.groups()) == 2:
29- # If the title already is in the form "[xxx] Footitle" enrich
30- # the [xxx] tag with remote_app
31- new_title = "[{}-{}] {}".format(mat.group(1), remote_app, mat.group(2))
32- else:
33- new_title = "[juju-{}] {}".format(remote_app, title)
34- return new_title
35+ prefix, title = mat.groups()
36+
37+ # Header is of form "<prefix>-<app>", unless <app> is not suitable for display for
38+ # some reason, in which case we simply use the prefix.
39+ header_tokens = [prefix]
40+ # Apps seen via cross-model relationships show up with names like
41+ # remote-<128-bit hash>; omit the app name in this case.
42+ skip_app_name = remote_app.startswith("remote-")
43+ if not skip_app_name:
44+ header_tokens.append(remote_app)
45+ header = "-".join(header_tokens)
46+
47+ return "[{}] {}".format(header, title)
48
49
50 def get_folders():
51diff --git a/src/tests/unit/test_grafana.py b/src/tests/unit/test_grafana.py
52index 2645b53..663fa17 100644
53--- a/src/tests/unit/test_grafana.py
54+++ b/src/tests/unit/test_grafana.py
55@@ -95,6 +95,9 @@ class GrafanaTestCase(unittest.TestCase):
56 ((None, "app"), "[juju-app] app"),
57 (("bar", None), "bar"),
58 ((None, None), "Untitled"),
59+ # Cross-model relation cases (detected via remote-<128-bit hash> names)
60+ (("foo", "remote-0123456789abcdef0123456789abcdef"), "[juju] foo"),
61+ (("[x] foo", "remote-0123456789abcdef0123456789abcdef"), "[x] foo"),
62 )
63 for inputs, expect in inputs_expect:
64 self.assertEqual(compute_dash_title(*inputs), expect)

Subscribers

People subscribed via source and target branches

to all changes: