Skip to content

Commit 5b8ab41

Browse files
authored
Adoption charts distribution, stars, and active instances (#1690)
* Adoption charts distribution, stars, and active instances Show observed counter history and keep gaps where telemetry has no measurement. Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> * The rename fixture keeps both memory cases Use distinct prose so canonicalization does not merge the two setup writes. Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> --------- Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
1 parent b07a10e commit 5b8ab41

17 files changed

Lines changed: 519 additions & 109 deletions

‎deploy/telemetry/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ region and set these server-side environment variables in Production.
3232
| `LOOM_TELEMETRY_CLICKHOUSE_PASSWORD` | Credential for that user |
3333
| `CRON_SECRET` | Secret for the daily snapshot job |
3434

35-
Vercel calls `/api/oss-snapshot` daily to save GitHub star and fork counts. The metric
36-
row key makes repeated runs on the same UTC day replace that day's snapshot. Set a
35+
Vercel calls `/api/oss-snapshot` daily to save GitHub star and fork counts, release
36+
asset downloads, and GHCR pulls. The metric row key makes repeated runs on the same
37+
UTC day replace that day's snapshot. Distribution charts show the latest observed
38+
total and compare snapshots from consecutive complete periods. Set a
3739
request rate limit on `/api/v1/adoption` in the deployment firewall. Before releasing
3840
the reporting worker, send a synthetic report to a deployment configured with a test
3941
warehouse. Check the acknowledgement, then resend the report and confirm that

‎docs/components/AdoptionActivity.astro‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
2-
import type { ChartGrain } from "../lib/adoption-chart-series.mjs";
3-
import { activityPoints } from "../lib/adoption-chart-series.mjs";
2+
import { Panel } from "@clickhouse/click-ui/Panel";
3+
import { Text } from "@clickhouse/click-ui/Text";
4+
import { Title } from "@clickhouse/click-ui/Title";
5+
import { activityPoints, periodStart, type ChartGrain } from "../lib/adoption-chart-series.mjs";
46
import AdoptionMetricPair from "./AdoptionMetricPair.astro";
7+
import AdoptionTrend from "./AdoptionTrend.astro";
58
69
interface Props {
710
rows: {
@@ -19,11 +22,12 @@ interface Props {
1922
grain: ChartGrain;
2023
rangeStart?: string;
2124
rangeEnd?: string;
22-
view: "activity" | "accounts" | "requests";
25+
view: "activity" | "accounts" | "instances" | "requests";
26+
firstAccountReport?: string;
2327
showProcesses?: boolean;
2428
}
2529
26-
const { rows, grain, rangeStart, rangeEnd, view, showProcesses } = Astro.props;
30+
const { rows, grain, rangeStart, rangeEnd, view, firstAccountReport, showProcesses } = Astro.props;
2731
const accountPoints = activityPoints(rows, "active_accounts", grain, "accounts_days_reported");
2832
const processPoints = activityPoints(rows, "serving_processes", grain, "processes_days_reported");
2933
---
@@ -53,7 +57,10 @@ const processPoints = activityPoints(rows, "serving_processes", grain, "processe
5357
{view === "accounts" && (
5458
<AdoptionMetricPair
5559
label="Active users"
56-
description="Authenticated users with successful requests, including service identities."
60+
description={
61+
"Authenticated users with successful requests, including service identities." +
62+
(firstAccountReport ? ` The first reported count in this window was on ${firstAccountReport} UTC.` : "")
63+
}
5764
observedLabel={grain === "day" ? "Daily total" : "Peak daily total"}
5865
rows={accountPoints}
5966
{grain}
@@ -62,6 +69,24 @@ const processPoints = activityPoints(rows, "serving_processes", grain, "processe
6269
axisEnd={rangeEnd}
6370
/>
6471
)}
72+
{view === "instances" && (
73+
<Panel orientation="vertical" alignItems="start" padding="lg" gap="xs" hasBorder fillWidth>
74+
<Title type="h3" size="sm">Active instances</Title>
75+
<Text size="sm" color="muted">
76+
Loom serving processes with successful requests across reporting installations. Restarts and workers can count separately.
77+
{grain !== "day" && " Each point shows the peak daily total."}
78+
</Text>
79+
<AdoptionTrend
80+
label="Active instances over time"
81+
rows={processPoints}
82+
{grain}
83+
mode="line"
84+
axisStart={rangeStart && periodStart(rangeStart, grain)}
85+
axisEnd={rangeEnd && periodStart(rangeEnd, grain)}
86+
emptyMessage="No instance counts were reported in this window."
87+
/>
88+
</Panel>
89+
)}
6590
{view === "activity" && (showProcesses || processPoints.length > 0) && (
6691
<AdoptionMetricPair
6792
label="Serving processes"

‎docs/components/AdoptionDomainDirectory.astro‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ const headers = [
5858
},
5959
{ label: "Requests", scope: "col" as const, width: "124px" },
6060
{ label: "Active users", scope: "col" as const },
61-
{ label: "Active instances", scope: "col" as const },
62-
...(withProcesses ? [{ label: "Serving processes", scope: "col" as const }] : []),
61+
{ label: "Active installations", scope: "col" as const },
62+
...(withProcesses ? [{ label: "Active instances", scope: "col" as const }] : []),
6363
{ label: "Loom version", scope: "col" as const },
6464
{ label: "First seen", scope: "col" as const },
6565
{ label: "Last active", scope: "col" as const },
@@ -123,7 +123,7 @@ const headers = [
123123
{page < lastPage && <Button {...{ name: "domain_page", value: String(page + 1) }} htmlType="submit" type="secondary" iconRight="chevron-right" label="Next" />}
124124
</form>}
125125
</div>
126-
{withUsage && <Text size="sm" color="muted">Active instances ran a successful request. Domain activity uses completed daily reports. User and process counts use the latest measured UTC day.</Text>}
126+
{withUsage && <Text size="sm" color="muted">Active installations recorded a successful request. Domain activity uses completed daily reports. User and instance counts use the latest measured UTC day.</Text>}
127127
</Panel>
128128
)}
129129
</section>

‎docs/components/AdoptionPage.astro‎

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { readAdoptionPage } from "../lib/adoption-request.mjs";
1111
import {
1212
adoptionGrowthForRange,
1313
adoptionPaths,
14+
dailyActivityForRange,
1415
daysBefore,
1516
periodOffset,
1617
thresholds,
@@ -59,13 +60,10 @@ const directoryFallback = ranked == null && requestedDirectoryDays === 30;
5960
const summary = selfHosted.totals?.find(
6061
({ range_days, comparison }) => range_days === days && comparison === "current",
6162
);
62-
const latestAccounts = selfHosted.activity
63-
.filter(
64-
({ grain, period, active_accounts }) =>
65-
grain === "day" && period >= cutoff && period < today && Number.isFinite(active_accounts),
66-
)
67-
.sort((left, right) => right.period.localeCompare(left.period))
68-
.at(0);
63+
const accountReports = dailyActivityForRange(selfHosted.activity, "active_accounts", cutoff, today);
64+
const firstAccounts = accountReports[0];
65+
const latestAccounts = accountReports.at(-1);
66+
const latestInstances = dailyActivityForRange(selfHosted.activity, "serving_processes", cutoff, today).at(-1);
6967
const overview = [
7068
{
7169
label: "Active domains",
@@ -83,11 +81,17 @@ const overview = [
8381
note: latestAccounts ? `Reported ${showDay(latestAccounts.period)} UTC` : "User data unavailable",
8482
},
8583
{ label: "Active installations", value: summary?.active, note: "At least one successful request" },
84+
{
85+
label: "Active instances",
86+
value: latestInstances?.serving_processes,
87+
note: latestInstances ? `Reported ${showDay(latestInstances.period)} UTC` : "Instance data unavailable",
88+
},
8689
{ label: "Successful requests", value: summary?.operations, note: "Across all Loom features" },
8790
];
8891
8992
const growthMetrics = [
9093
{ value: "installations", label: "Installations" },
94+
{ value: "instances", label: "Instances" },
9195
{ value: "accounts", label: "Users" },
9296
{ value: "requests", label: "Requests" },
9397
] as const;
@@ -182,12 +186,10 @@ const sdkSeries = groupDailySeries(selectedSdk?.history ?? [], grain, { start: c
182186
const stars = oss.find(({ id }) => id === "stars");
183187
const starSeries = groupDailySeries(stars?.history ?? [], grain, {
184188
start: cutoff,
185-
end: daysBefore(today, -1),
189+
end: today,
186190
kind: "gauge",
187-
}).map((point) => ({
188-
...point,
189-
current: point.current || (stars?.day === today && point.day === periodStart(today, grain)),
190-
}));
191+
includeCurrent: true,
192+
});
191193
const distribution = oss.filter(({ id }) => id === "releases" || id === "pulls");
192194
const selectedDistribution =
193195
distribution.find(({ id }) => id === input("distribution")) ??
@@ -197,6 +199,7 @@ const distributionSeries = groupDailySeries(selectedDistribution?.history ?? [],
197199
start: cutoff,
198200
end: today,
199201
kind: "gauge",
202+
includeCurrent: true,
200203
});
201204
const moreSdks = [
202205
["Go SDK", "/docs/reference/go-sdk"],
@@ -284,7 +287,14 @@ const state = Object.fromEntries(
284287
</form>
285288
{selectedGrowth === "installations"
286289
? <AdoptionGrowth rows={growth} {grain} rangeStart={cutoff} rangeEnd={lastDay} />
287-
: <AdoptionActivity rows={events} {grain} view={selectedGrowth} rangeStart={cutoff} rangeEnd={lastDay} />}
290+
: <AdoptionActivity
291+
rows={events}
292+
{grain}
293+
view={selectedGrowth}
294+
rangeStart={cutoff}
295+
rangeEnd={lastDay}
296+
firstAccountReport={firstAccounts && showDay(firstAccounts.period)}
297+
/>}
288298
</section>
289299

290300
<AdoptionDomainDirectory
@@ -433,19 +443,22 @@ const state = Object.fromEntries(
433443
<section class="adoption-section" id="repository" aria-labelledby="repository-title">
434444
<div class="section-heading">
435445
<Title type="h2" size="lg" id="repository-title">GitHub stars</Title>
436-
{starSeries.length > 0 && <AdoptionDownload {path} {state} dataset="stars" label="Export stars CSV" />}
446+
{stars?.history.some(({ reconstructed }) => !reconstructed) &&
447+
<AdoptionDownload {path} {state} dataset="stars" label="Export UTC totals CSV" />}
437448
</div>
438449
<Panel className="stars-chart" orientation="vertical" alignItems="start" padding="lg" gap="xs" hasBorder fillWidth>
439450
<AdoptionTrend
440451
label="GitHub stars over time"
441452
rows={starSeries}
442453
{grain}
443454
mode="line"
444-
fitObservedRange
445455
axisStart={periodStart(cutoff, grain)}
446456
axisEnd={periodStart(stars?.day === today ? today : lastDay, grain)}
447457
emptyMessage="Star history is unavailable for this window."
448458
/>
459+
{stars?.history.some(({ reconstructed }) => reconstructed) && (
460+
<Text size="sm" color="muted">Earlier points use GitHub’s daily star counts and reporting calendar.</Text>
461+
)}
449462
</Panel>
450463
</section>
451464

@@ -472,7 +485,7 @@ const state = Object.fromEntries(
472485
{grain}
473486
kind="gauge"
474487
axisStart={cutoff}
475-
axisEnd={lastDay}
488+
axisEnd={selectedDistribution.day === today ? today : lastDay}
476489
observedLabel="Cumulative snapshot"
477490
growthLabel={"Net change per " + grain}
478491
/>
@@ -501,7 +514,7 @@ const state = Object.fromEntries(
501514
.adoption-window { display: grid; gap: 0.2rem; text-align: end; }
502515
.overview { margin-block-end: clamp(1.35rem, 3vw, 2.25rem); }
503516
.metrics, .sdk-metrics, .two-column { display: grid; gap: 0.75rem; }
504-
.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
517+
.metrics { grid-template-columns: repeat(5, minmax(0, 1fr)); }
505518
.sdk-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
506519
.counters, .two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
507520
.two-column > :only-child { grid-column: 1 / -1; }
@@ -534,7 +547,10 @@ const state = Object.fromEntries(
534547
.sdk-list { display: flex; flex-wrap: wrap; gap: 0 1rem; list-style: none; padding: 0; margin-block: 0.65rem 0; }
535548
.sdk-list :global(a) { display: inline-flex; align-items: center; min-block-size: 2.75rem; }
536549
.adoption-cta { margin-block-start: clamp(1.4rem, 3vw, 2.75rem); }
537-
@media (max-width: 60rem) { .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
550+
@media (max-width: 60rem) {
551+
.metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
552+
.metrics > :last-child { grid-column: 1 / -1; }
553+
}
538554
@media (max-width: 43rem) { .two-column, .sdk-metrics { grid-template-columns: minmax(0, 1fr); } }
539555
@media (max-width: 38rem) { .adoption-window { text-align: start; } }
540556
@media (max-width: 26rem) {

‎docs/components/AdoptionTrend.astro‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface Props {
99
mode?: "line" | "bars";
1010
color?: "accent" | "info";
1111
axisMaximum?: number;
12-
fitObservedRange?: boolean;
1312
axisStart?: string;
1413
axisEnd?: string;
1514
compact?: boolean;
@@ -25,7 +24,6 @@ const {
2524
mode = "bars",
2625
color = "accent",
2726
axisMaximum = 0,
28-
fitObservedRange = false,
2927
axisStart,
3028
axisEnd,
3129
compact = false,
@@ -58,14 +56,8 @@ const rawMaximum = Math.max(0, axisMaximum, ...reported.map(({ value }) => value
5856
const rawMinimum = Math.min(0, ...reported.map(({ value }) => value));
5957
const signed = rawMinimum < 0;
6058
const upper = signed && rawMaximum > 0 ? scaleLimit(Math.max(rawMaximum, -rawMinimum)) : scaleLimit(rawMaximum);
61-
let minimum = signed ? (rawMaximum > 0 ? -upper : -scaleLimit(-rawMinimum)) : 0;
62-
let maximum = !signed && upper === 0 ? 1 : upper;
63-
if (fitObservedRange && mode === "line" && reported.length > 0 && !signed) {
64-
const lower = Math.min(...reported.map(({ value }) => value));
65-
const step = scaleLimit(Math.max(1, (rawMaximum - lower) / 2));
66-
minimum = Math.max(0, Math.floor((lower - step / 3) / step) * step);
67-
maximum = Math.max(minimum + 2 * step, Math.ceil(rawMaximum / step) * step);
68-
}
59+
const minimum = signed ? (rawMaximum > 0 ? -upper : -scaleLimit(-rawMinimum)) : 0;
60+
const maximum = !signed && upper === 0 ? 1 : upper;
6961
const yPosition = (value: number) => 100 - ((value - minimum) * 100) / (maximum - minimum);
7062
const zero = yPosition(0);
7163

‎docs/lib/adoption-chart-series.mjs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ export function scaleLimit(value) {
3131

3232
/**
3333
* Group dated observations inside [start, end). A gauge uses its last observed level in each period.
34+
* Include the end date for a live counter whose current period is still in progress.
3435
* @param {ReadonlyArray<ChartPoint>} history
3536
* @param {ChartGrain} grain
36-
* @param {{start: string, end: string, kind?: ChartKind}} options
37+
* @param {{start: string, end: string, kind?: ChartKind, includeCurrent?: boolean}} options
3738
* @returns {ChartPoint[]}
3839
*/
39-
export function groupDailySeries(history, grain, { start, end, kind = "additive" }) {
40+
export function groupDailySeries(history, grain, { start, end, kind = "additive", includeCurrent = false }) {
41+
const observationEnd = includeCurrent ? daysBefore(end, -1) : end;
4042
const reported = history
41-
.filter(({ day, value }) => day >= start && day < end && Number.isFinite(value))
43+
.filter(({ day, value }) => day >= start && day < observationEnd && Number.isFinite(value))
4244
.sort((left, right) => left.day.localeCompare(right.day));
4345
const periods = Map.groupBy(reported, ({ day }) => periodStart(day, grain));
4446
return Array.from(periods, ([day, rows]) => {

‎docs/lib/adoption-chart-series.test.mjs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ test("source intervals sum observed events or use the last observed gauge", () =
3232
);
3333
});
3434

35+
test("published counters plot today's snapshot without counting it as completed activity", () => {
36+
const today = "2026-11-28";
37+
const options = { start: "2026-11-01", end: today, kind: "gauge", includeCurrent: true };
38+
for (const value of [1325, 2161]) {
39+
const points = groupDailySeries([{ day: today, value }], "day", options);
40+
assert.deepEqual(points, [{ day: today, value, days: 1, current: true, partial: false }]);
41+
assert.deepEqual(metricGrowth(points, "day", "gauge"), []);
42+
}
43+
44+
const points = groupDailySeries(
45+
[
46+
{ day: "2026-11-26", value: 1200 },
47+
{ day: "2026-11-27", value: 1220 },
48+
{ day: today, value: 1325 },
49+
],
50+
"day",
51+
options,
52+
);
53+
assert.deepEqual(
54+
metricGrowth(points, "day", "gauge").map(({ value }) => value),
55+
[20],
56+
);
57+
});
58+
3559
test("cumulative observed counts preserve gaps and reported zeros", () => {
3660
const rows = [
3761
{ day: "2026-01-04", value: 5, partial: true },

0 commit comments

Comments
 (0)