Merge ~verterok/charm-graylog:beats-lb into charm-graylog:master

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: James Troup
Approved revision: 651d326ae5496d39d60614d9bf2210d0588ba85a
Merged at revision: ab29d166b1eb89596a7c74e4b7499f8f746c3fc6
Proposed branch: ~verterok/charm-graylog:beats-lb
Merge into: charm-graylog:master
Diff against target: 191 lines (+66/-14)
10 files modified
src/metadata.yaml (+2/-0)
src/reactive/graylog.py (+13/-0)
src/tests/functional/tests/bundles/bionic-graylog2-ha.yaml (+2/-2)
src/tests/functional/tests/bundles/bionic-graylog2.yaml (+2/-2)
src/tests/functional/tests/bundles/bionic-graylog3-ha.yaml (+2/-2)
src/tests/functional/tests/bundles/bionic-graylog3.yaml (+2/-2)
src/tests/functional/tests/bundles/bionic-ha.yaml (+2/-2)
src/tests/functional/tests/bundles/focal-graylog2.yaml (+2/-2)
src/tests/functional/tests/bundles/focal-graylog3.yaml (+2/-2)
src/tests/unit/test_graylog.py (+37/-0)
Reviewer Review Type Date Requested Status
🤖 prod-jenkaas-bootstack (community) continuous-integration Needs Fixing
James Troup (community) Needs Fixing
BootStack Reviewers Pending
Review via email: mp+411035@code.launchpad.net

Commit message

Add support to loadbalance beats protocol using a haproxy in front of a cluster via beats-lb relation

Description of the change

This adds a beats-lb relation, which allows to use haproxy as a reverseproxy for the beats protocol

No tests added, as I was not sure which kind of test a new relation is required for this change: unit or functional? Also, I couldn't find any testing related to haproxy relations, please point me out if I missed something.

e.g:
# deploy a graylog cluster

juju deploy haproxy

juju add-relation haproxy:reverseproxy graylog:beats-lb

juju config haproxy services=$(cat <<-END
- service_name: beats
  service_host: "0.0.0.0"
  service_port: 5044
  service_options:
      - mode tcp
      - balance leastconn
      - timeout server 30000
      - timeout client 30000
  server_options: check inter 2000 rise 2 fall 5 maxconn 200
END
)

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
James Troup (elmo) wrote :

I'd personally be fine with a unit test for this, but given the typo, I do think it needs at least that. I don't object to a functional test, if you want, but given the code change, it seems like overkill to me. I'm curious about the use case?

(See comment inline.)

review: Needs Fixing
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Indeed, this was intended as a PoC of the idea.
As disucssed in MM:
[17:02] │ verterok: I have no proofs, but we have a huge log volume, and some units see a lot more traffic than others. so, if a couple of those "busy" units land in the same graylog node...ka-boom?
[17:02] elmo: ah, I see

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

fixed and pushed

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 :
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 :
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
James Troup (elmo) wrote :

CI still fails, but it fails on trunk too. Approving this for now.

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

Change successfully merged at revision ab29d166b1eb89596a7c74e4b7499f8f746c3fc6

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/metadata.yaml b/src/metadata.yaml
2index c5bdd50..4a88639 100644
3--- a/src/metadata.yaml
4+++ b/src/metadata.yaml
5@@ -19,6 +19,8 @@ provides:
6 interface: http
7 beats:
8 interface: elastic-beats
9+ beats-lb:
10+ interface: http
11 requires:
12 elasticsearch:
13 interface: elasticsearch
14diff --git a/src/reactive/graylog.py b/src/reactive/graylog.py
15index b554506..2bb524d 100644
16--- a/src/reactive/graylog.py
17+++ b/src/reactive/graylog.py
18@@ -838,6 +838,19 @@ def update_reverseproxy_config(website):
19
20
21 @when("graylog.configured")
22+@when("beats-lb.available")
23+def update_beats_reverseproxy_config(beats_lb):
24+ """Share Graylog beats endpoint details for a reverse proxy to use."""
25+ conf = hookenv.config()
26+ beats_port = conf["beats_port"]
27+ if not data_changed("beats_port", beats_port):
28+ # nothing changed
29+ return
30+ if beats_port:
31+ beats_lb.configure(port=beats_port)
32+
33+
34+@when("graylog.configured")
35 @when("graylog.needs_restart")
36 def restart_service(service=SERVICE_NAME):
37 """Restart the service and on failure wait 15 seconds and try again.
38diff --git a/src/tests/functional/tests/bundles/bionic-graylog2-ha.yaml b/src/tests/functional/tests/bundles/bionic-graylog2-ha.yaml
39index 0f34a96..f1376ab 100644
40--- a/src/tests/functional/tests/bundles/bionic-graylog2-ha.yaml
41+++ b/src/tests/functional/tests/bundles/bionic-graylog2-ha.yaml
42@@ -41,7 +41,7 @@ relations:
43 - mongo
44 - - graylog
45 - elastic
46- - - graylog
47- - haproxy
48+ - - graylog:website
49+ - haproxy:reverseproxy
50 - - graylog
51 - nrpe
52diff --git a/src/tests/functional/tests/bundles/bionic-graylog2.yaml b/src/tests/functional/tests/bundles/bionic-graylog2.yaml
53index f97b308..09d2597 100644
54--- a/src/tests/functional/tests/bundles/bionic-graylog2.yaml
55+++ b/src/tests/functional/tests/bundles/bionic-graylog2.yaml
56@@ -45,8 +45,8 @@ relations:
57 - mongo
58 - - graylog
59 - elastic
60- - - graylog
61- - haproxy
62+ - - graylog:website
63+ - haproxy:reverseproxy
64 - - graylog
65 - nrpe
66 - - nagios
67diff --git a/src/tests/functional/tests/bundles/bionic-graylog3-ha.yaml b/src/tests/functional/tests/bundles/bionic-graylog3-ha.yaml
68index ab2238a..8717729 100644
69--- a/src/tests/functional/tests/bundles/bionic-graylog3-ha.yaml
70+++ b/src/tests/functional/tests/bundles/bionic-graylog3-ha.yaml
71@@ -41,7 +41,7 @@ relations:
72 - mongo
73 - - graylog
74 - elastic
75- - - graylog
76- - haproxy
77+ - - graylog:website
78+ - haproxy:reverseproxy
79 - - graylog
80 - nrpe
81diff --git a/src/tests/functional/tests/bundles/bionic-graylog3.yaml b/src/tests/functional/tests/bundles/bionic-graylog3.yaml
82index a4509c3..2c6d6da 100644
83--- a/src/tests/functional/tests/bundles/bionic-graylog3.yaml
84+++ b/src/tests/functional/tests/bundles/bionic-graylog3.yaml
85@@ -45,8 +45,8 @@ relations:
86 - mongo
87 - - graylog
88 - elastic
89- - - graylog
90- - haproxy
91+ - - graylog:website
92+ - haproxy:reverseproxy
93 - - graylog
94 - nrpe
95 - - nagios
96diff --git a/src/tests/functional/tests/bundles/bionic-ha.yaml b/src/tests/functional/tests/bundles/bionic-ha.yaml
97index 8e19581..711b68b 100644
98--- a/src/tests/functional/tests/bundles/bionic-ha.yaml
99+++ b/src/tests/functional/tests/bundles/bionic-ha.yaml
100@@ -42,7 +42,7 @@ relations:
101 - mongo
102 - - graylog
103 - elastic
104- - - graylog
105- - haproxy
106+ - - graylog:website
107+ - haproxy:reverseproxy
108 - - graylog
109 - nrpe
110diff --git a/src/tests/functional/tests/bundles/focal-graylog2.yaml b/src/tests/functional/tests/bundles/focal-graylog2.yaml
111index bb513e6..634fea7 100644
112--- a/src/tests/functional/tests/bundles/focal-graylog2.yaml
113+++ b/src/tests/functional/tests/bundles/focal-graylog2.yaml
114@@ -45,8 +45,8 @@ relations:
115 - mongo
116 - - graylog
117 - elastic
118- - - graylog
119- - haproxy
120+ - - graylog:website
121+ - haproxy:reverseproxy
122 - - graylog
123 - nrpe
124 - - nagios
125diff --git a/src/tests/functional/tests/bundles/focal-graylog3.yaml b/src/tests/functional/tests/bundles/focal-graylog3.yaml
126index ae0991d..1ada366 100644
127--- a/src/tests/functional/tests/bundles/focal-graylog3.yaml
128+++ b/src/tests/functional/tests/bundles/focal-graylog3.yaml
129@@ -45,8 +45,8 @@ relations:
130 - mongo
131 - - graylog
132 - elastic
133- - - graylog
134- - haproxy
135+ - - graylog:website
136+ - haproxy:reverseproxy
137 - - graylog
138 - nrpe
139 - - nagios
140diff --git a/src/tests/unit/test_graylog.py b/src/tests/unit/test_graylog.py
141index dc53ed7..1f9a57a 100644
142--- a/src/tests/unit/test_graylog.py
143+++ b/src/tests/unit/test_graylog.py
144@@ -32,6 +32,7 @@ from reactive.graylog import ( # noqa: E402
145 set_conf,
146 set_jvm_heap_size,
147 tls_request_certificate,
148+ update_beats_reverseproxy_config,
149 update_config,
150 upgrade_charm,
151 validate_jvm_heap_size,
152@@ -894,3 +895,39 @@ class TestEmailConfig(unittest.TestCase):
153 class Config(dict):
154 def __init__(self, *args, **kw):
155 super(Config, self).__init__(*args, **kw)
156+
157+
158+class BeatsLBTestCase(unittest.TestCase):
159+ @mock.patch("charmhelpers.core.hookenv.config")
160+ @mock.patch("reactive.graylog.data_changed")
161+ def test_update_beats_reverseproxy_config(
162+ self,
163+ mock_data_changed,
164+ mock_hookenv_config,
165+ ):
166+ mock_hookenv_config.return_value = {
167+ "beats_port": 5041,
168+ }
169+ mock_data_changed.return_value = True
170+ mock_interface = mock.Mock()
171+
172+ update_beats_reverseproxy_config(mock_interface)
173+
174+ mock_interface.configure.assert_called_once_with(port=5041)
175+
176+ @mock.patch("charmhelpers.core.hookenv.config")
177+ @mock.patch("reactive.graylog.data_changed")
178+ def test_update_beats_reverseproxy_config_no_config_change(
179+ self,
180+ mock_data_changed,
181+ mock_hookenv_config,
182+ ):
183+ mock_hookenv_config.return_value = {
184+ "beats_port": 5041,
185+ }
186+ mock_data_changed.return_value = False
187+ mock_interface = mock.Mock()
188+
189+ update_beats_reverseproxy_config(mock_interface)
190+
191+ mock_interface.configure.assert_not_called()

Subscribers

People subscribed via source and target branches

to all changes: