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_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_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_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_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
    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_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)
Esempio n. 9
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_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)
    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_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
Esempio n. 13
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"])
    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_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
    def test_products_absent(self):
        SAMPLE_HISTOGRAM = {
            "TEST_NO_PRODUCTS": {
                "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_allowlist()

        def test_parse():
            return parse_histograms.Histogram(
                "TEST_NO_PRODUCTS",
                histograms["TEST_NO_PRODUCTS"],
                strict_type_checks=True,
            )

        self.assertRaises(SystemExit, test_parse)
    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"])