Merge ~twom/launchpad:stats-can-the-builders-count into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: af7276751e073b4f1b3756fbd9463a6fd713ed3e
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:stats-can-the-builders-count
Merge into: launchpad:master
Diff against target: 215 lines (+57/-4)
5 files modified
lib/lp/buildmaster/model/buildfarmjobbehaviour.py (+9/-0)
lib/lp/buildmaster/tests/test_buildfarmjobbehaviour.py (+18/-1)
lib/lp/oci/tests/test_ocirecipebuildbehaviour.py (+9/-1)
lib/lp/snappy/tests/test_snapbuildbehaviour.py (+8/-1)
lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py (+13/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+391610@code.launchpad.net

Commit message

Add counts for build dispatches

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
af72767... by Tom Wardill

Add other package tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/buildmaster/model/buildfarmjobbehaviour.py b/lib/lp/buildmaster/model/buildfarmjobbehaviour.py
2index fa44fb9..edff53b 100644
3--- a/lib/lp/buildmaster/model/buildfarmjobbehaviour.py
4+++ b/lib/lp/buildmaster/model/buildfarmjobbehaviour.py
5@@ -34,6 +34,7 @@ from lp.services.config import config
6 from lp.services.helpers import filenameToContentType
7 from lp.services.librarian.interfaces import ILibraryFileAliasSet
8 from lp.services.librarian.utils import copy_and_close
9+from lp.services.statsd.interfaces.statsd_client import IStatsdClient
10 from lp.services.utils import sanitise_urls
11 from lp.services.webapp import canonical_url
12
13@@ -152,6 +153,14 @@ class BuildFarmJobBehaviourBase:
14 (status, info) = yield self._slave.build(
15 cookie, builder_type, chroot.content.sha1, filename_to_sha1, args)
16
17+ # Update stats
18+ job_type = getattr(self.build, 'job_type', None)
19+ job_type_name = job_type.name if job_type else 'UNKNOWN'
20+ getUtility(IStatsdClient).incr(
21+ 'build.count,job_type={},builder_name={}'.format(
22+ job_type_name,
23+ self._builder.name))
24+
25 logger.info(
26 "Job %s (%s) started on %s: %s %s"
27 % (cookie, self.build.title, self._builder.url, status, info))
28diff --git a/lib/lp/buildmaster/tests/test_buildfarmjobbehaviour.py b/lib/lp/buildmaster/tests/test_buildfarmjobbehaviour.py
29index 8cbda44..3bdf53d 100644
30--- a/lib/lp/buildmaster/tests/test_buildfarmjobbehaviour.py
31+++ b/lib/lp/buildmaster/tests/test_buildfarmjobbehaviour.py
32@@ -44,6 +44,7 @@ from lp.buildmaster.tests.mock_slaves import (
33 from lp.registry.interfaces.pocket import PackagePublishingPocket
34 from lp.services.config import config
35 from lp.services.log.logger import BufferLogger
36+from lp.services.statsd.tests import StatsMixin
37 from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
38 from lp.testing import (
39 TestCase,
40@@ -55,6 +56,7 @@ from lp.testing.fakemethod import FakeMethod
41 from lp.testing.layers import (
42 LaunchpadZopelessLayer,
43 ZopelessDatabaseLayer,
44+ ZopelessLayer,
45 )
46 from lp.testing.mail_helpers import pop_notifications
47
48@@ -155,8 +157,9 @@ class TestBuildFarmJobBehaviourBase(TestCaseWithFactory):
49 self.assertIs(False, behaviour.extraBuildArgs()["fast_cleanup"])
50
51
52-class TestDispatchBuildToSlave(TestCase):
53+class TestDispatchBuildToSlave(StatsMixin, TestCase):
54
55+ layer = ZopelessLayer
56 run_tests_with = AsynchronousDeferredRunTest
57
58 def makeBehaviour(self, das):
59@@ -260,6 +263,20 @@ class TestDispatchBuildToSlave(TestCase):
60 self.assertDispatched(
61 slave, logger, 'chroot-fooix-bar-y86.tar.gz', 'chroot')
62
63+ @defer.inlineCallbacks
64+ def test_dispatchBuildToSlave_stats(self):
65+ self.setUpStats()
66+ behaviour = self.makeBehaviour(FakeDistroArchSeries())
67+ builder = MockBuilder()
68+ slave = OkSlave()
69+ logger = BufferLogger()
70+ behaviour.setBuilder(builder, slave)
71+ yield behaviour.dispatchBuildToSlave(logger)
72+ self.assertEqual(1, self.stats_client.incr.call_count)
73+ self.assertEqual(
74+ self.stats_client.incr.call_args_list[0][0],
75+ ('build.count,job_type=UNKNOWN,builder_name=mock-builder',))
76+
77
78 class TestGetUploadMethodsMixin:
79 """Tests for `IPackageBuild` that need objects from the rest of LP."""
80diff --git a/lib/lp/oci/tests/test_ocirecipebuildbehaviour.py b/lib/lp/oci/tests/test_ocirecipebuildbehaviour.py
81index 9a15fb9..ded60cf 100644
82--- a/lib/lp/oci/tests/test_ocirecipebuildbehaviour.py
83+++ b/lib/lp/oci/tests/test_ocirecipebuildbehaviour.py
84@@ -76,6 +76,7 @@ from lp.services.config import config
85 from lp.services.features.testing import FeatureFixture
86 from lp.services.log.logger import DevNullLogger
87 from lp.services.propertycache import get_property_cache
88+from lp.services.statsd.tests import StatsMixin
89 from lp.services.webapp import canonical_url
90 from lp.soyuz.adapters.archivedependencies import (
91 get_sources_list_for_building,
92@@ -150,7 +151,8 @@ class TestOCIBuildBehaviour(TestCaseWithFactory):
93 self.assertProvides(job, IBuildFarmJobBehaviour)
94
95
96-class TestAsyncOCIRecipeBuildBehaviour(MakeOCIBuildMixin, TestCaseWithFactory):
97+class TestAsyncOCIRecipeBuildBehaviour(
98+ StatsMixin, MakeOCIBuildMixin, TestCaseWithFactory):
99
100 run_tests_with = AsynchronousDeferredRunTestForBrokenTwisted.make_factory(
101 timeout=10)
102@@ -176,6 +178,7 @@ class TestAsyncOCIRecipeBuildBehaviour(MakeOCIBuildMixin, TestCaseWithFactory):
103 "time.time", return_value=self.now))
104 self.useFixture(FeatureFixture({OCI_RECIPE_ALLOW_CREATE: 'on'}))
105 self.addCleanup(shut_down_default_process_pool)
106+ self.setUpStats()
107
108 def assertHasNoZopeSecurityProxy(self, data):
109 """Makes sure that data doesn't contain a security proxy.
110@@ -370,6 +373,11 @@ class TestAsyncOCIRecipeBuildBehaviour(MakeOCIBuildMixin, TestCaseWithFactory):
111 yield job.dispatchBuildToSlave(DevNullLogger())
112 self.assertEqual(
113 ('ensurepresent', lxd_lfa.http_url, '', ''), slave.call_log[0])
114+ self.assertEqual(1, self.stats_client.incr.call_count)
115+ self.assertEqual(
116+ self.stats_client.incr.call_args_list[0][0],
117+ ('build.count,job_type=OCIRECIPEBUILD,builder_name={}'.format(
118+ builder.name),))
119
120 @defer.inlineCallbacks
121 def test_dispatchBuildToSlave_falls_back_to_chroot(self):
122diff --git a/lib/lp/snappy/tests/test_snapbuildbehaviour.py b/lib/lp/snappy/tests/test_snapbuildbehaviour.py
123index 37bc7d2..ca4debb 100644
124--- a/lib/lp/snappy/tests/test_snapbuildbehaviour.py
125+++ b/lib/lp/snappy/tests/test_snapbuildbehaviour.py
126@@ -86,6 +86,7 @@ from lp.services.log.logger import (
127 BufferLogger,
128 DevNullLogger,
129 )
130+from lp.services.statsd.tests import StatsMixin
131 from lp.services.webapp import canonical_url
132 from lp.snappy.interfaces.snap import (
133 SNAP_PRIVATE_FEATURE_FLAG,
134@@ -283,7 +284,7 @@ class TestSnapBuildBehaviour(TestSnapBuildBehaviourBase):
135 self.assertIn("Missing chroot", str(e))
136
137
138-class TestAsyncSnapBuildBehaviour(TestSnapBuildBehaviourBase):
139+class TestAsyncSnapBuildBehaviour(StatsMixin, TestSnapBuildBehaviourBase):
140 run_tests_with = AsynchronousDeferredRunTestForBrokenTwisted.make_factory(
141 timeout=10)
142
143@@ -306,6 +307,7 @@ class TestAsyncSnapBuildBehaviour(TestSnapBuildBehaviourBase):
144 self.useFixture(fixtures.MockPatch(
145 "time.time", return_value=self.now))
146 self.addCleanup(shut_down_default_process_pool)
147+ self.setUpStats()
148
149 def makeJob(self, **kwargs):
150 # We need a builder slave in these tests, in order that requesting a
151@@ -779,6 +781,11 @@ class TestAsyncSnapBuildBehaviour(TestSnapBuildBehaviourBase):
152 yield job.dispatchBuildToSlave(DevNullLogger())
153 self.assertEqual(
154 ('ensurepresent', lxd_lfa.http_url, '', ''), slave.call_log[0])
155+ self.assertEqual(1, self.stats_client.incr.call_count)
156+ self.assertEqual(
157+ self.stats_client.incr.call_args_list[0][0],
158+ ('build.count,job_type=SNAPBUILD,builder_name={}'.format(
159+ builder.name),))
160
161 @defer.inlineCallbacks
162 def test_dispatchBuildToSlave_falls_back_to_chroot(self):
163diff --git a/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py b/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
164index aa79d81..e773d17 100644
165--- a/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
166+++ b/lib/lp/soyuz/tests/test_binarypackagebuildbehaviour.py
167@@ -58,6 +58,7 @@ from lp.registry.interfaces.sourcepackage import SourcePackageFileType
168 from lp.services.config import config
169 from lp.services.librarian.interfaces import ILibraryFileAliasSet
170 from lp.services.log.logger import BufferLogger
171+from lp.services.statsd.tests import StatsMixin
172 from lp.services.webapp import canonical_url
173 from lp.soyuz.adapters.archivedependencies import (
174 get_sources_list_for_building,
175@@ -74,7 +75,7 @@ from lp.testing.keyserver import InProcessKeyServerFixture
176 from lp.testing.layers import LaunchpadZopelessLayer
177
178
179-class TestBinaryBuildPackageBehaviour(TestCaseWithFactory):
180+class TestBinaryBuildPackageBehaviour(StatsMixin, TestCaseWithFactory):
181 """Tests for the BinaryPackageBuildBehaviour.
182
183 In particular, these tests are about how the BinaryPackageBuildBehaviour
184@@ -90,6 +91,7 @@ class TestBinaryBuildPackageBehaviour(TestCaseWithFactory):
185 def setUp(self):
186 super(TestBinaryBuildPackageBehaviour, self).setUp()
187 switch_dbuser('testadmin')
188+ self.setUpStats()
189
190 @defer.inlineCallbacks
191 def assertExpectedInteraction(self, call_log, builder, build, chroot,
192@@ -182,6 +184,11 @@ class TestBinaryBuildPackageBehaviour(TestCaseWithFactory):
193 yield self.assertExpectedInteraction(
194 slave.call_log, builder, build, lf, archive,
195 ArchivePurpose.PRIMARY, 'universe')
196+ self.assertEqual(1, self.stats_client.incr.call_count)
197+ self.assertEqual(
198+ self.stats_client.incr.call_args_list[0][0],
199+ ('build.count,job_type=PACKAGEBUILD,builder_name={}'.format(
200+ builder.name),))
201
202 @defer.inlineCallbacks
203 def test_non_virtual_ppa_dispatch_with_primary_ancestry(self):
204@@ -233,6 +240,11 @@ class TestBinaryBuildPackageBehaviour(TestCaseWithFactory):
205 interactor.getBuildBehaviour(bq, builder, slave), BufferLogger())
206 yield self.assertExpectedInteraction(
207 slave.call_log, builder, build, lf, archive, ArchivePurpose.PPA)
208+ self.assertEqual(1, self.stats_client.incr.call_count)
209+ self.assertEqual(
210+ self.stats_client.incr.call_args_list[0][0],
211+ ('build.count,job_type=PACKAGEBUILD,builder_name={}'.format(
212+ builder.name),))
213
214 @defer.inlineCallbacks
215 def test_private_source_dispatch(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: