Skip to content

Commit

Permalink
bug 1849352: add throttler rule for Firefox ESR Windows <= 8.1
Browse files Browse the repository at this point in the history
This adds a throttler rule to accept only 25% of Firefox, ESR, Windows
<= 8.1 crash reports.
  • Loading branch information
willkg committed Sep 14, 2023
1 parent f72c884 commit bff8736
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 2 deletions.
48 changes: 48 additions & 0 deletions antenna/throttler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import datetime
import importlib
import json
import logging
import random
import re
Expand Down Expand Up @@ -281,6 +282,40 @@ def match_old_buildid(throttler, data):
return buildid_date < (now - datetime.timedelta(days=730))


WINDOWS_8_1_BUILD_NUMBER = 9600


def match_unsupported_windows(throttler, data):
"""Match Windows versions we don't support."""
telemetry_environment = safe_get(data, "TelemetryEnvironment")
if not telemetry_environment:
return False

try:
telemetry_environment_data = json.loads(telemetry_environment)
except (json.decoder.JSONDecodeError, UnicodeDecodeError):
return False

system_data = telemetry_environment_data.get("system")
if not system_data or not isinstance(system_data, dict):
return False

os_data = system_data.get("os")
if not os_data or not isinstance(os_data, dict):
return False

os_name = os_data.get("name")
if not os_name or os_name != "Windows_NT":
return False

windows_build_number = os_data.get("windowsBuildNumber")
if not windows_build_number or not isinstance(windows_build_number, int):
return False

# At this point, we should have a windowsBuildNumber with a valid value.
return windows_build_number <= WINDOWS_8_1_BUILD_NUMBER


#: This accepts crash reports for all products
ALL_PRODUCTS = []

Expand Down Expand Up @@ -372,6 +407,19 @@ def match_old_buildid(throttler, data):
condition=lambda throttler, x: x == "ShutDownKill",
result=(10, CONTINUE, REJECT),
),
# Accept 25% crash reports from Firefox ESR Windows <= 8.1
Rule(
rule_name="is_firefox_esr_unsupported_windows",
key="*",
condition=(
lambda throttler, data: (
safe_get(data, "ProductName") == "Firefox"
and safe_get(data, "ReleaseChannel") == "esr"
and match_unsupported_windows(throttler, data)
)
),
result=(25, CONTINUE, REJECT),
),
# Accept crash reports in ReleaseChannel=aurora, beta, esr channels
Rule(
rule_name="is_alpha_beta_esr",
Expand Down
83 changes: 81 additions & 2 deletions tests/unittest/test_throttler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import json
import logging

from everett.manager import ConfigManager
Expand All @@ -16,6 +17,7 @@
Throttler,
match_infobar_true,
match_old_buildid,
match_unsupported_windows,
)


Expand Down Expand Up @@ -91,7 +93,7 @@ def test_ruleset(self):
)


class Testmatch_infobar_true:
class Test_match_infobar_true:
@pytest.mark.parametrize(
"version, expected",
[
Expand Down Expand Up @@ -186,7 +188,57 @@ def test_buildid(self, throttler):
assert match_infobar_true(throttler, raw_crash) is False


class Testmatch_old_buildid:
class Test_match_unsupported_windows:
@pytest.mark.parametrize(
"data",
[
{},
{"TelemetryEnvironment": "{}"},
{"TelemetryEnvironment": '{"system":{}}'},
{"TelemetryEnvironment": '{"system":{"os":{}}}'},
{"TelemetryEnvironment": '{"system":{"os":{"name":""}}}'},
{"TelemetryEnvironment": '{"system":{"os":{"name":"Windows_NT"}}}'},
{
"TelemetryEnvironment": '{"system":{"os":{"name":"Windows_NT","windowsBuildNumber":""}}}'
},
{
"TelemetryEnvironment": '{"system":{"os":{"name":"Windows_NT","windowsBuildNumber":null}}}'
},
],
)
def test_missing_data(self, throttler, data):
assert match_unsupported_windows(throttler, data) is False

@pytest.mark.parametrize(
"version, expected",
[
# Windows 7
(7601, True),
# Windows 8
(9200, True),
# Windows 8.1
(9600, True),
# Windows 10
(10240, False),
],
)
def test_windows_versions(self, throttler, version, expected):
data = {
"TelemetryEnvironment": json.dumps(
{
"system": {
"os": {
"name": "Windows_NT",
"windowsBuildNumber": version,
},
},
}
)
}
assert match_unsupported_windows(throttler, data) is expected


class Test_match_old_buildid:
def test_no_buildid(self, throttler):
assert match_old_buildid(throttler, {}) is False

Expand Down Expand Up @@ -373,6 +425,33 @@ def test_is_shutdownkill(self, throttler, randommock):
raw_crash = {"ProductName": "Test", "ipc_channel_error": "ShutDownKill"}
assert throttler.throttle(raw_crash) == (ACCEPT, "accept_everything", 100)

def test_is_firefox_esr_unsupported_windows(self, throttler, randommock):
tel_env = json.dumps(
{
"system": {
"os": {
"name": "Windows_NT",
"windowsBuildNumber": 9600,
},
},
}
)
raw_crash = {
"ProductName": "Firefox",
"ReleaseChannel": "esr",
"TelemetryEnvironment": tel_env,
}
with randommock(0.30):
assert throttler.throttle(raw_crash) == (
REJECT,
"is_firefox_esr_unsupported_windows",
25,
)

# If it returns CONTINUE, then it will trigger another rule
with randommock(0.20):
assert throttler.throttle(raw_crash) == (ACCEPT, "is_alpha_beta_esr", 100)

@pytest.mark.parametrize("channel", ["aurora", "beta", "esr"])
def test_is_alpha_beta_esr(self, throttler, channel):
raw_crash = {"ProductName": "Test", "ReleaseChannel": channel}
Expand Down

0 comments on commit bff8736

Please sign in to comment.