def test_monitor_api_keys_multiple(self, celery, redis, metricsmock): now = util.utcnow() today = now.strftime("%Y%m%d") yesterday = (now - timedelta(hours=24)).strftime("%Y%m%d") data = { "test": {"v1.search": 11, "v1.geolocate": 13}, "no_key_1": {"v1.search": 12}, "no_key_2": {"v1.geolocate": 15}, } for key, paths in data.items(): for path, value in paths.items(): rate_key = "apilimit:%s:%s:%s" % (key, path, today) redis.incr(rate_key, value) rate_key = "apilimit:%s:%s:%s" % (key, path, yesterday) redis.incr(rate_key, value - 10) # add some other items into Redis redis.lpush("default", 1, 2) redis.set("cache_something", "{}") monitor_api_key_limits.delay().get() metricsmock.assert_gauge_once( "api.limit", value=13, tags=["key:test", "path:v1.geolocate"] ) metricsmock.assert_gauge_once( "api.limit", value=11, tags=["key:test", "path:v1.search"] ) metricsmock.assert_gauge_once( "api.limit", value=12, tags=["key:no_key_1", "path:v1.search"] ) metricsmock.assert_gauge_once( "api.limit", value=15, tags=["key:no_key_2", "path:v1.geolocate"] )
def test_monitor_api_keys_multiple(self): now = util.utcnow() today = now.strftime('%Y%m%d') yesterday = (now - timedelta(hours=24)).strftime('%Y%m%d') data = { 'test': {'v1.search': 11, 'v1.geolocate': 13}, 'no_key_1': {'v1.search': 12}, 'no_key_2': {'v1.geolocate': 15}, } for key, paths in data.items(): for path, value in paths.items(): rate_key = 'apilimit:%s:%s:%s' % (key, path, today) self.redis_client.incr(rate_key, value) rate_key = 'apilimit:%s:%s:%s' % (key, path, yesterday) self.redis_client.incr(rate_key, value - 10) # add some other items into Redis self.redis_client.lpush('default', 1, 2) self.redis_client.set('cache_something', '{}') monitor_api_key_limits.delay().get() self.check_stats(gauge=[ ('api.limit', ['key:test', 'path:v1.geolocate']), ('api.limit', ['key:test', 'path:v1.search']), ('api.limit', ['key:no_key_1', 'path:v1.search']), ('api.limit', ['key:no_key_2', 'path:v1.geolocate']), ])
def test_monitor_api_keys_multiple(self, celery, redis, stats): now = util.utcnow() today = now.strftime('%Y%m%d') yesterday = (now - timedelta(hours=24)).strftime('%Y%m%d') data = { 'test': {'v1.search': 11, 'v1.geolocate': 13}, 'no_key_1': {'v1.search': 12}, 'no_key_2': {'v1.geolocate': 15}, } for key, paths in data.items(): for path, value in paths.items(): rate_key = 'apilimit:%s:%s:%s' % (key, path, today) redis.incr(rate_key, value) rate_key = 'apilimit:%s:%s:%s' % (key, path, yesterday) redis.incr(rate_key, value - 10) # add some other items into Redis redis.lpush('default', 1, 2) redis.set('cache_something', '{}') monitor_api_key_limits.delay().get() stats.check(gauge=[ ('api.limit', ['key:test', 'path:v1.geolocate']), ('api.limit', ['key:test', 'path:v1.search']), ('api.limit', ['key:no_key_1', 'path:v1.search']), ('api.limit', ['key:no_key_2', 'path:v1.geolocate']), ])
def test_monitor_api_keys_one(self, celery, redis, metricsmock): today = util.utcnow().strftime("%Y%m%d") rate_key = "apilimit:no_key_1:v1.geolocate:" + today redis.incr(rate_key, 13) monitor_api_key_limits.delay().get() metricsmock.assert_gauge_once( "api.limit", value=13, tags=["key:no_key_1", "path:v1.geolocate"])
def test_monitor_api_keys_one(self): today = util.utcnow().strftime('%Y%m%d') rate_key = 'apilimit:no_key_1:v1.geolocate:' + today self.redis_client.incr(rate_key, 13) monitor_api_key_limits.delay().get() self.check_stats(gauge=[ ('api.limit', ['key:no_key_1', 'path:v1.geolocate']), ])
def test_monitor_api_keys_one(self, celery, redis, stats): today = util.utcnow().strftime('%Y%m%d') rate_key = 'apilimit:no_key_1:v1.geolocate:' + today redis.incr(rate_key, 13) monitor_api_key_limits.delay().get() stats.check(gauge=[ ('api.limit', ['key:no_key_1', 'path:v1.geolocate']), ])
def test_monitor_api_keys_one(self, celery, redis, stats): today = util.utcnow().strftime('%Y%m%d') rate_key = 'apilimit:no_key_1:v1.geolocate:' + today redis.incr(rate_key, 13) monitor_api_key_limits.delay().get() stats.check(gauge=[ ('api.limit', ['key:no_key_1', 'path:v1.geolocate']), ])
def test_monitor_api_keys_one(self): today = util.utcnow().strftime('%Y%m%d') rate_key = 'apilimit:no_key_1:v1.geolocate:' + today self.redis_client.incr(rate_key, 13) monitor_api_key_limits.delay().get() self.check_stats(gauge=[ ('api.limit', ['key:no_key_1', 'path:v1.geolocate']), ])
def test_monitor_api_keys_multiple(self): redis_client = self.redis_client now = util.utcnow() today = now.strftime('%Y%m%d') yesterday = (now - timedelta(hours=24)).strftime('%Y%m%d') data = { 'test': { 'v1.search': 11, 'v1.geolocate': 13 }, 'no_key_1': { 'v1.search': 12 }, 'no_key_2': { 'v1.geolocate': 15 }, } for key, paths in data.items(): for path, value in paths.items(): rate_key = 'apilimit:%s:%s:%s' % (key, path, today) redis_client.incr(rate_key, value) rate_key = 'apilimit:%s:%s:%s' % (key, path, yesterday) redis_client.incr(rate_key, value - 10) api_keys = [ ApiKey(valid_key='no_key_1', shortname='shortname_1'), ApiKey(valid_key='no_key_2'), ApiKey(valid_key='no_key_3', shortname='shortname_3'), ] self.session.add_all(api_keys) self.session.flush() # add some other items into Redis redis_client.lpush('default', 1, 2) redis_client.set('cache_something', '{}') result = monitor_api_key_limits.delay().get() self.check_stats(gauge=[ ('api.limit', ['key:test', 'path:v1.geolocate']), ('api.limit', ['key:test', 'path:v1.search']), ('api.limit', ['key:shortname_1', 'path:v1.search']), ('api.limit', ['key:no_key_2', 'path:v1.geolocate']), ]) self.assertDictEqual( result, { 'test': { 'v1.search': 11, 'v1.geolocate': 13 }, 'shortname_1': { 'v1.search': 12 }, 'no_key_2': { 'v1.geolocate': 15 }, })
def test_monitor_api_keys_one(self): redis_client = self.redis_client now = util.utcnow() today = now.strftime('%Y%m%d') rate_key = 'apilimit:no_key_1:v1.geolocate:' + today redis_client.incr(rate_key, 13) result = monitor_api_key_limits.delay().get() self.assertEqual(result, {'no_key_1': {'v1.geolocate': 13}}) self.check_stats(gauge=[ ('api.limit', ['key:no_key_1', 'path:v1.geolocate']), ])
def test_monitor_api_keys_one(self): redis_client = self.redis_client now = util.utcnow() today = now.strftime('%Y%m%d') rate_key = 'apilimit:no_key_1:v1.geolocate:' + today redis_client.incr(rate_key, 13) result = monitor_api_key_limits.delay().get() self.assertEqual(result, {'no_key_1': {'v1.geolocate': 13}}) self.check_stats(gauge=[ ('api.limit', ['key:no_key_1', 'path:v1.geolocate']), ])
def test_monitor_api_keys_multiple(self): redis_client = self.redis_client now = util.utcnow() today = now.strftime('%Y%m%d') yesterday = (now - timedelta(hours=24)).strftime('%Y%m%d') data = { 'test': {'v1.search': 11, 'v1.geolocate': 13}, 'no_key_1': {'v1.search': 12}, 'no_key_2': {'v1.geolocate': 15}, } for key, paths in data.items(): for path, value in paths.items(): rate_key = 'apilimit:%s:%s:%s' % (key, path, today) redis_client.incr(rate_key, value) rate_key = 'apilimit:%s:%s:%s' % (key, path, yesterday) redis_client.incr(rate_key, value - 10) api_keys = [ ApiKey(valid_key='no_key_1', shortname='shortname_1'), ApiKey(valid_key='no_key_2'), ApiKey(valid_key='no_key_3', shortname='shortname_3'), ] self.session.add_all(api_keys) self.session.flush() # add some other items into Redis redis_client.lpush('default', 1, 2) redis_client.set('cache_something', '{}') result = monitor_api_key_limits.delay().get() self.check_stats(gauge=[ ('api.limit', ['key:test', 'path:v1.geolocate']), ('api.limit', ['key:test', 'path:v1.search']), ('api.limit', ['key:shortname_1', 'path:v1.search']), ('api.limit', ['key:no_key_2', 'path:v1.geolocate']), ]) self.assertDictEqual(result, { 'test': {'v1.search': 11, 'v1.geolocate': 13}, 'shortname_1': {'v1.search': 12}, 'no_key_2': {'v1.geolocate': 15}, })
def test_monitor_api_keys_empty(self, celery, stats): monitor_api_key_limits.delay().get() stats.check(gauge=[('api.limit', 0)])
def test_monitor_api_keys_empty(self, celery, metricsmock): monitor_api_key_limits.delay().get() assert not metricsmock.has_record("gauge", "api.limit")
def test_monitor_api_keys_empty(self): monitor_api_key_limits.delay().get() self.check_stats(gauge=[('api.limit', 0)])
def test_monitor_api_keys_empty(self, celery, metricsmock): monitor_api_key_limits.delay().get() metricsmock.assert_not_gauge("api.limit")
def test_monitor_api_keys_empty(self): result = monitor_api_key_limits.delay().get() self.assertEqual(result, {})
def test_monitor_api_keys_empty(self): result = monitor_api_key_limits.delay().get() self.assertEqual(result, {})
def test_monitor_api_keys_empty(self, celery, stats): monitor_api_key_limits.delay().get() stats.check(gauge=[('api.limit', 0)])
def test_monitor_api_keys_empty(self): monitor_api_key_limits.delay().get() self.check_stats(gauge=[('api.limit', 0)])