lex-metering 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CLAUDE.md +2 -2
- data/lib/legion/extensions/metering/runners/metering.rb +13 -9
- data/lib/legion/extensions/metering/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f6ed98a119f0cd8391dfcbabef08384a0ead7ff8f9cfd45added086ce825ddef
|
|
4
|
+
data.tar.gz: 47b5dc7406297ff5c9bec985b4d4ef2d0d554cc3cea0c0c489305d545c22b07f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be6917d55265e01b080e4165de8c5df74c41ab38738ad6400e0fe84188d61e5e022ec806f0fb19e705fa2d04a5877d33892f744978c18a018e8dda9ef25784ec
|
|
7
|
+
data.tar.gz: d12d6e44b297b5d533a3f6e49764f9fbd3a4e74a86594c83c1a5e13812a6654f08667f81fc5a84a34368a75cf8b8c8a11933bc894ba4f5aa1833070608749d40
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.3] - 2026-03-18
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- `worker_costs` period filtering now uses cross-DB `Sequel.lit('recorded_at >= ?', cutoff)` with Ruby time arithmetic instead of PostgreSQL-only `CURRENT_TIMESTAMP - INTERVAL` syntax
|
|
7
|
+
|
|
3
8
|
## [0.1.2] - 2026-03-17
|
|
4
9
|
|
|
5
10
|
### Changed
|
data/CLAUDE.md
CHANGED
|
@@ -11,7 +11,7 @@ Captures LLM token usage metrics per task for cost attribution and intelligent r
|
|
|
11
11
|
## Gem Info
|
|
12
12
|
|
|
13
13
|
- **Gem name**: `lex-metering`
|
|
14
|
-
- **Version**: `0.1.
|
|
14
|
+
- **Version**: `0.1.3`
|
|
15
15
|
- **Module**: `Legion::Extensions::Metering`
|
|
16
16
|
- **Ruby**: `>= 3.4`
|
|
17
17
|
- **License**: MIT
|
|
@@ -72,4 +72,4 @@ lib/legion/extensions/metering/
|
|
|
72
72
|
- Extension has `data_required? true` (both at module level and instance level) — will skip loading if `legion-data` is not connected
|
|
73
73
|
- No explicit actors — gets auto-generated subscription actors from the framework
|
|
74
74
|
- `routing_stats` uses `select_append { avg(latency_ms).as(avg_latency) }` — Sequel virtual row syntax
|
|
75
|
-
- Time interval filtering uses `Sequel.lit(
|
|
75
|
+
- Time interval filtering uses `Sequel.lit('recorded_at >= ?', cutoff)` with Ruby `Time` arithmetic for cross-database compatibility (PostgreSQL, SQLite, MySQL)
|
|
@@ -5,6 +5,8 @@ module Legion
|
|
|
5
5
|
module Metering
|
|
6
6
|
module Runners
|
|
7
7
|
module Metering
|
|
8
|
+
PERIOD_DAYS = { 'daily' => 1, 'weekly' => 7, 'monthly' => 30 }.freeze
|
|
9
|
+
|
|
8
10
|
def record(worker_id: nil, task_id: nil, provider: nil, model_id: nil,
|
|
9
11
|
input_tokens: 0, output_tokens: 0, thinking_tokens: 0,
|
|
10
12
|
input_context_bytes: 0, latency_ms: 0, routing_reason: nil,
|
|
@@ -35,15 +37,7 @@ module Legion
|
|
|
35
37
|
|
|
36
38
|
def worker_costs(worker_id:, period: 'daily', **)
|
|
37
39
|
ds = Legion::Data.connection[:metering_records].where(worker_id: worker_id)
|
|
38
|
-
|
|
39
|
-
case period
|
|
40
|
-
when 'daily'
|
|
41
|
-
ds = ds.where { recorded_at >= Sequel.lit("CURRENT_TIMESTAMP - INTERVAL '1 day'") }
|
|
42
|
-
when 'weekly'
|
|
43
|
-
ds = ds.where { recorded_at >= Sequel.lit("CURRENT_TIMESTAMP - INTERVAL '7 days'") }
|
|
44
|
-
when 'monthly'
|
|
45
|
-
ds = ds.where { recorded_at >= Sequel.lit("CURRENT_TIMESTAMP - INTERVAL '30 days'") }
|
|
46
|
-
end
|
|
40
|
+
ds = apply_period_filter(ds, period)
|
|
47
41
|
|
|
48
42
|
{
|
|
49
43
|
worker_id: worker_id,
|
|
@@ -93,6 +87,16 @@ module Legion
|
|
|
93
87
|
Legion::Logging.info "[metering] cleanup: purged=#{count} retention_days=#{retention_days} cutoff=#{cutoff}"
|
|
94
88
|
{ purged: count, retention_days: retention_days, cutoff: cutoff }
|
|
95
89
|
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
|
|
93
|
+
def apply_period_filter(dataset, period)
|
|
94
|
+
days = PERIOD_DAYS[period]
|
|
95
|
+
return dataset unless days
|
|
96
|
+
|
|
97
|
+
cutoff = Time.now.utc - (days * 86_400)
|
|
98
|
+
dataset.where(::Sequel.lit('recorded_at >= ?', cutoff))
|
|
99
|
+
end
|
|
96
100
|
end
|
|
97
101
|
end
|
|
98
102
|
end
|