예제 #1
0
    def test_many_days(self, celery, geoip_data, redis, metricsmock):
        bhutan_ip = geoip_data["Bhutan"]["ip"]
        london_ip = geoip_data["London"]["ip"]
        days_6 = (self.today - timedelta(days=6)).strftime("%Y-%m-%d")
        days_7 = (self.today - timedelta(days=7)).strftime("%Y-%m-%d")
        redis.pfadd("apiuser:submit:test:" + self.today_str, "127.0.0.1",
                    bhutan_ip)
        # add the same IPs + one new one again
        redis.pfadd("apiuser:submit:test:" + days_6, "127.0.0.1", bhutan_ip,
                    london_ip)
        # add one entry which is too old
        redis.pfadd("apiuser:submit:test:" + days_7, bhutan_ip)

        monitor_api_users.delay().get()
        assert (len(
            metricsmock.filter_records("gauge",
                                       "submit.user",
                                       value=2,
                                       tags=["key:test", "interval:1d"])) == 1)
        # We count unique IPs over the entire 7 day period, so it's just 3 uniques.
        assert (len(
            metricsmock.filter_records("gauge",
                                       "submit.user",
                                       value=3,
                                       tags=["key:test", "interval:7d"])) == 1)

        # the too old key was deleted manually
        assert not redis.exists("apiuser:submit:test:" + days_7)
예제 #2
0
    def test_one_day(self, celery, geoip_data, redis, metricsmock):
        bhutan_ip = geoip_data["Bhutan"]["ip"]
        london_ip = geoip_data["London"]["ip"]
        redis.pfadd("apiuser:submit:test:" + self.today_str, bhutan_ip,
                    london_ip)
        redis.pfadd("apiuser:submit:valid_key:" + self.today_str, bhutan_ip)
        redis.pfadd("apiuser:locate:valid_key:" + self.today_str, bhutan_ip)

        monitor_api_users.delay().get()
        metricsmock.assert_gauge_once("submit.user",
                                      value=2,
                                      tags=["key:test", "interval:1d"])
        metricsmock.assert_gauge_once("submit.user",
                                      value=2,
                                      tags=["key:test", "interval:7d"])
        metricsmock.assert_gauge_once("submit.user",
                                      value=1,
                                      tags=["key:valid_key", "interval:1d"])
        metricsmock.assert_gauge_once("submit.user",
                                      value=1,
                                      tags=["key:valid_key", "interval:7d"])
        metricsmock.assert_gauge_once("locate.user",
                                      value=1,
                                      tags=["key:valid_key", "interval:1d"])
        metricsmock.assert_gauge_once("locate.user",
                                      value=1,
                                      tags=["key:valid_key", "interval:7d"])
예제 #3
0
    def test_many_days(self):
        days_6 = (self.today - timedelta(days=6)).strftime('%Y-%m-%d')
        days_7 = (self.today - timedelta(days=7)).strftime('%Y-%m-%d')
        self.redis_client.pfadd(
            'apiuser:submit:test:' + self.today_str,
            '127.0.0.1', self.bhutan_ip)
        # add the same IPs + one new one again
        self.redis_client.pfadd(
            'apiuser:submit:test:' + days_6,
            '127.0.0.1', self.bhutan_ip, self.london_ip)
        # add one entry which is too old
        self.redis_client.pfadd(
            'apiuser:submit:test:' + days_7, self.bhutan_ip)

        monitor_api_users.delay().get()
        self.check_stats(gauge=[
            ('submit.user', 1, 2, ['key:test', 'interval:1d']),
            # we count unique IPs over the entire 7 day period,
            # so it's just 3 uniques
            ('submit.user', 1, 3, ['key:test', 'interval:7d']),
        ])

        # the too old key was deleted manually
        self.assertFalse(
            self.redis_client.exists('apiuser:submit:test:' + days_7))
예제 #4
0
    def test_many_days(self):
        days_6 = (self.today - timedelta(days=6)).strftime('%Y-%m-%d')
        days_7 = (self.today - timedelta(days=7)).strftime('%Y-%m-%d')
        self.redis_client.pfadd(
            'apiuser:submit:test:' + self.today_str,
            '127.0.0.1', self.bhutan_ip)
        # add the same IPs + one new one again
        self.redis_client.pfadd(
            'apiuser:submit:test:' + days_6,
            '127.0.0.1', self.bhutan_ip, self.london_ip)
        # add one entry which is too old
        self.redis_client.pfadd(
            'apiuser:submit:test:' + days_7, self.bhutan_ip)

        monitor_api_users.delay().get()
        self.check_stats(gauge=[
            ('submit.user', 1, 2, ['key:test', 'interval:1d']),
            # we count unique IPs over the entire 7 day period,
            # so it's just 3 uniques
            ('submit.user', 1, 3, ['key:test', 'interval:7d']),
        ])

        # the too old key was deleted manually
        self.assertFalse(
            self.redis_client.exists('apiuser:submit:test:' + days_7))
예제 #5
0
    def test_one_day(self):
        self.redis_client.pfadd(
            'apiuser:submit:test:' + self.today_str,
            self.bhutan_ip, self.london_ip)
        self.redis_client.pfadd(
            'apiuser:submit:valid_key:' + self.today_str,
            self.bhutan_ip)
        self.redis_client.pfadd(
            'apiuser:locate:valid_key:' + self.today_str,
            self.bhutan_ip)

        result = monitor_api_users.delay().get()
        self.assertEqual(result, {
            'submit:test:1d': 2,
            'submit:test:7d': 2,
            'submit:valid_key:1d': 1,
            'submit:valid_key:7d': 1,
            'locate:valid_key:1d': 1,
            'locate:valid_key:7d': 1,
        })

        self.check_stats(gauge=[
            ('submit.user', 1, 2, ['key:test', 'interval:1d']),
            ('submit.user', 1, 2, ['key:test', 'interval:7d']),
            ('submit.user', 1, 1, ['key:valid_key', 'interval:1d']),
            ('submit.user', 1, 1, ['key:valid_key', 'interval:7d']),
            ('locate.user', 1, 1, ['key:valid_key', 'interval:1d']),
            ('locate.user', 1, 1, ['key:valid_key', 'interval:7d']),
        ])
예제 #6
0
    def test_one_day(self):
        self.redis_client.pfadd('apiuser:submit:test:' + self.today_str,
                                self.bhutan_ip, self.london_ip)
        self.redis_client.pfadd('apiuser:submit:valid_key:' + self.today_str,
                                self.bhutan_ip)
        self.redis_client.pfadd('apiuser:locate:valid_key:' + self.today_str,
                                self.bhutan_ip)

        result = monitor_api_users.delay().get()
        self.assertEqual(
            result, {
                'submit:test:1d': 2,
                'submit:test:7d': 2,
                'submit:valid_key:1d': 1,
                'submit:valid_key:7d': 1,
                'locate:valid_key:1d': 1,
                'locate:valid_key:7d': 1,
            })

        self.check_stats(gauge=[
            ('submit.user', 1, 2, ['key:test', 'interval:1d']),
            ('submit.user', 1, 2, ['key:test', 'interval:7d']),
            ('submit.user', 1, 1, ['key:valid_key', 'interval:1d']),
            ('submit.user', 1, 1, ['key:valid_key', 'interval:7d']),
            ('locate.user', 1, 1, ['key:valid_key', 'interval:1d']),
            ('locate.user', 1, 1, ['key:valid_key', 'interval:7d']),
        ])
예제 #7
0
    def test_one_day(self, celery, geoip_data, redis, stats):
        bhutan_ip = geoip_data['Bhutan']['ip']
        london_ip = geoip_data['London']['ip']
        redis.pfadd(
            'apiuser:submit:test:' + self.today_str, bhutan_ip, london_ip)
        redis.pfadd(
            'apiuser:submit:valid_key:' + self.today_str, bhutan_ip)
        redis.pfadd(
            'apiuser:locate:valid_key:' + self.today_str, bhutan_ip)

        monitor_api_users.delay().get()
        stats.check(gauge=[
            ('submit.user', 1, 2, ['key:test', 'interval:1d']),
            ('submit.user', 1, 2, ['key:test', 'interval:7d']),
            ('submit.user', 1, 1, ['key:valid_key', 'interval:1d']),
            ('submit.user', 1, 1, ['key:valid_key', 'interval:7d']),
            ('locate.user', 1, 1, ['key:valid_key', 'interval:1d']),
            ('locate.user', 1, 1, ['key:valid_key', 'interval:7d']),
        ])
예제 #8
0
    def test_one_day(self, celery, geoip_data, redis, stats):
        bhutan_ip = geoip_data['Bhutan']['ip']
        london_ip = geoip_data['London']['ip']
        redis.pfadd(
            'apiuser:submit:test:' + self.today_str, bhutan_ip, london_ip)
        redis.pfadd(
            'apiuser:submit:valid_key:' + self.today_str, bhutan_ip)
        redis.pfadd(
            'apiuser:locate:valid_key:' + self.today_str, bhutan_ip)

        monitor_api_users.delay().get()
        stats.check(gauge=[
            ('submit.user', 1, 2, ['key:test', 'interval:1d']),
            ('submit.user', 1, 2, ['key:test', 'interval:7d']),
            ('submit.user', 1, 1, ['key:valid_key', 'interval:1d']),
            ('submit.user', 1, 1, ['key:valid_key', 'interval:7d']),
            ('locate.user', 1, 1, ['key:valid_key', 'interval:1d']),
            ('locate.user', 1, 1, ['key:valid_key', 'interval:7d']),
        ])
예제 #9
0
    def test_many_days(self, celery, geoip_data, redis, stats):
        bhutan_ip = geoip_data['Bhutan']['ip']
        london_ip = geoip_data['London']['ip']
        days_6 = (self.today - timedelta(days=6)).strftime('%Y-%m-%d')
        days_7 = (self.today - timedelta(days=7)).strftime('%Y-%m-%d')
        redis.pfadd(
            'apiuser:submit:test:' + self.today_str, '127.0.0.1', bhutan_ip)
        # add the same IPs + one new one again
        redis.pfadd(
            'apiuser:submit:test:' + days_6, '127.0.0.1', bhutan_ip, london_ip)
        # add one entry which is too old
        redis.pfadd(
            'apiuser:submit:test:' + days_7, bhutan_ip)

        monitor_api_users.delay().get()
        stats.check(gauge=[
            ('submit.user', 1, 2, ['key:test', 'interval:1d']),
            # we count unique IPs over the entire 7 day period,
            # so it's just 3 uniques
            ('submit.user', 1, 3, ['key:test', 'interval:7d']),
        ])

        # the too old key was deleted manually
        assert not redis.exists('apiuser:submit:test:' + days_7)
예제 #10
0
    def test_many_days(self, celery, geoip_data, redis, stats):
        bhutan_ip = geoip_data['Bhutan']['ip']
        london_ip = geoip_data['London']['ip']
        days_6 = (self.today - timedelta(days=6)).strftime('%Y-%m-%d')
        days_7 = (self.today - timedelta(days=7)).strftime('%Y-%m-%d')
        redis.pfadd(
            'apiuser:submit:test:' + self.today_str, '127.0.0.1', bhutan_ip)
        # add the same IPs + one new one again
        redis.pfadd(
            'apiuser:submit:test:' + days_6, '127.0.0.1', bhutan_ip, london_ip)
        # add one entry which is too old
        redis.pfadd(
            'apiuser:submit:test:' + days_7, bhutan_ip)

        monitor_api_users.delay().get()
        stats.check(gauge=[
            ('submit.user', 1, 2, ['key:test', 'interval:1d']),
            # we count unique IPs over the entire 7 day period,
            # so it's just 3 uniques
            ('submit.user', 1, 3, ['key:test', 'interval:7d']),
        ])

        # the too old key was deleted manually
        assert not redis.exists('apiuser:submit:test:' + days_7)
예제 #11
0
 def test_empty(self, celery, metricsmock):
     monitor_api_users.delay().get()
     metricsmock.assert_not_gauge("submit.user")
     metricsmock.assert_not_gauge("locate.user")
예제 #12
0
 def test_empty(self, celery, stats):
     monitor_api_users.delay().get()
     stats.check(gauge=[('submit.user', 0), ('locate.user', 0)])
예제 #13
0
 def test_empty(self):
     monitor_api_users.delay().get()
     self.check_stats(gauge=[('submit.user', 0), ('locate.user', 0)])
예제 #14
0
 def test_empty(self):
     monitor_api_users.delay().get()
     self.check_stats(gauge=[('submit.user', 0), ('locate.user', 0)])
예제 #15
0
 def test_empty(self, celery, stats):
     monitor_api_users.delay().get()
     stats.check(gauge=[('submit.user', 0), ('locate.user', 0)])
예제 #16
0
 def test_empty(self):
     result = monitor_api_users.delay().get()
     self.assertEqual(result, {})
예제 #17
0
 def test_empty(self):
     result = monitor_api_users.delay().get()
     self.assertEqual(result, {})
예제 #18
0
 def test_empty(self, celery, metricsmock):
     monitor_api_users.delay().get()
     assert not metricsmock.has_record("gauge", "submit.user")
     assert not metricsmock.has_record("gauge", "locate.user")