Merge lp:~bigkevmcd/offspring/monitoring-endpoint-as-slaves-scanned into lp:offspring

Proposed by Kevin McDermott
Status: Merged
Merged at revision: 156
Proposed branch: lp:~bigkevmcd/offspring/monitoring-endpoint-as-slaves-scanned
Merge into: lp:offspring
Diff against target: 176 lines (+76/-11)
5 files modified
lib/offspring/web/queuemanager/models.py (+10/-0)
lib/offspring/web/queuemanager/tests/test_models.py (+16/-2)
lib/offspring/web/queuemanager/tests/test_views.py (+33/-7)
lib/offspring/web/queuemanager/views.py (+15/-1)
lib/offspring/web/urls.py (+2/-1)
To merge this branch: bzr merge lp:~bigkevmcd/offspring/monitoring-endpoint-as-slaves-scanned
Reviewer Review Type Date Requested Status
Nicola Heald Approve
Review via email: mp+144260@code.launchpad.net

Description of the change

This adds /builds/ and /builders/ to allow checking of the master-slave communication, which is the most common failure point at the moment.

To post a comment you must log in.
Revision history for this message
Nicola Heald (notnownikki) wrote :

Looks ok to me, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/offspring/web/queuemanager/models.py'
2--- lib/offspring/web/queuemanager/models.py 2013-01-04 17:45:17 +0000
3+++ lib/offspring/web/queuemanager/models.py 2013-01-22 10:09:19 +0000
4@@ -489,3 +489,13 @@
5 cutoff = datetime.utcnow() - period
6 query = dict(finished_at__gte=cutoff)
7 return BuildResult.objects.filter(**query)
8+
9+
10+def get_updated_builders(period):
11+ """
12+ Return the builders that have been updated within the specified period (a
13+ datetime.timedelta).
14+ """
15+ cutoff = datetime.utcnow() - period
16+ query = dict(updated_at__gte=cutoff)
17+ return Lexbuilder.objects.filter(**query)
18
19=== modified file 'lib/offspring/web/queuemanager/tests/test_models.py'
20--- lib/offspring/web/queuemanager/tests/test_models.py 2013-01-04 17:45:17 +0000
21+++ lib/offspring/web/queuemanager/tests/test_models.py 2013-01-22 10:09:19 +0000
22@@ -10,7 +10,8 @@
23
24 from offspring.enums import ProjectBuildStates
25
26-from offspring.web.queuemanager.models import ProjectGroup, get_completed_builds
27+from offspring.web.queuemanager.models import (
28+ ProjectGroup, get_completed_builds, get_updated_builders, Lexbuilder)
29 from offspring.web.queuemanager.tests.factory import factory
30 from offspring.web.queuemanager.tests.helpers import (
31 create_build_results_with_durations
32@@ -178,7 +179,7 @@
33
34
35
36-class UtilityFunctionTests(TestCase):
37+class UtilityFunctionTests(MockerTestCase, TestCase):
38
39 def test_get_completed_builds(self):
40 """
41@@ -195,3 +196,16 @@
42 finished_at=started_at + timedelta(minutes=30),
43 builder=None)
44 self.assertEqual(2, get_completed_builds(timedelta(hours=1)).count())
45+
46+ def test_get_updated_builders(self):
47+ """
48+ get_updated_builders(timedelta(minutes=10)) should return all
49+ Lexbuilders which have been updated within the last 10 minutes.
50+ """
51+ builder1 = factory.make_lexbuilder()
52+ # This cheats the updated_at autonow value.
53+ Lexbuilder.objects.filter(pk=builder1.pk).update(
54+ updated_at=datetime.utcnow() - timedelta(minutes=12))
55+ builder2 = factory.make_lexbuilder()
56+ builder3 = factory.make_lexbuilder()
57+ self.assertEqual(2, get_updated_builders(timedelta(minutes=10)).count())
58
59=== modified file 'lib/offspring/web/queuemanager/tests/test_views.py'
60--- lib/offspring/web/queuemanager/tests/test_views.py 2013-01-07 11:24:34 +0000
61+++ lib/offspring/web/queuemanager/tests/test_views.py 2013-01-22 10:09:19 +0000
62@@ -11,9 +11,7 @@
63
64 from offspring.enums import ProjectBuildStates
65 from offspring.web.queuemanager.models import (
66- LaunchpadProject,
67- ProjectGroup,
68-)
69+ LaunchpadProject, ProjectGroup, Lexbuilder)
70 from offspring.web.queuemanager.forms import (
71 LaunchpadProjectForm,
72 ProjectGroupForm,
73@@ -525,11 +523,11 @@
74 project_group2.name)
75
76
77-class AliveViewsTests(TestCase):
78+class AliveBuildsViewTests(TestCase):
79
80 def setUp(self):
81 self.view_url = reverse(
82- "offspring.web.queuemanager.views.alive")
83+ "offspring.web.queuemanager.views.alive_builds")
84 self.user = factory.make_user()
85 project = factory.make_project()
86 started_at = datetime.utcnow() - timedelta(hours=2)
87@@ -543,8 +541,8 @@
88
89 def test_alive_returns_build_count(self):
90 """
91- Fetching the /alive URL returns the number of builds completed in the
92- last hour.
93+ Fetching the /alive/builds/ URL returns the number of builds completed
94+ in the last hour.
95 """
96 response = self.client.get(self.view_url)
97 self.assertEqual("2", response.content)
98@@ -556,3 +554,31 @@
99 """
100 response = self.client.get(self.view_url, {"hours": 2})
101 self.assertEqual("3", response.content)
102+
103+
104+class AliveBuildersViewTests(TestCase):
105+
106+ def setUp(self):
107+ self.view_url = reverse(
108+ "offspring.web.queuemanager.views.alive_builders")
109+ builder1 = factory.make_lexbuilder()
110+ Lexbuilder.objects.filter(pk=builder1.pk).update(
111+ updated_at=datetime.utcnow() - timedelta(minutes=12))
112+ builder2 = factory.make_lexbuilder()
113+ builder3 = factory.make_lexbuilder()
114+
115+ def test_alive_returns_updates_builders_count(self):
116+ """
117+ Fetching the /alive/builders/ URL returns the number of builders
118+ updated within the 10 minutes.
119+ """
120+ response = self.client.get(self.view_url)
121+ self.assertEqual("2", response.content)
122+
123+ def test_alive_with_optional_duration(self):
124+ """
125+ It's possible to specify a duration, which is used as a timedelta for
126+ the alive url.
127+ """
128+ response = self.client.get(self.view_url, {"minutes": 15})
129+ self.assertEqual("3", response.content)
130
131=== modified file 'lib/offspring/web/queuemanager/views.py'
132--- lib/offspring/web/queuemanager/views.py 2013-01-07 11:29:44 +0000
133+++ lib/offspring/web/queuemanager/views.py 2013-01-22 10:09:19 +0000
134@@ -58,6 +58,7 @@
135 Project,
136 ProjectGroup,
137 Release,
138+ get_updated_builders,
139 get_completed_builds,
140 )
141
142@@ -389,7 +390,20 @@
143 "queuemanager.add_launchpadproject")(launchpad_project_create)
144
145
146-def alive(request):
147+def alive_builders(request):
148+ """
149+ Returns the number of slaves updated in the last 10 minutes, useful for
150+ checking the "alive" status of Offspring.
151+
152+ Optionally accepts a number of minutes as a parameter to use for the
153+ timedelta.
154+ """
155+ minutes = int(request.GET.get("minutes", 10))
156+ return HttpResponse(
157+ str(get_updated_builders(timedelta(minutes=minutes)).count()))
158+
159+
160+def alive_builds(request):
161 """
162 Returns the number of completed builds in the last hour, useful for checking
163 the "alive" status of Offspring.
164
165=== modified file 'lib/offspring/web/urls.py'
166--- lib/offspring/web/urls.py 2013-01-02 17:18:09 +0000
167+++ lib/offspring/web/urls.py 2013-01-22 10:09:19 +0000
168@@ -97,7 +97,8 @@
169 (r'^schedule/\+api/milestones/$', milestone_handler),
170 (r'^schedule/\+(?P<milestoneType>[^/]+)-milestones$', 'offspring.web.queuemanager.views.milestones'),
171 (r'^schedule/$', 'offspring.web.queuemanager.views.schedule'),
172- (r'^alive/', 'offspring.web.queuemanager.views.alive'),
173+ (r'^alive/builders/', 'offspring.web.queuemanager.views.alive_builders'),
174+ (r'^alive/builds/', 'offspring.web.queuemanager.views.alive_builds'),
175 (r'^$', 'offspring.web.queuemanager.views.projects'),
176 )
177

Subscribers

People subscribed via source and target branches