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

Subscribers

People subscribed via source and target branches