def test_service_handlers(self): """ Test if we can calculate metrics """ self.client.login(username=self.user, password=self.passwd) for idx, _l in enumerate(Layer.objects.all()): for inum in range(0, idx + 1): self.client.get(reverse('layer_detail', args=(_l.alternate, )), **{"HTTP_USER_AGENT": self.ua}) requests = RequestEvent.objects.all() c = CollectorAPI() q = requests.order_by('created') c.process_requests(self.service, requests, q.last().created, q.first().created) interval = self.service.check_interval now = datetime.utcnow().replace(tzinfo=pytz.utc) valid_from = now - (2 * interval) valid_to = now self.assertTrue(isinstance(valid_from, datetime)) self.assertTrue(isinstance(valid_to, datetime)) self.assertTrue(isinstance(interval, timedelta))
def test_metric_data_endpoints(self): """ Test GeoNode collect metrics """ # Login (optional) self.client.force_login(self.u) self.assertTrue(get_user(self.client).is_authenticated()) _l = Layer.objects.all().first() # Event self.client.get(reverse('layer_detail', args=(_l.alternate, )), **{"HTTP_USER_AGENT": self.ua}) requests = RequestEvent.objects.all() self.assertTrue(requests.count() > 0) # First check for MetricValue table self.assertTrue(MetricValue.objects.all().count() == 0) # Metric data collection collector = CollectorAPI() q = requests.order_by('created') collector.process_requests(self.service, requests, q.first().created, q.last().created) # Second check for MetricValue table self.assertTrue(MetricValue.objects.all().count() >= 0) # Call endpoint url = "%s?%s" % ( reverse('monitoring:api_metric_data', args={'request.users'}), 'last=86400&interval=86400&event_type=view&resource_type=layer') response = self.client.get(url) # noqa
def test_service_handlers(self): """ Test if we can calculate metrics """ self.client.login(username=self.user, password=self.passwd) for idx, _l in enumerate(Layer.objects.all()): for inum in range(0, idx + 1): self.client.get( reverse('layer_detail', args=(_l.alternate, )), **{"HTTP_USER_AGENT": self.ua}) requests = RequestEvent.objects.all() c = CollectorAPI() q = requests.order_by('created') c.process_requests( self.service, requests, q.last().created, q.first().created) interval = self.service.check_interval now = datetime.utcnow().replace(tzinfo=pytz.utc) valid_from = now - (2 * interval) valid_to = now self.assertTrue(isinstance(valid_from, datetime)) self.assertTrue(isinstance(valid_to, datetime)) self.assertTrue(isinstance(interval, timedelta))
def test_service_handlers(self): """ Test if we can calculate metrics """ self.client.force_login(self.u) self.assertTrue(get_user(self.client).is_authenticated()) _l = file_upload( os.path.join(gisdata.VECTOR_DATA, "san_andres_y_providencia_poi.shp"), name="san_andres_y_providencia_poi", user=self.u, overwrite=True, ) for idx, _l in enumerate(Layer.objects.all()): for inum in range(0, idx + 1): self.client.get(reverse('layer_detail', args=(_l.alternate, )), **{"HTTP_USER_AGENT": self.ua}) # Works only with Postgres requests = RequestEvent.objects.all() c = CollectorAPI() q = requests.order_by('created') c.process_requests(self.service, requests, q.first().created, q.last().created) interval = self.service.check_interval now = datetime.utcnow().replace(tzinfo=pytz.utc) valid_from = now - (2 * interval) valid_to = now self.assertTrue(isinstance(valid_from, datetime)) self.assertTrue(isinstance(valid_to, datetime)) self.assertTrue(isinstance(interval, timedelta)) # Works only with Postgres metrics = c.get_metrics_for(metric_name='request.ip', valid_from=valid_from, valid_to=valid_to, interval=interval) self.assertIsNotNone(metrics)