Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #1149 from AdrianGaudebert/852466-release-channel-…

…search

Fixes bug 852466 - Added release channel filter in search report/list se...
  • Loading branch information...
commit b5f3f0ba1b9386b8945c7ba8f9afb6358c73bb88 2 parents eb3b1a8 + 1b7048a
Chris Lonnen authored
8  docs/middleware.rst
Source Rendered
@@ -273,6 +273,8 @@ Optional parameters
273 273
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
274 274
 | reasons                | String or list of strings     | None           | Restricts search to crashes caused by this reason.                                                                                                      |
275 275
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  276
+| release_channels       | String or list of strings     | None           | Restricts search to crashes with these release channels.                                                                                                |
  277
++------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
276 278
 | build\_ids             | Integer or list of integers   | None           | Restricts search to crashes that happened on a product with this build ID.                                                                              |
277 279
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
278 280
 | build\_from            | Integer or list of integers   | None           | Restricts search to crashes with a build id greater than this.                                                                                          |
@@ -498,6 +500,8 @@ Optional parameters
498 500
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
499 501
 | reasons                | String or list of strings     | None           | Restricts search to crashes caused by this reason.                                                                                                      |
500 502
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  503
+| release_channels       | String or list of strings     | None           | Restricts search to crashes with these release channels.                                                                                                |
  504
++------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
501 505
 | build\_ids             | Integer or list of integers   | None           | Restricts search to crashes that happened on a product with this build ID.                                                                              |
502 506
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
503 507
 | build\_from            | Integer or list of integers   | None           | Restricts search to crashes with a build id greater than this.                                                                                          |
@@ -1384,6 +1388,8 @@ Optional parameters
1384 1388
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
1385 1389
 | reasons                | String or list of strings     | None           | Restricts search to crashes caused by this reason.                                                                                                      |
1386 1390
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  1391
+| release_channels       | String or list of strings     | None           | Restricts search to crashes with these release channels.                                                                                                |
  1392
++------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
1387 1393
 | build_ids              | Integer or list of integers   | None           | Restricts search to crashes that happened on a product with this build ID.                                                                              |
1388 1394
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
1389 1395
 | build\_from            | Integer or list of integers   | None           | Restricts search to crashes with a build id greater than this.                                                                                          |
@@ -1641,6 +1647,8 @@ Optional parameters
1641 1647
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
1642 1648
 | reasons                | String or list of strings     | None           | Restricts search to crashes caused by this reason.                                                                                                      |
1643 1649
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  1650
+| release_channels       | String or list of strings     | None           | Restricts search to crashes with these release channels.                                                                                                |
  1651
++------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
1644 1652
 | build\_ids             | Integer or list of integers   | None           | Restricts search to crashes that happened on a product with this build ID.                                                                              |
1645 1653
 +------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
1646 1654
 | build\_from            | Integer or list of integers   | None           | Restricts search to crashes with a build id greater than this.                                                                                          |
7  socorro/external/elasticsearch/base.py
@@ -176,6 +176,13 @@ def build_query_from_params(params, config):
176 176
             filters["and"].append(
177 177
                             ElasticSearchBase.build_terms_query("reason",
178 178
                                     [x.lower() for x in params["reasons"]]))
  179
+        if params["release_channels"]:
  180
+            filters["and"].append(
  181
+                ElasticSearchBase.build_terms_query(
  182
+                    "release_channel",
  183
+                    [x.lower() for x in params["release_channels"]]
  184
+                )
  185
+            )
179 186
 
180 187
         filters["and"].append({
181 188
                 "range": {
10  socorro/external/elasticsearch/search.py
@@ -41,6 +41,16 @@ def get(self, **kwargs):
41 41
         Optional arguments: see SearchCommon.get_parameters()
42 42
 
43 43
         """
  44
+        # change aliases from the web to the implementation's need
  45
+        if "for" in kwargs and "terms" not in kwargs:
  46
+            kwargs["terms"] = kwargs.get("for")
  47
+        if "from" in kwargs and "from_date" not in kwargs:
  48
+            kwargs["from_date"] = kwargs.get("from")
  49
+        if "to" in kwargs and "to_date" not in kwargs:
  50
+            kwargs["to_date"] = kwargs.get("to")
  51
+        if "in" in kwargs and "fields" not in kwargs:
  52
+            kwargs["fields"] = kwargs.get("in")
  53
+
44 54
         params = search_common.get_parameters(kwargs)
45 55
 
46 56
         # Get information about the versions
13  socorro/external/postgresql/base.py
@@ -257,6 +257,19 @@ def build_reports_sql_where(params, sql_params, config):
257 257
             sql_params = add_param_to_dict(sql_params, "reason",
258 258
                                            params["reasons"])
259 259
 
  260
+        ## Adding release channels to where clause
  261
+        if params["release_channels"]:
  262
+            channels_list = [
  263
+                "r.release_channel=%%(release_channel%s)s" % x
  264
+                for x in range(len(params["release_channels"]))
  265
+            ]
  266
+            sql_where.append("(%s)" % " OR ".join(channels_list))
  267
+            sql_params = add_param_to_dict(
  268
+                sql_params,
  269
+                "release_channel",
  270
+                params["release_channels"]
  271
+            )
  272
+
260 273
         ## Adding report type to where clause
261 274
         if params["report_type"] == "crash":
262 275
             sql_where.append("r.hangid IS NULL")
3  socorro/lib/search_common.py
@@ -54,6 +54,8 @@ def get_parameters(kwargs):
54 54
         Default is all.
55 55
     reasons -- Restrict search to crashes caused by this reason.
56 56
         Default is all.
  57
+    release_channels -- Restrict search to crashes in this release channels.
  58
+        Default is all.
57 59
     report_type -- Retrict to a type of report.
58 60
         Can be any, crash or hang.
59 61
         Default is any.
@@ -91,6 +93,7 @@ def get_parameters(kwargs):
91 93
         ("versions", None, ["list", "str"]),
92 94
         ("os", None, ["list", "str"]),
93 95
         ("reasons", None, ["list", "str"]),
  96
+        ("release_channels", None, ["list", "str"]),
94 97
         ("build_ids", None, ["list", "str"]),
95 98
         ("build_from", lastweek, "datetime"),
96 99
         ("build_to", now, "datetime"),
22  socorro/unittest/external/postgresql/test_search.py
@@ -140,7 +140,7 @@ def setUp(self):
140 140
                 'Linux',
141 141
                 null,
142 142
                 'plugin',
143  
-                'Release'
  143
+                'Nightly'
144 144
             ),
145 145
             (
146 146
                 8,
@@ -168,7 +168,7 @@ def setUp(self):
168 168
                 'Linux',
169 169
                 null,
170 170
                 'browser',
171  
-                'Release'
  171
+                'Nightly'
172 172
             ),
173 173
             (
174 174
                 10,
@@ -401,3 +401,21 @@ def test_get(self):
401 401
         res = search.get(**params)
402 402
         self.assertEqual(res['total'], 2)
403 403
         self.assertEqual(res, res_expected)
  404
+
  405
+        # Test 9: release channels
  406
+        params = {
  407
+            'release_channels': ['Nightly']
  408
+        }
  409
+        res = search.get(**params)
  410
+        self.assertEqual(res['total'], 2)
  411
+
  412
+        hits = res['hits'][0]
  413
+        self.assertEqual(hits['signature'], 'js::functions::call::hello_world')
  414
+        hits = res['hits'][1]
  415
+        self.assertEqual(hits['signature'], 'sig2')
  416
+
  417
+        params = {
  418
+            'release_channels': ['Nightly', 'Release']
  419
+        }
  420
+        res = search.get(**params)
  421
+        self.assertEqual(res['total'], 5)
1  socorro/unittest/lib/test_search_common.py
@@ -40,6 +40,7 @@ def test_get_parameters(self):
40 40
             "to_date": "",
41 41
             "versions": "",
42 42
             "reasons": "",
  43
+            "release_channels": "",
43 44
             "os": "",
44 45
             "search_mode": "",
45 46
             "build_ids": "",

0 notes on commit b5f3f0b

Please sign in to comment.
Something went wrong with that request. Please try again.