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 (community) 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
diff --git a/src/lib/charms/layer/grafana.py b/src/lib/charms/layer/grafana.py
index 009c812..d8fc7b8 100644
--- a/src/lib/charms/layer/grafana.py
+++ b/src/lib/charms/layer/grafana.py
@@ -43,21 +43,38 @@ def get_admin_password():
4343
4444
45def compute_dash_title(title, remote_app=None):45def compute_dash_title(title, remote_app=None):
46 """Compute title for dashboards."""46 """Compute title for dashboards.
47
48 The returned title will typically be of the form "[<prefix>-<appname>] <title>",
49 although there are some exceptions where the header portion will be shortened or
50 omitted.
51
52 """
47 if remote_app is None:53 if remote_app is None:
48 # "local" / backward compat case -- we don't have a remote app54 # "local" / backward compat case -- we don't have a remote app
49 return title or "Untitled"55 return title or "Untitled"
5056
51 if not title:57 if not title:
52 title = remote_app58 title = remote_app
59
60 prefix = "juju"
61 # For titles with an embedded prefix (e.g. of form "[prefix] title"), extract the
62 # components.
53 mat = TITLE_PAT.search(title)63 mat = TITLE_PAT.search(title)
54 if mat and len(mat.groups()) == 2:64 if mat and len(mat.groups()) == 2:
55 # If the title already is in the form "[xxx] Footitle" enrich65 prefix, title = mat.groups()
56 # the [xxx] tag with remote_app66
57 new_title = "[{}-{}] {}".format(mat.group(1), remote_app, mat.group(2))67 # Header is of form "<prefix>-<app>", unless <app> is not suitable for display for
58 else:68 # some reason, in which case we simply use the prefix.
59 new_title = "[juju-{}] {}".format(remote_app, title)69 header_tokens = [prefix]
60 return new_title70 # Apps seen via cross-model relationships show up with names like
71 # remote-<128-bit hash>; omit the app name in this case.
72 skip_app_name = remote_app.startswith("remote-")
73 if not skip_app_name:
74 header_tokens.append(remote_app)
75 header = "-".join(header_tokens)
76
77 return "[{}] {}".format(header, title)
6178
6279
63def get_folders():80def get_folders():
diff --git a/src/tests/unit/test_grafana.py b/src/tests/unit/test_grafana.py
index 2645b53..663fa17 100644
--- a/src/tests/unit/test_grafana.py
+++ b/src/tests/unit/test_grafana.py
@@ -95,6 +95,9 @@ class GrafanaTestCase(unittest.TestCase):
95 ((None, "app"), "[juju-app] app"),95 ((None, "app"), "[juju-app] app"),
96 (("bar", None), "bar"),96 (("bar", None), "bar"),
97 ((None, None), "Untitled"),97 ((None, None), "Untitled"),
98 # Cross-model relation cases (detected via remote-<128-bit hash> names)
99 (("foo", "remote-0123456789abcdef0123456789abcdef"), "[juju] foo"),
100 (("[x] foo", "remote-0123456789abcdef0123456789abcdef"), "[x] foo"),
98 )101 )
99 for inputs, expect in inputs_expect:102 for inputs, expect in inputs_expect:
100 self.assertEqual(compute_dash_title(*inputs), expect)103 self.assertEqual(compute_dash_title(*inputs), expect)

Subscribers

People subscribed via source and target branches

to all changes: