querying-tophog
Skill721 starsChanged 2 months agoMITView on GitHub
Query tophog — the ingestion pipeline's heavy-hitter store in ClickHouse — to identify hot or expensive actors (team_id, distinct_id, session_id, partition) during incident triage. Use when investigating ingestion lag, a hot or lagging Kafka partition, expensive person processing, merge storms, or any "which team or distinct_id is causing this" question. Covers the internal Metabase access path (SSO via hogli), the tophog schema, and the cost-vs-volume query lens. Internal-only: results contain cross-customer identifiers.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- PostHog/posthogword for word, first seen Oct 4, 2026
Other versions1 project uses a version of this.
Word for word · 1
- PostHog/posthog★ 40k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository119 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- common/CLAUDE.mdCLAUDE.md
- proto/CLAUDE.mdCLAUDE.md
- rust/CLAUDE.mdCLAUDE.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/react-typescript.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-llm-gateway-paritySkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- autoresolving-pr-conflictsSkill
- building-product-empty-statesSkill
- clickhouse-migrationsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- finding-llm-gateway-migration-candidatesSkill
- fixing-flaky-testsSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- implementing-mcp-ui-appsSkill
- implementing-warehouse-sourcesSkill
- improving-drf-endpointsSkill
- improving-mcp-toolsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 49
Run queries; the cookie is read internally and never enters the transcript:
- Distinctive: line 112
Check before relying on them:
- Very specific: line 204
Always bound timestamp — the table is partitioned by day and holds 30 days.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Querying tophog
tophog is the ingestion pipeline's heavy-hitter tracker: workers accumulate
per-key aggregates (counts, timers) in memory and periodically flush them to
the tophog ClickHouse table via Kafka (clickhouse_tophog topic). It answers
"which actor is responsible" questions that fleet-level Prometheus metrics
cannot — per-metric label cardinality is unbounded (distinct_id,
session_id), so this data lives only in ClickHouse. Retention is 30 days.
The staff-only Django admin has a dashboard over it, but for agent-driven triage query it directly through the internal Metabase.
Access — internal Metabase, never Grafana
The production ClickHouse clusters hold customer data, so there is
deliberately no ClickHouse datasource for agents in Grafana. The
sanctioned path is the internal Metabase using the engineer's own SSO
session — per-person identity, attributable in Metabase's query history, no
standing credential. General mechanics live in the
querying-production-databases-via-metabase skill; the short version:
- The user must run login themselves (the agent shell cannot access the
Keychain):
hogli metabase:login --region eu(orus). macOS will prompt about "Chrome Safe Storage" — that'sbrowser_cookie3decrypting the browser's cookie store to capture the SSO session; one-time Allow is the right choice. Discover the database id — it is not stable across Metabase rebuilds:
hogli metabase:databases --region euPick "PostHog ClickHouse PROD
<REGION>Data Tier" (the data tier, not the query tier — tophog lives with the events data).Run queries; the cookie is read internally and never enters the transcript:
hogli metabase:query --region eu --database-id <id> <<'SQL' SELECT ... SQL
Schema
Table tophog (Distributed over sharded_tophog), ordered by
(pipeline, lane, metric, timestamp, key), partitioned by day:
| Column | Type | Notes |
timestamp | DateTime64(6) | Flush-window time; always bound it (daily partitions) |
metric | LowCardinality(String) | See inventory below |
type | LowCardinality(String) | Aggregation semantics: sum (default), max, avg |
key | Map(String, String) | The actor: access as key['team_id'], key['distinct_id'], key['partition'], key['session_id'] |
value | Float64 | The aggregated value for this flush window |
count | UInt64 | Observations in the window |
pipeline | LowCardinality(String) | e.g. analytics |
lane | LowCardinality(String) | main, overflow, historical, async, turbo |
labels | Map(String, String) | Extra non-key labels |
One row is one worker's flush window for one (metric, key) — always aggregate
on read. Read-side semantics per type (matches the admin dashboard):
CASE type
WHEN 'max' THEN max(value)
WHEN 'avg' THEN sum(value * count) / sum(count)
ELSE sum(value)
ENDMetric inventory — discover live, don't trust lists
Metrics are defined inline in the ingestion pipelines (grep topHog( /
timer( / sum( in nodejs/src/ingestion/pipelines/analytics/), so the set
evolves. Always start with discovery:
SELECT metric, type, count() AS rows, sum(count) AS observations
FROM tophog
WHERE timestamp > now() - INTERVAL 1 HOUR
GROUP BY metric, type
ORDER BY metricAs of 2026-07-06 (master), the analytics metrics include
process_persons_time (timer; key: team_id, distinct_id, partition),
emitted_events[_per_distinct_id|_per_partition],
transformations_run[_per_partition],
events_dropped_by_transformation[_per_partition],
merge_events_per_distinct_id (merge-intent events: $create_alias /
$merge_dangerously with alias, $identify with $anon_distinct_id),
group_identify_events_per_distinct_id, resolved_teams, and session-replay
*_by_session_id timers.
Dimensions are deploy-gated and rows are immutable: the partition key on
process_persons_time and the merge/group-identify metrics merged 2026-07-06
and only exist in data written after that deploy reaches the environment.
Check before relying on them:
SELECT countIf(key['partition'] != '') AS with_partition, count() AS total
FROM tophog
WHERE timestamp > now() - INTERVAL 1 HOUR AND metric = 'process_persons_time'The lens: cost vs volume
This is the load-bearing idea. Volume ranking finds busy actors; cost ranking finds slow ones — and a single lagging partition is usually a cost problem (a real incident: the top-cost actor was invisible in every volume view). Rank by summed timer value, and compute the per-event ratio to classify what you found:
| Pattern | Reading |
| High events, normal ms/event | Hot key (volume) — overflow/rebalance is the lever |
| Low events, high ms/event | Expensive actor — fat person properties, merge-heavy, or contended writes; scaling out will not help |
Canned queries
Top actors by person-processing cost (the incident query):
SELECT
key['team_id'] AS team_id,
key['distinct_id'] AS distinct_id,
round(sum(value)) AS total_ms,
sum(count) AS events,
round(sum(value) / sum(count), 1) AS ms_per_event,
arraySort(groupUniqArray(lane)) AS lanes
FROM tophog
WHERE timestamp > now() - INTERVAL 1 HOUR
AND metric = 'process_persons_time'
GROUP BY team_id, distinct_id
ORDER BY total_ms DESC
LIMIT 10Scoped to one lagging partition (data written after the partition dimension deployed):
-- add to WHERE:
AND key['partition'] = '434'Merge storms (merges are the classic person-processing cost driver):
SELECT key['team_id'] AS team_id, key['distinct_id'] AS distinct_id,
key['partition'] AS partition, sum(value) AS merge_events
FROM tophog
WHERE timestamp > now() - INTERVAL 1 HOUR
AND metric = 'merge_events_per_distinct_id'
GROUP BY team_id, distinct_id, partition
ORDER BY merge_events DESC
LIMIT 10Generic top-10 per metric with correct type semantics (the admin dashboard's
query shape) — filter by pipeline / lane as needed:
SELECT metric, type, key, total, obs
FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY metric, type ORDER BY total DESC) AS rn
FROM (
SELECT metric, type, key,
CASE type
WHEN 'max' THEN max(value)
WHEN 'avg' THEN sum(value * count) / sum(count)
ELSE sum(value)
END AS total,
sum(count) AS obs
FROM tophog
WHERE timestamp > now() - INTERVAL 1 HOUR
AND pipeline = 'analytics' AND lane = 'main'
GROUP BY metric, type, key
)
)
WHERE rn <= 10
ORDER BY metric, type, rnCautions
distinct_idandsession_idvalues are customer PII (often emails). Internal triage use only — never paste them into public PRs, issues, or commit messages.- Always bound
timestamp— the table is partitioned by day and holds 30 days. - Queries run under the engineer's Metabase identity and appear in their query history.
Related
monitoring-ingestion-pipeline— the Grafana-side diagnosis, including the single-partition-lag playbook that hands off to this skill for actor identification.- The pganalyze MCP — the next hop when person processing is implicated (query-level view of the persons Postgres).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

