Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug 852466 - Added release channel filter in search report/list se... #1149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/middleware.rst
Expand Up @@ -273,6 +273,8 @@ Optional parameters
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| reasons | String or list of strings | None | Restricts search to crashes caused by this reason. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| release_channels | String or list of strings | None | Restricts search to crashes with these release channels. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| build\_ids | Integer or list of integers | None | Restricts search to crashes that happened on a product with this build ID. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| build\_from | Integer or list of integers | None | Restricts search to crashes with a build id greater than this. |
Expand Down Expand Up @@ -498,6 +500,8 @@ Optional parameters
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| reasons | String or list of strings | None | Restricts search to crashes caused by this reason. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| release_channels | String or list of strings | None | Restricts search to crashes with these release channels. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| build\_ids | Integer or list of integers | None | Restricts search to crashes that happened on a product with this build ID. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| build\_from | Integer or list of integers | None | Restricts search to crashes with a build id greater than this. |
Expand Down Expand Up @@ -1384,6 +1388,8 @@ Optional parameters
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| reasons | String or list of strings | None | Restricts search to crashes caused by this reason. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| release_channels | String or list of strings | None | Restricts search to crashes with these release channels. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| build_ids | Integer or list of integers | None | Restricts search to crashes that happened on a product with this build ID. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| build\_from | Integer or list of integers | None | Restricts search to crashes with a build id greater than this. |
Expand Down Expand Up @@ -1641,6 +1647,8 @@ Optional parameters
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| reasons | String or list of strings | None | Restricts search to crashes caused by this reason. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| release_channels | String or list of strings | None | Restricts search to crashes with these release channels. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| build\_ids | Integer or list of integers | None | Restricts search to crashes that happened on a product with this build ID. |
+------------------------+-------------------------------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| build\_from | Integer or list of integers | None | Restricts search to crashes with a build id greater than this. |
Expand Down
7 changes: 7 additions & 0 deletions socorro/external/elasticsearch/base.py
Expand Up @@ -176,6 +176,13 @@ def build_query_from_params(params, config):
filters["and"].append(
ElasticSearchBase.build_terms_query("reason",
[x.lower() for x in params["reasons"]]))
if params["release_channels"]:
filters["and"].append(
ElasticSearchBase.build_terms_query(
"release_channel",
[x.lower() for x in params["release_channels"]]
)
)

filters["and"].append({
"range": {
Expand Down
10 changes: 10 additions & 0 deletions socorro/external/elasticsearch/search.py
Expand Up @@ -41,6 +41,16 @@ def get(self, **kwargs):
Optional arguments: see SearchCommon.get_parameters()

"""
# change aliases from the web to the implementation's need
if "for" in kwargs and "terms" not in kwargs:
kwargs["terms"] = kwargs.get("for")
if "from" in kwargs and "from_date" not in kwargs:
kwargs["from_date"] = kwargs.get("from")
if "to" in kwargs and "to_date" not in kwargs:
kwargs["to_date"] = kwargs.get("to")
if "in" in kwargs and "fields" not in kwargs:
kwargs["fields"] = kwargs.get("in")

params = search_common.get_parameters(kwargs)

# Get information about the versions
Expand Down
13 changes: 13 additions & 0 deletions socorro/external/postgresql/base.py
Expand Up @@ -257,6 +257,19 @@ def build_reports_sql_where(params, sql_params, config):
sql_params = add_param_to_dict(sql_params, "reason",
params["reasons"])

## Adding release channels to where clause
if params["release_channels"]:
channels_list = [
"r.release_channel=%%(release_channel%s)s" % x
for x in range(len(params["release_channels"]))
]
sql_where.append("(%s)" % " OR ".join(channels_list))
sql_params = add_param_to_dict(
sql_params,
"release_channel",
params["release_channels"]
)

## Adding report type to where clause
if params["report_type"] == "crash":
sql_where.append("r.hangid IS NULL")
Expand Down
3 changes: 3 additions & 0 deletions socorro/lib/search_common.py
Expand Up @@ -54,6 +54,8 @@ def get_parameters(kwargs):
Default is all.
reasons -- Restrict search to crashes caused by this reason.
Default is all.
release_channels -- Restrict search to crashes in this release channels.
Default is all.
report_type -- Retrict to a type of report.
Can be any, crash or hang.
Default is any.
Expand Down Expand Up @@ -91,6 +93,7 @@ def get_parameters(kwargs):
("versions", None, ["list", "str"]),
("os", None, ["list", "str"]),
("reasons", None, ["list", "str"]),
("release_channels", None, ["list", "str"]),
("build_ids", None, ["list", "str"]),
("build_from", lastweek, "datetime"),
("build_to", now, "datetime"),
Expand Down
22 changes: 20 additions & 2 deletions socorro/unittest/external/postgresql/test_search.py
Expand Up @@ -140,7 +140,7 @@ def setUp(self):
'Linux',
null,
'plugin',
'Release'
'Nightly'
),
(
8,
Expand Down Expand Up @@ -168,7 +168,7 @@ def setUp(self):
'Linux',
null,
'browser',
'Release'
'Nightly'
),
(
10,
Expand Down Expand Up @@ -401,3 +401,21 @@ def test_get(self):
res = search.get(**params)
self.assertEqual(res['total'], 2)
self.assertEqual(res, res_expected)

# Test 9: release channels
params = {
'release_channels': ['Nightly']
}
res = search.get(**params)
self.assertEqual(res['total'], 2)

hits = res['hits'][0]
self.assertEqual(hits['signature'], 'js::functions::call::hello_world')
hits = res['hits'][1]
self.assertEqual(hits['signature'], 'sig2')

params = {
'release_channels': ['Nightly', 'Release']
}
res = search.get(**params)
self.assertEqual(res['total'], 5)
1 change: 1 addition & 0 deletions socorro/unittest/lib/test_search_common.py
Expand Up @@ -40,6 +40,7 @@ def test_get_parameters(self):
"to_date": "",
"versions": "",
"reasons": "",
"release_channels": "",
"os": "",
"search_mode": "",
"build_ids": "",
Expand Down