Merge lp:~bigkevmcd/offspring/build-stats-for-project-group into lp:offspring

Proposed by Kevin McDermott
Status: Merged
Merged at revision: 116
Proposed branch: lp:~bigkevmcd/offspring/build-stats-for-project-group
Merge into: lp:offspring
Prerequisite: lp:~bigkevmcd/offspring/non-scheduled-builds
Diff against target: 141 lines (+77/-7)
2 files modified
lib/offspring/web/queuemanager/metrics.py (+19/-7)
lib/offspring/web/queuemanager/tests/test_metrics.py (+58/-0)
To merge this branch: bzr merge lp:~bigkevmcd/offspring/build-stats-for-project-group
Reviewer Review Type Date Requested Status
Guilherme Salgado Needs Fixing
Offspring Committers Pending
Review via email: mp+85627@code.launchpad.net

Description of the change

This adds functionality allowing the metrics to be gathered per project group.

To post a comment you must log in.
132. By Kevin McDermott

Add failing test for get_average_queue_time with a ProjectGroup.

133. By Kevin McDermott

And add it to the get_average_build_time code.

134. By Kevin McDermott

Remove extra character from docstring.

135. By Kevin McDermott

Merge forward.

136. By Kevin McDermott

Merge forward.

137. By Kevin McDermott

Merge forward.

138. By Kevin McDermott

Merge forward.

Revision history for this message
Guilherme Salgado (salgado) wrote :

You don't seem to use seconds_into_time() anywhere, so I'd just remove it and re-add in whichever branch needs it, if there is one.

I'd have made get_average_time() raise an error if the client passes both a project and a project_group, but given that the docstring states what will happen in that case it's no big deal, so go with whichever you prefer

Here you also use the factory to create a build result and right after it you set its started_at/finished_at attributes, which can now be removed as the factory method should take those attributes as arguments (from the fix you did in your previous branch ;)

The docstring of test_get_average_build_time_with_excludes_projects_not_in_group(self) is identical to that of the previous test method:

140 + """
141 + All Projects in a ProjectGroup should be included in the average
142 + buildtime.
143 + """

review: Needs Fixing
139. By Kevin McDermott

Address Salgado's review points.

140. By Kevin McDermott

Merge forward.

Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

> You don't seem to use seconds_into_time() anywhere, so I'd just remove it and
> re-add in whichever branch needs it, if there is one.

Yeah, I was going to use it for the output, but I decided against it :-)

>
> I'd have made get_average_time() raise an error if the client passes both a
> project and a project_group, but given that the docstring states what will
> happen in that case it's no big deal, so go with whichever you prefer

This seems reasonable, lemme do this in a tiny separate branch, merging forward is proving troublesome...

> Here you also use the factory to create a build result and right after it you
> set its started_at/finished_at attributes, which can now be removed as the
> factory method should take those attributes as arguments (from the fix you did
> in your previous branch ;)

Fixed!

> The docstring of
> test_get_average_build_time_with_excludes_projects_not_in_group(self) is
> identical to that of the previous test method:

Fixed!

Thanks for the review.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/offspring/web/queuemanager/metrics.py'
2--- lib/offspring/web/queuemanager/metrics.py 2012-01-12 08:35:32 +0000
3+++ lib/offspring/web/queuemanager/metrics.py 2012-01-12 08:35:32 +0000
4@@ -4,7 +4,8 @@
5 from offspring.enums import ProjectBuildStates
6
7
8-def get_average_time(query_params, columns, project=None, automated=None):
9+def get_average_time(query_params, columns, project=None, automated=None,
10+ project_group=None):
11
12 """
13 Return the average time between the two named columns.
14@@ -19,10 +20,14 @@
15
16 project: A Project to filter BuildResults with, if none supplied, will use
17 all Projects
18+ project_group: A ProjectGroup to filter BuildResults with, if supplied,
19+ this will average all Projects within the ProjectGroup.
20 automated: If not None, filter BuildResults using the requestor, if True,
21 only BuildResults with no requestor will be used, otherwise
22 BuildResults with the requestor field populated will be used.
23 period: A tuple of datetime objects (start_time, end_time)
24+
25+ NOTE: If project and project_group are supplied, only project will be used.
26 """
27 # FIXME: This should really be done using PostgreSQL queries, but the tests
28 # don't run using PostgreSQL...
29@@ -37,6 +42,9 @@
30 * 10 ** 6) / 10 ** 6)
31 if project is not None:
32 query_params["project"] = project
33+ else:
34+ if project_group is not None:
35+ query_params["project__project_group"] = project_group
36
37 if automated is not None:
38 query_params["requestor__isnull"] = automated
39@@ -49,7 +57,8 @@
40 return float(sum(times)) / len(time_stamps)
41
42
43-def get_average_build_time(project=None, automated=None, period=None):
44+def get_average_build_time(project=None, automated=None, period=None,
45+ project_group=None):
46 """
47 Return the average time taken between BuildResult.started_at and
48 BuildResult.finished_at in seconds for all BuildResults associated with the
49@@ -64,10 +73,12 @@
50 if period is not None:
51 query_params["finished_at__range"] = period
52 return get_average_time(query_params, ("started_at", "finished_at"),
53- project=project, automated=automated)
54-
55-
56-def get_average_queue_time(project=None, automated=None, period=None):
57+ project=project, automated=automated,
58+ project_group=project_group)
59+
60+
61+def get_average_queue_time(project=None, automated=None, period=None,
62+ project_group=None):
63 """
64 Return the average time taken between BuildResult.requested_at and
65 BuildResult.dispatched_at in seconds for all BuildResults associated with the
66@@ -81,7 +92,8 @@
67 if period is not None:
68 query_params["dispatched_at__range"] = period
69 return get_average_time(query_params, ("requested_at", "dispatched_at"),
70- project=project, automated=automated)
71+ project=project, automated=automated,
72+ project_group=project_group)
73
74
75 def get_build_result_metrics():
76
77=== modified file 'lib/offspring/web/queuemanager/tests/test_metrics.py'
78--- lib/offspring/web/queuemanager/tests/test_metrics.py 2012-01-12 08:35:32 +0000
79+++ lib/offspring/web/queuemanager/tests/test_metrics.py 2012-01-12 08:35:32 +0000
80@@ -315,3 +315,61 @@
81 ("Average requested queue time (30 days)", 23.25*60),
82 ("Average requested queue time (90 days)", 25.5*60)],
83 get_build_result_metrics())
84+
85+
86+class ProjectGroupBuildMetricsTests(TestCase):
87+
88+ def setUp(self):
89+ self.project_group = factory.make_project_group()
90+ self.project = factory.make_project(project_group=self.project_group)
91+
92+ def test_get_average_build_time_with_project_group(self):
93+ """
94+ get_average_build_time should take a project group, and calculate the
95+ average build time of all projects within that group.
96+ """
97+ build_result = factory.make_build_result(
98+ project=self.project, result=ProjectBuildStates.SUCCESS)
99+ finished_at = datetime.now()
100+ build_result.finished_at = finished_at
101+ build_result.started_at = finished_at - timedelta(minutes=10)
102+ build_result.save()
103+ self.assertEqual(
104+ 10*60,
105+ get_average_build_time(project_group=self.project_group))
106+
107+ def test_get_average_build_time_with_multiple_projects_in_group(self):
108+ """
109+ All Projects in a ProjectGroup should be included in the average
110+ buildtime.
111+ """
112+ create_build_results_with_durations(self.project, [10, 20])
113+ project2 = factory.make_project(project_group=self.project_group)
114+ create_build_results_with_durations(project2, [20, 30])
115+ # 10 + 20 + 20 + 30 / 4 = 20 minutes
116+ self.assertEqual(
117+ 20*60,
118+ get_average_build_time(project_group=self.project_group))
119+
120+ def test_get_average_build_time_with_excludes_projects_not_in_group(self):
121+ """
122+ Only Projects in a ProjectGroup should be included in the average
123+ buildtime.
124+ """
125+ create_build_results_with_durations(self.project, [10, 20])
126+ project2 = factory.make_project()
127+ create_build_results_with_durations(project2, [20, 30])
128+ # 10 + 20 / 2 = 15 minutes
129+ self.assertEqual(
130+ 15*60,
131+ get_average_build_time(project_group=self.project_group))
132+
133+ def test_get_average_queue_time_with_project_group(self):
134+ """
135+ get_average_queue_time should take a project group, and calculate the
136+ average queue time of all projects within that group.
137+ """
138+ create_build_results_with_queue_times(self.project, [10, 20])
139+ self.assertEqual(
140+ 15*60,
141+ get_average_queue_time(project_group=self.project_group))

Subscribers

People subscribed via source and target branches