Skip to content

Commit de442b1

Browse files
committed
Add a time_since_oldest gauge, and rename the gauges a bit
1 parent 41014d5 commit de442b1

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

partitionmanager/cli.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,13 @@ def stats_cmd(args):
211211
"total", help_text="Total number of partitions", type="counter"
212212
)
213213
metrics.describe(
214-
"time_since_last_partitioned_seconds",
215-
help_text="How many seconds since the last partition was created",
214+
"time_since_newest_partition_seconds",
215+
help_text="The age in seconds of the last partition for the table",
216+
type="gauge",
217+
)
218+
metrics.describe(
219+
"time_since_oldest_partition_seconds",
220+
help_text="The age in seconds of the first partition for the table",
216221
type="gauge",
217222
)
218223
metrics.describe(
@@ -229,11 +234,17 @@ def stats_cmd(args):
229234
for table, results in all_results.items():
230235
if "partitions" in results:
231236
metrics.add("total", table, results["partitions"])
232-
if "time_since_last_partition" in results:
237+
if "time_since_newest_partition" in results:
238+
metrics.add(
239+
"time_since_newest_partition_seconds",
240+
table,
241+
results["time_since_newest_partition"].total_seconds(),
242+
)
243+
if "time_since_oldest_partition" in results:
233244
metrics.add(
234-
"time_since_last_partitioned_seconds",
245+
"time_since_oldest_partition_seconds",
235246
table,
236-
results["time_since_last_partition"].total_seconds(),
247+
results["time_since_oldest_partition"].total_seconds(),
237248
)
238249
if "mean_partition_delta" in results:
239250
metrics.add(

partitionmanager/cli_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ def test_stats(self):
189189
)
190190
r = stats_cmd(args)
191191
self.assertEqual(r["partitioned_yesterday"]["partitions"], 3)
192-
self.assertLess(r["partitioned_yesterday"]["time_since_last_partition"].days, 2)
192+
self.assertLess(
193+
r["partitioned_yesterday"]["time_since_newest_partition"].days, 2
194+
)
195+
self.assertLess(
196+
r["partitioned_yesterday"]["time_since_oldest_partition"].days, 32
197+
)
193198
self.assertGreater(r["partitioned_yesterday"]["mean_partition_delta"].days, 2)
194199
self.assertGreater(r["partitioned_yesterday"]["max_partition_delta"].days, 2)
195200

partitionmanager/stats.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def get_statistics(partitions, current_timestamp, table):
7474
raise UnexpectedPartitionException(tail_part)
7575

7676
if tail_part.timestamp():
77-
results["time_since_last_partition"] = current_timestamp - tail_part.timestamp()
77+
results["time_since_newest_partition"] = (
78+
current_timestamp - tail_part.timestamp()
79+
)
7880

7981
for p in partitions:
8082
if p.timestamp():
@@ -84,6 +86,11 @@ def get_statistics(partitions, current_timestamp, table):
8486
if not head_part or head_part == tail_part:
8587
return results
8688

89+
if head_part.timestamp():
90+
results["time_since_oldest_partition"] = (
91+
current_timestamp - head_part.timestamp()
92+
)
93+
8794
if head_part.timestamp() and tail_part.timestamp():
8895
results["mean_partition_delta"] = (
8996
tail_part.timestamp() - head_part.timestamp()

partitionmanager/stats_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_statistics_single_partition(self):
2929
[MaxValuePartition("p_19480113", 1)], ts, Table("single_part")
3030
)
3131
self.assertEqual(
32-
s, {"partitions": 1, "time_since_last_partition": timedelta(days=365)}
32+
s, {"partitions": 1, "time_since_newest_partition": timedelta(days=365)}
3333
)
3434

3535
def test_statistics_two_partitions(self):
@@ -42,7 +42,8 @@ def test_statistics_two_partitions(self):
4242
s,
4343
{
4444
"partitions": 2,
45-
"time_since_last_partition": timedelta(days=11),
45+
"time_since_newest_partition": timedelta(days=11),
46+
"time_since_oldest_partition": timedelta(days=377),
4647
"mean_partition_delta": timedelta(days=366),
4748
"max_partition_delta": timedelta(days=366),
4849
},
@@ -63,7 +64,8 @@ def test_statistics_weekly_partitions_year(self):
6364
s,
6465
{
6566
"partitions": 53,
66-
"time_since_last_partition": timedelta(days=14),
67+
"time_since_newest_partition": timedelta(days=14),
68+
"time_since_oldest_partition": timedelta(days=378),
6769
"mean_partition_delta": timedelta(days=7),
6870
"max_partition_delta": timedelta(days=7),
6971
},

0 commit comments

Comments
 (0)