Revision: 341
Author: bslatkin
Date: Mon Mar 1 00:07:24 2010
Log: hub: fix per-callback stat value
http://code.google.com/p/pubsubhubbub/source/detail?r=341
Modified:
/trunk/hub/dos.py
/trunk/hub/dos_test.py
/trunk/hub/main.py
=======================================
--- /trunk/hub/dos.py Sun Feb 28 23:04:32 2010
+++ /trunk/hub/dos.py Mon Mar 1 00:07:24 2010
@@ -529,7 +529,6 @@
self.title = config.title
self.key_name = config.key_name
self.value_units = config.value_units
- self.overall_rate = 1.0 * self.total_samples / time_elapsed
# Maps key -> [(when, value), ...]
self.sample_dict = {}
@@ -548,6 +547,14 @@
samples.append((when, value))
self.unique_samples += 1
+ def overall_rate(self):
+ """Gets the overall rate of events.
+
+ Returns:
+ Total events per second.
+ """
+ return 1.0 * self.total_samples / self.time_elapsed
+
def get_min(self, key):
"""Gets the min value seen for a key.
@@ -804,7 +811,11 @@
key, when_encoded, value_encoded = (
combined_value.rsplit(':', 2) + ['', '', ''])[:3]
if single_key is not None and single_key != key:
+ # Must decement the overall count in the result to prevent us from
+ # leaking the total number of samples made thus far.
+ results.total_samples -= 1
continue
+
if len(when_encoded) != 4:
continue
when = struct.unpack('!l', when_encoded)[0]
=======================================
--- /trunk/hub/dos_test.py Sun Feb 28 23:04:32 2010
+++ /trunk/hub/dos_test.py Mon Mar 1 00:07:24 2010
@@ -1039,6 +1039,40 @@
expected_min=5,
expected_average=5)
+ def testGetSingleKey(self):
+ """Tests getting the stats for a single key."""
+ config = dos.ReservoirConfig(
+ 'always',
+ period=300,
+ rate=1,
+ samples=10000,
+ by_domain=True)
+ sampler = dos.MultiSampler([config], gettime=self.fake_gettime)
+
+ reporter = dos.Reporter()
+ reporter.set(self.url1, config)
+ reporter.set(self.url2, config)
+ reporter.set(self.url3, config)
+ reporter.set(self.url4, config)
+ reporter.set(self.url5, config)
+ self.gettime_results.extend([0, 10, 10])
+ sampler.sample(reporter)
+ results = sampler.get(config)
+ self.assertEquals(5, results.total_samples)
+ self.assertEquals(5, results.unique_samples)
+ self.verify_sample(results, self.domainA, 1, 0.1)
+ self.verify_sample(results, self.domainB, 2, 0.2)
+ self.verify_sample(results, self.domainC, 1, 0.1)
+ self.verify_sample(results, self.domainD, 1, 0.1)
+
+ results = sampler.get(config, self.domainA)
+ self.assertEquals(1, results.total_samples)
+ self.assertEquals(1, results.unique_samples)
+ self.verify_sample(results, self.domainA, 1, 0.1)
+ self.verify_no_sample(results, self.domainB)
+ self.verify_no_sample(results, self.domainC)
+ self.verify_no_sample(results, self.domainD)
+
def testCountLost(self):
"""Tests when the count variable disappears between samples."""
config = dos.ReservoirConfig(
=======================================
--- /trunk/hub/main.py Sun Feb 28 23:22:07 2010
+++ /trunk/hub/main.py Mon Mar 1 00:07:24 2010
@@ -2926,7 +2926,9 @@
}
if not subscription or (
- subscription.secret and subscription.secret != secret):
+ not users.is_current_user_admin() and
+ subscription.secret and
+ subscription.secret != secret):
context.update({
'error': 'Could not find any subscription for '
'the given (callback, topic, secret) tuple'