Skip to content

Compare changes

Choose two branches to see what one has that the other does not, then open a pull request for it.

Open a pull request

4 commits

3 files+30−130/3 viewed
+8−5
191191 const days = Math.max(1, Math.ceil((Date.now() - new Date(since).getTime()) / 86_400_000));
192192 // While g1t is free nothing is charged, so usage is measured at cost
193193 // and credit is not drawn down.
194− const total = usage.free ? usage.usedMicros : usage.spentMicros;
195− const perDay = usage.free ? 0 : total / days;
194+ // Free or comped, nothing is charged: what the runs used, at cost, is
195+ // what there is to show.
196+ const atCost = usage.free || comped;
197+ const total = atCost ? usage.usedMicros : usage.spentMicros;
198+ const perDay = atCost ? 0 : total / days;
196199 const runway = perDay > 0 ? Math.floor(account.balanceMicros / perDay) : null;
197200 return (
198201 <div className="space-y-8">
214217 </div>
215218
216219 <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
217− {usage.free ? (
220+ {atCost ? (
218221 <Stat
219222 label="Used"
220223 value={dollars(total)}
221− note="At cost. Nothing is charged while g1t is being built out."
224+ note={comped ? "At cost. The workspace is comped: nothing is charged." : "At cost. Nothing is charged while g1t is being built out."}
222225 />
223226 ) : (
224227 <Stat
270273
271274 <section className="rounded-2xl bg-surface p-5 ring-1 ring-line">
272275 <div className="flex flex-wrap items-baseline justify-between gap-3">
273− <h3 className="text-sm font-medium">{usage.free ? "Usage per day" : "Spend per day"}</h3>
276+ <h3 className="text-sm font-medium">{atCost ? "Usage per day" : "Spend per day"}</h3>
274277 <ul className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted">
275278 {byTask.map((slice) => (
276279 <li key={slice.key} className="flex items-center gap-1.5">
+14−2
382382 micros: Option<i64>,
383383 runs: Option<u32>,
384384 }
385− // While nothing is charged, what was used is what there is to show.
386− let measure = if self.free { "COALESCE(cost_micros, 0)" } else { "-amount_micros" };
385+ // While nothing is charged (g1t is free, or the workspace is
386+ // comped), what was used is what there is to show.
387+ #[derive(serde::Deserialize)]
388+ struct Comped {
389+ n: i64,
390+ }
391+ let comped = self
392+ .db
393+ .prepare("SELECT COUNT(*) AS n FROM billing_accounts WHERE kind = 'workspace' AND terms_kind = 'comped' AND substr(id, 4) = ?1")
394+ .bind(&[workspace.as_str().into()])?
395+ .first::<Comped>(None)
396+ .await?
397+ .is_some_and(|row| row.n > 0);
398+ let measure = if self.free || comped { "COALESCE(cost_micros, 0)" } else { "-amount_micros" };
387399 let slices = |key: &str, limit: u32| {
388400 format!(
389401 "SELECT {key} AS key, SUM({measure}) AS micros, COUNT(*) AS runs FROM ledger
+8−6
15581558 }
15591559 };
15601560 timing.mark("kept");
1561− if let Some((response, status, message)) = limited? {
1562− after.ended(status, Some(message.to_owned()));
1563− after.spawn(env, ctx);
1564− return Ok(response);
1565− }
1561+ // A kept pack first: it never reaches the store, so it is never an
1562+ // operation, and a free workspace past its operation cap still gets
1563+ // it. (The other limits are a push's, and a pack is only a fetch.)
15661564 if let Some(kept) = pack {
15671565 timing.note("pack", "hit");
1568− // Never reached the store: never an operation.
15691566 let sent = body.as_ref().map_or(0, |body| body.len() as u64);
15701567 meters::record(pack_cache::HIT, &key, sent, kept.size);
15711568 after.ended(200, None);
15721569 after.spawn(env, ctx);
15731570 return kept.response();
15741571 }
1572+ if let Some((response, status, message)) = limited? {
1573+ after.ended(status, Some(message.to_owned()));
1574+ after.spawn(env, ctx);
1575+ return Ok(response);
1576+ }
15751577 if pack_key.is_some() {
15761578 timing.note("pack", "miss");
15771579 }