def test_high_n_buckets(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS": {
                "record_in_processes": ["main", "content"],
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "exponential",
                "low": 1024,
                "high": 16777216,
                "n_buckets": 200,
                "products": ["firefox"],
                "description": "Test histogram",
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        parse_histograms.Histogram(
            "TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS",
            histograms["TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS"],
            strict_type_checks=True,
        )

        self.assertRaises(SystemExit, ParserError.exit_func)

        # Set global allowlists for parse_histograms.
        parse_histograms.allowlists = {
            "alert_emails": [],
            "bug_numbers": [],
            "n_buckets": ["TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS"],
            "expiry_default": [],
            "kind": [],
        }

        hist = parse_histograms.Histogram(
            "TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS",
            histograms["TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS"],
            strict_type_checks=True,
        )

        ParserError.exit_func()
        self.assertEqual(hist.expiration(), "never")
        self.assertEqual(hist.kind(), "exponential")
        self.assertEqual(hist.record_in_processes(), ["main", "content"])
        self.assertEqual(hist.keyed(), False)
        self.assertEqual(hist.low(), 1024)
        self.assertEqual(hist.high(), 16777216)
        self.assertEqual(hist.n_buckets(), 200)

        parse_histograms.allowlists = None
    def test_gv_streaming_keyed(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_GV_STREAMING": {
                "record_in_processes": ["main", "content"],
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "exponential",
                "low": 1024,
                "high": 2**64,
                "n_buckets": 100,
                "keyed": "true",
                "description": "Test histogram",
                "products": ["geckoview_streaming"],
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()
        parse_histograms.Histogram(
            "TEST_HISTOGRAM_GV_STREAMING",
            histograms["TEST_HISTOGRAM_GV_STREAMING"],
            strict_type_checks=True,
        )

        self.assertRaises(SystemExit, ParserError.exit_func)
    def test_enumerated_histogram_with_100_buckets(self):
        SAMPLE_HISTOGRAM = {
            "TEST_100_BUCKETS_HISTOGRAM": {
                "record_in_processes": ["main", "content", "socket"],
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "enumerated",
                "n_values": 100,
                "products": ["firefox"],
                "description": "Test histogram"
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        hist = parse_histograms.Histogram(
            'TEST_100_BUCKETS_HISTOGRAM',
            histograms['TEST_100_BUCKETS_HISTOGRAM'],
            strict_type_checks=True)

        ParserError.exit_func()
        self.assertTrue(hist.expiration(), "never")
        self.assertTrue(hist.kind(), "enumerated")
        self.assertTrue(hist.n_buckets(), 101)
        self.assertTrue(hist.record_in_processes, ["main", "content"])
        self.assertTrue(hist.record_into_store, ["main"])
    def test_multistore(self):
        SAMPLE_HISTOGRAM = {
            "TEST_VALID_HISTOGRAM": {
                "record_in_processes": ["main", "content"],
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "boolean",
                "description": "Test histogram",
                "products": ["firefox"],
                "record_into_store": ["main", "sync"],
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        hist = parse_histograms.Histogram(
            "TEST_VALID_HISTOGRAM",
            histograms["TEST_VALID_HISTOGRAM"],
            strict_type_checks=True,
        )

        ParserError.exit_func()
        self.assertTrue(hist.expiration(), "never")
        self.assertTrue(hist.kind(), "boolean")
        self.assertTrue(hist.record_into_store, ["main", "sync"])
    def test_high_value(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS": {
                "record_in_processes": ["main", "content"],
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "exponential",
                "low": 1024,
                "high": 2**64,
                "n_buckets": 100,
                "products": ["firefox"],
                "description": "Test histogram",
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        parse_histograms.Histogram(
            "TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS",
            histograms["TEST_HISTOGRAM_ALLOWLIST_N_BUCKETS"],
            strict_type_checks=True,
        )

        self.assertRaises(SystemExit, ParserError.exit_func)
    def test_expiry_default(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_ALLOWLIST_EXPIRY_DEFAULT": {
                "record_in_processes": ["main", "content"],
                "expires_in_version": "default",
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "kind": "boolean",
                "products": ["firefox"],
                "description": "Test histogram",
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        parse_histograms.Histogram(
            "TEST_HISTOGRAM_ALLOWLIST_EXPIRY_DEFAULT",
            histograms["TEST_HISTOGRAM_ALLOWLIST_EXPIRY_DEFAULT"],
            strict_type_checks=True,
        )

        self.assertRaises(SystemExit, ParserError.exit_func)

        # Set global allowlists for parse_histograms.
        parse_histograms.allowlists = {
            "alert_emails": [],
            "bug_numbers": [],
            "n_buckets": [],
            "expiry_default": ["TEST_HISTOGRAM_ALLOWLIST_EXPIRY_DEFAULT"],
            "kind": [],
        }

        hist = parse_histograms.Histogram(
            "TEST_HISTOGRAM_ALLOWLIST_EXPIRY_DEFAULT",
            histograms["TEST_HISTOGRAM_ALLOWLIST_EXPIRY_DEFAULT"],
            strict_type_checks=True,
        )

        ParserError.exit_func()
        self.assertEqual(hist.expiration(), "default")
        self.assertEqual(hist.kind(), "boolean")
        self.assertEqual(hist.record_in_processes(), ["main", "content"])
        self.assertEqual(hist.keyed(), False)

        parse_histograms.allowlists = None
    def test_missing_alert_emails(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_ALLOWLIST_ALERT_EMAILS": {
                "record_in_processes": ["main", "content"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "boolean",
                "products": ["firefox"],
                "description": "Test histogram",
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        parse_histograms.Histogram(
            'TEST_HISTOGRAM_ALLOWLIST_ALERT_EMAILS',
            histograms['TEST_HISTOGRAM_ALLOWLIST_ALERT_EMAILS'],
            strict_type_checks=True)

        self.assertRaises(SystemExit, ParserError.exit_func)

        # Set global allowlists for parse_histograms.
        parse_histograms.allowlists = {
            "alert_emails": ["TEST_HISTOGRAM_ALLOWLIST_ALERT_EMAILS"],
            "bug_numbers": [],
            "n_buckets": [],
            "expiry_default": [],
            "kind": []
        }

        hist = parse_histograms.Histogram(
            'TEST_HISTOGRAM_ALLOWLIST_ALERT_EMAILS',
            histograms['TEST_HISTOGRAM_ALLOWLIST_ALERT_EMAILS'],
            strict_type_checks=True)

        ParserError.exit_func()
        self.assertEqual(hist.expiration(), 'never')
        self.assertEqual(hist.kind(), 'boolean')
        self.assertEqual(hist.record_in_processes(), ["main", "content"])
        self.assertEqual(hist.keyed(), False)

        parse_histograms.allowlists = None
Пример #8
0
    def test_missing_bug_numbers(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_WHITELIST_BUG_NUMBERS": {
                "record_in_processes": ["main", "content"],
                "alert_emails": ["*****@*****.**"],
                "expires_in_version": "never",
                "kind": "boolean",
                "description": "Test histogram"
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_whitelist()

        parse_histograms.Histogram('TEST_HISTOGRAM_WHITELIST_BUG_NUMBERS',
                                   histograms['TEST_HISTOGRAM_WHITELIST_BUG_NUMBERS'],
                                   strict_type_checks=True)

        self.assertRaises(SystemExit, ParserError.exit_func)

        # Set global whitelists for parse_histograms.
        parse_histograms.whitelists = {
            "alert_emails": [],
            "bug_numbers": [
                "TEST_HISTOGRAM_WHITELIST_BUG_NUMBERS"
            ],
            "n_buckets": [],
            "expiry_default": [],
            "kind": []
        }

        hist = parse_histograms.Histogram('TEST_HISTOGRAM_WHITELIST_BUG_NUMBERS',
                                          histograms['TEST_HISTOGRAM_WHITELIST_BUG_NUMBERS'],
                                          strict_type_checks=True)

        ParserError.exit_func()
        self.assertEqual(hist.expiration(), 'never')
        self.assertEqual(hist.kind(), 'boolean')
        self.assertEqual(hist.record_in_processes(), ["main", "content"])
        self.assertEqual(hist.keyed(), False)

        parse_histograms.whitelists = None
    def test_no_products(self):
        SAMPLE_HISTOGRAM = {
            "TEST_EMPTY_PRODUCTS": {
                "kind": "flag",
                "description": "sample",
            }
        }

        histograms = load_histogram(SAMPLE_HISTOGRAM)
        hist = parse_histograms.Histogram('TEST_EMPTY_PRODUCTS',
                                          histograms['TEST_EMPTY_PRODUCTS'],
                                          strict_type_checks=False)

        self.assertEqual(hist.kind(), 'flag')
        # bug 1486072: absent `product` key becomes None instead of ["all"]
        self.assertEqual(hist.products(), None)
    def test_unsupported_kind_count(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_ALLOWLIST_KIND": {
                "record_in_processes": ["main", "content"],
                "expires_in_version": "never",
                "kind": "count",
                "releaseChannelCollection": "opt-out",
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "products": ["firefox"],
                "description": "Test histogram",
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        self.assertRaises(
            SystemExit,
            parse_histograms.Histogram,
            "TEST_HISTOGRAM_ALLOWLIST_KIND",
            histograms["TEST_HISTOGRAM_ALLOWLIST_KIND"],
            strict_type_checks=True,
        )

        # Set global allowlists for parse_histograms.
        parse_histograms.allowlists = {
            "alert_emails": [],
            "bug_numbers": [],
            "n_buckets": [],
            "expiry_default": [],
            "kind": ["TEST_HISTOGRAM_ALLOWLIST_KIND"],
        }

        hist = parse_histograms.Histogram(
            "TEST_HISTOGRAM_ALLOWLIST_KIND",
            histograms["TEST_HISTOGRAM_ALLOWLIST_KIND"],
            strict_type_checks=True,
        )

        ParserError.exit_func()
        self.assertEqual(hist.expiration(), "never")
        self.assertEqual(hist.kind(), "count")
        self.assertEqual(hist.record_in_processes(), ["main", "content"])
        self.assertEqual(hist.keyed(), False)

        parse_histograms.allowlists = None
Пример #11
0
    def test_usecounter_collection_enabled(self):
        SAMPLE_HISTOGRAM = {
            "USE_COUNTER2_TEST_HISTOGRAM": {
                "expires_in_version": "never",
                "kind": "boolean",
                "description": "Whether a foo used bar"
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        hist = parse_histograms.Histogram('USE_COUNTER2_TEST_HISTOGRAM',
                                          histograms['USE_COUNTER2_TEST_HISTOGRAM'],
                                          strict_type_checks=True)

        ParserError.exit_func()
        self.assertEquals(hist.dataset(), "nsITelemetry::DATASET_ALL_CHANNELS")
        self.assertEquals(hist.products(), ["firefox", "fennec", "geckoview"])
 def test_gv_streaming_unsupported_kind(self):
     SAMPLE_HISTOGRAM = {
         "TEST_HISTOGRAM_GV_STREAMING": {
             "record_in_processes": ["main", "content"],
             "alert_emails": ["*****@*****.**"],
             "bug_numbers": [1383793],
             "expires_in_version": "never",
             "kind": "boolean",
             "description": "Test histogram",
             "products": ["geckoview_streaming"],
         }
     }
     histograms = load_histogram(SAMPLE_HISTOGRAM)
     parse_histograms.load_allowlist()
     parse_histograms.Histogram('TEST_HISTOGRAM_GV_STREAMING',
                                histograms['TEST_HISTOGRAM_GV_STREAMING'],
                                strict_type_checks=True)
     self.assertRaises(SystemExit, ParserError.exit_func)
    def test_unknown_field(self):
        SAMPLE_HISTOGRAM = {
            "A11Y_INSTANTIATED_FLAG": {
                "record_in_processes": ["main", "content"],
                "expires_in_version": "never",
                "kind": "flag",
                "description": "has accessibility support been instantiated",
                "new_field": "Its a new field"
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)

        hist = parse_histograms.Histogram('A11Y_INSTANTIATED_FLAG',
                                          histograms['A11Y_INSTANTIATED_FLAG'],
                                          strict_type_checks=False)
        self.assertEqual(hist.expiration(), 'never')
        self.assertEqual(hist.kind(), 'flag')
        self.assertEqual(hist.record_in_processes(), ["main", "content"])
    def test_products_all(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_ALL_PRODUCTS": {
                "record_in_processes": ["main", "content"],
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "boolean",
                "description": "Test histogram",
                "products": ["all"],
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        parse_histograms.Histogram('TEST_HISTOGRAM_ALL_PRODUCTS',
                                   histograms['TEST_HISTOGRAM_ALL_PRODUCTS'],
                                   strict_type_checks=True)
        self.assertRaises(SystemExit, ParserError.exit_func)
    def test_non_numeric_expressions(self):
        SAMPLE_HISTOGRAM = {
            "TEST_NON_NUMERIC_HISTOGRAM": {
                "kind": "linear",
                "description": "sample",
                "n_buckets": "JS::GCReason::NUM_TELEMETRY_REASONS",
                "high": "mozilla::StartupTimeline::MAX_EVENT_ID"
            }
        }

        histograms = load_histogram(SAMPLE_HISTOGRAM)
        hist = parse_histograms.Histogram(
            'TEST_NON_NUMERIC_HISTOGRAM',
            histograms['TEST_NON_NUMERIC_HISTOGRAM'],
            strict_type_checks=False)

        # expected values come off parse_histograms.py
        self.assertEqual(hist.n_buckets(), 101)
        self.assertEqual(hist.high(), 12)
Пример #16
0
    def test_multistore_empty(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_EMPTY_MULTISTORE": {
                "record_in_processes": ["main", "content"],
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "boolean",
                "description": "Test histogram",
                "record_into_store": [],
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_whitelist()

        parse_histograms.Histogram('TEST_HISTOGRAM_EMPTY_MULTISTORE',
                                   histograms['TEST_HISTOGRAM_EMPTY_MULTISTORE'],
                                   strict_type_checks=True)
        self.assertRaises(SystemExit, ParserError.exit_func)
Пример #17
0
    def test_usecounter_histogram(self):
        SAMPLE_HISTOGRAM = {
            "USE_COUNTER2_TEST_HISTOGRAM": {
                "expires_in_version": "never",
                "kind": "boolean",
                "description": "Whether a foo used bar"
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_allowlist()

        hist = parse_histograms.Histogram('USE_COUNTER2_TEST_HISTOGRAM',
                                          histograms['USE_COUNTER2_TEST_HISTOGRAM'],
                                          strict_type_checks=True)

        ParserError.exit_func()
        self.assertEquals(hist.expiration(), "never")
        self.assertEquals(hist.kind(), "boolean")
        self.assertEquals(hist.description(), "Whether a foo used bar")
        self.assertEquals(hist.products(), ["firefox", "fennec", "geckoview"])
Пример #18
0
    def test_unsupported_kind_flag(self):
        SAMPLE_HISTOGRAM = {
            "TEST_HISTOGRAM_WHITELIST_KIND": {
                "record_in_processes": ["main", "content"],
                "expires_in_version": "never",
                "kind": "flag",
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "description": "Test histogram",
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_whitelist()

        self.assertRaises(SystemExit, parse_histograms.Histogram,
                          'TEST_HISTOGRAM_WHITELIST_KIND',
                          histograms['TEST_HISTOGRAM_WHITELIST_KIND'],
                          strict_type_checks=True)

        # Set global whitelists for parse_histograms.
        parse_histograms.whitelists = {
            "alert_emails": [],
            "bug_numbers": [],
            "n_buckets": [],
            "expiry_default": [],
            "kind": [
                "TEST_HISTOGRAM_WHITELIST_KIND"
            ]
        }

        hist = parse_histograms.Histogram('TEST_HISTOGRAM_WHITELIST_KIND',
                                          histograms['TEST_HISTOGRAM_WHITELIST_KIND'],
                                          strict_type_checks=True)

        ParserError.exit_func()
        self.assertEqual(hist.expiration(), 'never')
        self.assertEqual(hist.kind(), 'flag')
        self.assertEqual(hist.record_in_processes(), ["main", "content"])
        self.assertEqual(hist.keyed(), False)

        parse_histograms.whitelists = None
Пример #19
0
    def test_valid_histogram(self):
        SAMPLE_HISTOGRAM = {
            "TEST_VALID_HISTOGRAM": {
                "record_in_processes": ["main", "content"],
                "alert_emails": ["*****@*****.**"],
                "bug_numbers": [1383793],
                "expires_in_version": "never",
                "kind": "boolean",
                "description": "Test histogram"
            }
        }
        histograms = load_histogram(SAMPLE_HISTOGRAM)
        parse_histograms.load_whitelist()

        hist = parse_histograms.Histogram('TEST_VALID_HISTOGRAM',
                                          histograms['TEST_VALID_HISTOGRAM'],
                                          strict_type_checks=True)

        ParserError.exit_func()
        self.assertTrue(hist.expiration(), "never")
        self.assertTrue(hist.kind(), "boolean")
        self.assertTrue(hist.record_in_processes, ["main", "content"])
 def test_parse():
     return parse_histograms.Histogram(
         "TEST_EMPTY_PRODUCTS",
         histograms["TEST_EMPTY_PRODUCTS"],
         strict_type_checks=True,
     )
 def test_parse():
     return parse_histograms.Histogram(
         'TEST_EMPTY_PRODUCTS',
         histograms['TEST_EMPTY_PRODUCTS'],
         strict_type_checks=True)