Merge ~ballot/cassandra-charm/+git/cassandra-charm:cRT#135443 into cassandra-charm:master

Proposed by Benjamin Allot
Status: Superseded
Proposed branch: ~ballot/cassandra-charm/+git/cassandra-charm:cRT#135443
Merge into: cassandra-charm:master
Diff against target: 101 lines (+79/-0)
3 files modified
LICENSE (+0/-0)
metadata.yaml (+3/-0)
reactive/cassandra/metrics.py (+76/-0)
Reviewer Review Type Date Requested Status
Cassandra Charmers Pending
Review via email: mp+419194@code.launchpad.net
To post a comment you must log in.

Unmerged commits

82de0b6... by Benjamin Allot

Add missing LICENSE file

669f6ab... by Benjamin Allot

Add relation for cassandra metrics

This provides a cassandra-metrics relation, providing the listen address
and port used for cassandra.
To be used in relation with telegraf

83b618e... by Benjamin Allot

Allow charmcraft pack

Add the charmcraft.yaml file and ignore .charm files

06ad2e2... by William Grant

add external cluster options

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/LICENSE b/LICENSE
2new file mode 100644
3index 0000000..e69de29
4--- /dev/null
5+++ b/LICENSE
6diff --git a/metadata.yaml b/metadata.yaml
7index ca123a9..82f4709 100644
8--- a/metadata.yaml
9+++ b/metadata.yaml
10@@ -34,6 +34,9 @@ provides:
11 nrpe-external-master:
12 interface: nrpe-external-master
13 scope: container
14+ cassandra-metrics:
15+ interface: cassandra-metrics
16+ scope: container
17 peers:
18 cluster:
19 interface: cassandra-cluster
20diff --git a/reactive/cassandra/metrics.py b/reactive/cassandra/metrics.py
21new file mode 100644
22index 0000000..54bb4bf
23--- /dev/null
24+++ b/reactive/cassandra/metrics.py
25@@ -0,0 +1,76 @@
26+# Copyright 2015-2022 Canonical Ltd.
27+#
28+# This file is part of the Cassandra Charm for Juju.
29+#
30+# This program is free software: you can redistribute it and/or modify
31+# it under the terms of the GNU General Public License version 3, as
32+# published by the Free Software Foundation.
33+#
34+# This program is distributed in the hope that it will be useful, but
35+# WITHOUT ANY WARRANTY; without even the implied warranties of
36+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
37+# PURPOSE. See the GNU General Public License for more details.
38+#
39+# You should have received a copy of the GNU General Public License
40+# along with this program. If not, see <http://www.gnu.org/licenses/>.
41+
42+import time
43+
44+from charmhelpers.core import (
45+ hookenv,
46+ host,
47+)
48+from charms import (
49+ leadership,
50+ reactive,
51+)
52+from charms.layer import cassandra
53+from charms.reactive import (
54+ when,
55+ when_any,
56+ when_not,
57+)
58+
59+
60+ENDPOINT = "cassandra-metrics"
61+
62+
63+@when_any("config.changed",
64+ "endpoint.cassandra-metrics.joined",
65+ "endpoint.cassandra-metrics.departed",
66+ "endpoint.cassandra-metrics.changed")
67+def trigger_publish():
68+ reactive.clear_flag("cassandra.metrics.published")
69+
70+
71+@when_not("cassandra.metrics.published")
72+@when(cassandra.metrics.available)
73+def publish():
74+ """Publish relation data needed for Cassandra metrics."""
75+
76+ relations = reactive.endpoint_from_name("cassandra-metrics")
77+ if not relations:
78+ return
79+ hookenv.log("Relations: {}".format(relations), hookenv.DEBUG)
80+ for rel in relations:
81+ if rel.application_name is not None:
82+ publish_listen_addr(rel)
83+ publish_port(rel)
84+
85+ reactive.set_flag("cassandra.metrics.published")
86+
87+
88+def publish_listen_addr(rel):
89+ """Put the Cassandra unit address in the relation data."""
90+
91+ ip = hookenv.network_get(ENDPOINT)['bind-addresses'][0]['addresses'][0]['address']
92+ hookenv.log("IP found for cassandra: {}".format(ip), hookenv.DEBUG)
93+ rel.to_publish_raw["listen_address"] = ip
94+
95+
96+def publish_port(rel):
97+ """Put the Cassandra client port in the relation data."""
98+
99+ port = cassandra.read_cassandra_yaml()["native_transport_port"]
100+ hookenv.log("Port found for cassandra: {}".format(port), hookenv.DEBUG)
101+ rel.to_publish_raw["native_transport_port"] = port

Subscribers

People subscribed via source and target branches