Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(mcp-analytics): crown the lab with the highest share (#114881)

Paul D'Ambra235772ac42c4
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e588326e20c5..a1dc2542acbb 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6927,13 +6927,13 @@ snapshots:
products-dashboards-tiles-image-tile-modal--existing-image--light:
hash: v1.k794b7964.a6f0232a7044b1a581e4beb9105ee9c00bbed9748fdfcd1c3c1a232acfa0333c.D40_QysPPcg1v2fjLF3-6qPyFXkBZ9rrdYat6l6djGU
products-dashboards-tiles-tile-decorations--cheeky-hog-on-hover--dark:
- hash: v1.k794b7964.8143bc5de1bfcac35f1b2ab9b9513a70bf005f7c998776290346cf47f6844d19.qCySXkG3gQLbLrXK85AOJT5ILT_vXkW8WX6o4jVq214
+ hash: v1.k794b7964.ce78d8eadbce18e2f25df24a9dd0d5400ab37f4502fe9d65ddcd4c572e30bf01.fFyVgKjKL0us2bm17v1zhQcaAQf5oWLR5MTZahsY70c
products-dashboards-tiles-tile-decorations--cheeky-hog-on-hover--light:
- hash: v1.k794b7964.0e28bdfc8b5eba2a60c9e4e16ff4bbeabd8ea4388588aa162e642daf06a79e3c.mGMlQpZDe7OSM0k9DShVQfiRN_dtROsqt4yJhdiskVc
+ hash: v1.k794b7964.8c3dd173301e76c957f5d5259ba2a744c100bdc814186becf76ae4baca8f8cbc.UGY3dCKIbp692OhMCQkBaRHwbveDeS5FuXdgJ7yghVs
products-dashboards-tiles-tile-decorations--winner-with-group-title--dark:
- hash: v1.k794b7964.7849b79cba5174608f6adc5d93ee89b79e8dfe4212f68724a94ce214e2ed91a7.ASToewJSB0zxlpbxMYpaf5haa3paw1i1Yf8xFnb1Hyk
+ hash: v1.k794b7964.762601bb7a59d6ca5aaad78a8f470aebfb3907f4714d2d534bf7353a54525c6d.iojbhy_Og8NozcL_fVG45sNdo7zUx4nAPUZVa80uFyI
products-dashboards-tiles-tile-decorations--winner-with-group-title--light:
- hash: v1.k794b7964.249113d15d84b891c0e61d69b070f260a23246f91695331c924273ab2db6ecec.296aB-zbbSUQFYuxU2s87U3_CKQzf4hZgo-KOi62qtQ
+ hash: v1.k794b7964.7b86b194158108c532550809ba0e7708df82e3e8d4a16a6580dfe614465f196d.oZ1nrnPhkV45bWhAMbGzhCXOtaVPBzhX6dDs2k8x1Tw
products-data-catalog-metric-lineage--being-prepared--dark:
hash: v1.k794b7964.9b3dd08fa1426e0715daefdf347f20d3e251483c787dd3a9f3ad02fca88ae00b.N85-92zGL68U5fyXpoWHYbbTGLRVTOw42k7LxJ3HZHw
products-data-catalog-metric-lineage--being-prepared--light:
diff --git a/products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.scss b/frontend/src/lib/components/TileDecorations/TileDecorations.scss
similarity index 76%
rename from products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.scss
rename to frontend/src/lib/components/TileDecorations/TileDecorations.scss
index 7aba572cb3d1..0db542de2802 100644
--- a/products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.scss
+++ b/frontend/src/lib/components/TileDecorations/TileDecorations.scss
@@ -1,4 +1,4 @@
-.DashboardTileDecorations__group-title {
+.TileDecorations__group-title {
position: absolute;
top: 0;
left: 2rem;
@@ -19,7 +19,7 @@
transform: translateY(-50%);
}
-.DashboardTileDecorations__crown {
+.TileDecorations__crown {
position: absolute;
top: 0;
left: 0;
@@ -31,8 +31,8 @@
transform: translate(-35%, -50%) rotate(-20deg);
}
-// The window clips the hog, so it slides up from behind the tile's top edge on hover.
-.DashboardTileDecorations__hog {
+// The window clips the hog, so it slides up from behind the card's top edge when the card that holds it is hovered.
+.TileDecorations__hog {
position: absolute;
right: 1rem;
bottom: 100%;
@@ -43,7 +43,7 @@
pointer-events: none;
img {
- transition: transform var(--dashboard-hog-slide-duration) ease-out;
+ transition: transform var(--tile-hog-slide-duration, 200ms) ease-out;
transform: translateY(100%);
@media (prefers-reduced-motion: reduce) {
@@ -52,6 +52,6 @@
}
}
-.react-grid-item:hover .DashboardTileDecorations__hog img {
+:hover > .TileDecorations__hog img {
transform: translateY(0);
}
diff --git a/products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.stories.tsx b/frontend/src/lib/components/TileDecorations/TileDecorations.stories.tsx
similarity index 86%
rename from products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.stories.tsx
rename to frontend/src/lib/components/TileDecorations/TileDecorations.stories.tsx
index 96253ef24775..7d4bc5dd06da 100644
--- a/products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.stories.tsx
+++ b/frontend/src/lib/components/TileDecorations/TileDecorations.stories.tsx
@@ -8,10 +8,10 @@ import { urls } from 'scenes/urls'
import { mswDecorator } from '~/mocks/browser'
import { EMPTY_PAGINATED_RESPONSE } from '~/mocks/handlers'
-import type { DashboardTileBadge } from '~/types'
+import type { TileBadge } from '~/types'
interface TileOverrides {
- badge?: DashboardTileBadge
+ badge?: TileBadge
group_key?: string
}
@@ -71,6 +71,8 @@ const meta: Meta = {
viewMode: 'story',
mockDate: '2023-02-01',
pageUrl: urls.dashboard(DASHBOARD_ID),
+ // These stories check the tile decorations. The charts paint async and flake the snapshot.
+ testOptions: { skipCanvasDraw: true },
},
}
export default meta
@@ -88,7 +90,7 @@ export const WinnerWithGroupTitle: Story = {
],
parameters: {
testOptions: {
- waitForSelector: ['.DashboardTileDecorations__crown', '.DashboardTileDecorations__group-title'],
+ waitForSelector: ['.TileDecorations__crown', '.TileDecorations__group-title'],
},
},
}
@@ -96,18 +98,18 @@ export const WinnerWithGroupTitle: Story = {
export const CheekyHogOnHover: Story = {
decorators: [dashboardMocks(buildDashboard({ 2: { badge: 'cheeky-hog' } }))],
parameters: {
- testOptions: { waitForSelector: '.DashboardTileDecorations__hog' },
+ testOptions: { waitForSelector: '.TileDecorations__hog' },
},
play: async () => {
// A play function cannot move the real pointer, so no browser :hover applies. This copies the hover rule's effect.
const hoverStyle = document.createElement('style')
hoverStyle.textContent = `
- .react-grid-layout.dashboard-view-mode .react-grid-item:has(> .DashboardTileDecorations__hog) { content-visibility: visible; transition: none; }
- .react-grid-item .DashboardTileDecorations__hog img { transform: translateY(0); }
+ .react-grid-layout.dashboard-view-mode .react-grid-item:has(> .TileDecorations__hog) { content-visibility: visible; transition: none; }
+ .react-grid-item .TileDecorations__hog img { transform: translateY(0); }
`
document.head.append(hoverStyle)
await waitFor(() => {
- const hog = document.querySelector('.DashboardTileDecorations__hog img')
+ const hog = document.querySelector('.TileDecorations__hog img')
if (!hog || getComputedStyle(hog).transform !== HOG_SLID_UP_TRANSFORM) {
throw new Error('The hog has not finished sliding up')
}
diff --git a/products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.tsx b/frontend/src/lib/components/TileDecorations/TileDecorations.tsx
similarity index 64%
rename from products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.tsx
rename to frontend/src/lib/components/TileDecorations/TileDecorations.tsx
index 3fdcf568d2f0..432275ba89fc 100644
--- a/products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations.tsx
+++ b/frontend/src/lib/components/TileDecorations/TileDecorations.tsx
@@ -1,27 +1,27 @@
-import './DashboardTileDecorations.scss'
+import './TileDecorations.scss'
import * as hooligan from '@posthog/brand/hoggies/png/hooligan'
import { pngHoggie } from 'lib/brand/hoggies'
-import type { DashboardTileBadge } from '~/types'
+import type { TileBadge } from '~/types'
const CheekyHog = pngHoggie(hooligan)
-interface DashboardTileDecorationsProps {
- badge?: DashboardTileBadge | null
+interface TileDecorationsProps {
+ badge?: TileBadge | null
groupTitle?: string
}
-export function DashboardTileDecorations({ badge, groupTitle }: DashboardTileDecorationsProps): JSX.Element | null {
+export function TileDecorations({ badge, groupTitle }: TileDecorationsProps): JSX.Element | null {
if (!badge && !groupTitle) {
return null
}
return (
<>
- {groupTitle && <div className="DashboardTileDecorations__group-title">{groupTitle}</div>}
+ {groupTitle && <div className="TileDecorations__group-title">{groupTitle}</div>}
{badge === 'winner' && (
- <div className="DashboardTileDecorations__crown" role="img" aria-label="Winner">
+ <div className="TileDecorations__crown" role="img" aria-label="Winner">
{/* IconCrown is an outline with a cut-out, so this draws only its outer contour to get a solid crown. */}
<svg className="LemonIcon" viewBox="0 0 24 24" fill="currentColor" aria-hidden>
<path d="M12 3a.75.75 0 0 1 .628.34l3.86 5.903 5.384-3.14a.75.75 0 0 1 1.113.798l-2.399 11.7A1.75 1.75 0 0 1 18.872 20H5.128a1.75 1.75 0 0 1-1.714-1.399l-2.399-11.7a.75.75 0 0 1 1.113-.799l5.384 3.141 3.86-5.903A.75.75 0 0 1 12 3Z" />
@@ -29,7 +29,7 @@ export function DashboardTileDecorations({ badge, groupTitle }: DashboardTileDec
</div>
)}
{badge === 'cheeky-hog' && (
- <div className="DashboardTileDecorations__hog" aria-hidden>
+ <div className="TileDecorations__hog" aria-hidden>
<CheekyHog className="w-12 h-12" />
</div>
)}
diff --git a/frontend/src/scenes/dashboard/DashboardItems.scss b/frontend/src/scenes/dashboard/DashboardItems.scss
index da7adf152d2b..d005a38ea61c 100644
--- a/frontend/src/scenes/dashboard/DashboardItems.scss
+++ b/frontend/src/scenes/dashboard/DashboardItems.scss
@@ -12,7 +12,7 @@
}
.react-grid-layout {
- --dashboard-hog-slide-duration: 200ms; // Also drives the hog's slide in DashboardTileDecorations.scss
+ --tile-hog-slide-duration: 200ms; // Also drives the hog's slide in TileDecorations.scss
--dashboard-tile-transition:
transform 220ms ease-out, width 220ms ease-out, height 220ms ease-out, border-color 100ms ease;
@@ -33,12 +33,12 @@
}
/* Tile decorations draw outside the tile box, so the same paint clip would cut them off */
- &:has(> .DashboardTileDecorations__group-title, > .DashboardTileDecorations__crown) {
+ &:has(> .TileDecorations__group-title, > .TileDecorations__crown) {
content-visibility: visible;
}
/* The hog only shows while hovered. On leave, hold the lift for the hog's slide down (browsers without discrete content-visibility transitions hide it at once) */
- &:where(:has(> .DashboardTileDecorations__hog)) {
+ &:where(:has(> .TileDecorations__hog)) {
&:hover {
content-visibility: visible;
transition-delay: 0s;
@@ -47,7 +47,7 @@
@supports (transition-behavior: allow-discrete) {
transition:
var(--dashboard-tile-transition),
- content-visibility 0s linear var(--dashboard-hog-slide-duration) allow-discrete;
+ content-visibility 0s linear var(--tile-hog-slide-duration) allow-discrete;
}
@media (prefers-reduced-motion: reduce) {
diff --git a/frontend/src/scenes/dashboard/DashboardItems.tsx b/frontend/src/scenes/dashboard/DashboardItems.tsx
index 4278a5dff3d0..46b67f07dee9 100644
--- a/frontend/src/scenes/dashboard/DashboardItems.tsx
+++ b/frontend/src/scenes/dashboard/DashboardItems.tsx
@@ -14,6 +14,7 @@ import { getDashboardWidgetFetchDisplayError } from '@posthog/products-dashboard
import { ApiError } from 'lib/api'
import { InsightCard } from 'lib/components/Cards/InsightCard'
import { EditModeEdge, useResizeHandleScrollbarPassThrough } from 'lib/components/Cards/InsightCard/EditModeEdgeOverlay'
+import { TileDecorations } from 'lib/components/TileDecorations/TileDecorations'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { DashboardEventSource, eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { objectsEqual } from 'lib/utils/objects'
@@ -39,7 +40,6 @@ import { insightsModel } from '~/models/insightsModel'
import { DashboardLayoutSize, DashboardPlacement, DashboardType } from '~/types'
import { DashboardTextItem } from 'products/dashboards/frontend/components/DashboardTextItem/DashboardTextItem'
-import { DashboardTileDecorations } from 'products/dashboards/frontend/components/DashboardTileDecorations/DashboardTileDecorations'
import { getDashboardTileSpacingGap } from 'products/dashboards/frontend/dashboardCustomization'
import { getGroupTitlesByTileId, hasTileDecorations } from 'products/dashboards/frontend/dashboardTileGroups'
@@ -531,10 +531,7 @@ export function DashboardItems({ showCreateAnomalyAlertButton }: DashboardItemsP
})
const decorations = (
- <DashboardTileDecorations
- badge={tile.badge}
- groupTitle={groupTitlesByTileId[tile.id]}
- />
+ <TileDecorations badge={tile.badge} groupTitle={groupTitlesByTileId[tile.id]} />
)
const commonTileProps = {
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index cce7bc364fd8..ca46e11c3c63 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -2617,10 +2617,10 @@ export interface DashboardTile extends Tileable {
show_description?: boolean | null
transparent_background?: boolean | null
group_key?: string | null
- badge?: DashboardTileBadge | null
+ badge?: TileBadge | null
}
-export type DashboardTileBadge = 'winner' | 'cheeky-hog'
+export type TileBadge = 'winner' | 'cheeky-hog'
export type DashboardWidgetType = 'insight' | 'text' | 'button_tile' | 'widget'
diff --git a/products/mcp_analytics/frontend/leaderboardHome/LabScoreboard.tsx b/products/mcp_analytics/frontend/leaderboardHome/LabScoreboard.tsx
index cdc1a66d79e7..ed6c4fc76164 100644
--- a/products/mcp_analytics/frontend/leaderboardHome/LabScoreboard.tsx
+++ b/products/mcp_analytics/frontend/leaderboardHome/LabScoreboard.tsx
@@ -1,8 +1,9 @@
import { Card, CardContent, Skeleton, ToggleGroup, ToggleGroupItem } from '@posthog/quill-primitives'
+import { TileDecorations } from 'lib/components/TileDecorations/TileDecorations'
import { formatPercentage } from 'lib/utils/numbers'
-import { type LabShare, type ScoreboardMetric } from './leaderboardShares'
+import { leadingLabs, type LabShare, type ScoreboardMetric } from './leaderboardShares'
import { LoadErrorMessage } from './LoadErrorMessage'
const PODIUM_SIZE = 3
@@ -32,6 +33,8 @@ export function LabScoreboard({
return null
}
const caption = METRICS.find(({ value }) => value === metric)?.caption
+ const podium = shares.slice(0, PODIUM_SIZE)
+ const leaders = leadingLabs(podium)
return (
<div className="flex min-w-0 flex-col gap-3">
<div className="flex flex-wrap items-center justify-between gap-2">
@@ -66,16 +69,19 @@ export function LabScoreboard({
<LoadErrorMessage />
) : (
<div className="grid min-w-0 grid-cols-1 gap-4 @min-[40rem]/mcp-overview:grid-cols-3">
- {shares.slice(0, PODIUM_SIZE).map(({ lab, share }) => (
- <Card key={lab} size="sm" data-attr="mcp-leaderboard-lab-tile">
- <CardContent className="flex flex-col gap-1">
- <span className="text-sm text-secondary">{lab}</span>
- <span className="text-3xl font-semibold tabular-nums text-primary">
- {formatPercentage(share, { compact: true })}
- </span>
- <span className="text-xs text-secondary">{caption}</span>
- </CardContent>
- </Card>
+ {podium.map(({ lab, share }) => (
+ <div key={lab} className="relative">
+ <TileDecorations badge={leaders.includes(lab) ? 'winner' : null} />
+ <Card size="sm" className="h-full" data-attr="mcp-leaderboard-lab-tile">
+ <CardContent className="flex flex-col gap-1">
+ <span className="text-sm text-secondary">{lab}</span>
+ <span className="text-3xl font-semibold tabular-nums text-primary">
+ {formatPercentage(share, { compact: true })}
+ </span>
+ <span className="text-xs text-secondary">{caption}</span>
+ </CardContent>
+ </Card>
+ </div>
))}
</div>
)}
diff --git a/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.test.ts b/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.test.ts
index c7a2ecaaa28d..c6952095138e 100644
--- a/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.test.ts
+++ b/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.test.ts
@@ -1,6 +1,7 @@
import { type HarnessRow } from '../mcpDashboardOverviewLogic'
import {
type BucketedFacetRow,
+ type LabShare,
buildLabShares,
buildLabUserShares,
buildReliabilitySeries,
@@ -8,6 +9,7 @@ import {
labSqlExpression,
buildShareSeries,
hasKnownLabels,
+ leadingLabs,
modelLab,
toReliabilityRows,
topFacetRows,
@@ -16,6 +18,7 @@ import {
} from './leaderboardShares'
const row = (bucket: string, label: string, calls: number): BucketedFacetRow => ({ bucket, label, calls })
+const labShare = (lab: LabShare['lab'], share: number): LabShare => ({ lab, share })
const windowRow = (label: string, calls: number): WindowFacetRow => ({ label, calls, users: 1, errors: 0 })
describe('leaderboardShares', () => {
@@ -141,4 +144,17 @@ describe('leaderboardShares', () => {
const [result] = toReliabilityRows([['2026-01-01 00:00:00', 4, 1, p50, p95]])
expect([result.p50, result.p95]).toEqual(expected)
})
+
+ test.each([
+ ['one lab ahead', [labShare('Anthropic', 60), labShare('OpenAI', 30), labShare('xAI', 10)], ['Anthropic']],
+ [
+ 'a tie at the top',
+ [labShare('OpenAI', 40), labShare('Anthropic', 40), labShare('xAI', 20)],
+ ['OpenAI', 'Anthropic'],
+ ],
+ ['every share is zero', [labShare('Anthropic', 0), labShare('OpenAI', 0)], []],
+ ['no labs', [], []],
+ ])('leadingLabs: %s', (_name, shares, expected) => {
+ expect(leadingLabs(shares)).toEqual(expected)
+ })
})
diff --git a/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.ts b/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.ts
index 76da6099bffe..2ece77c3d2a1 100644
--- a/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.ts
+++ b/products/mcp_analytics/frontend/leaderboardHome/leaderboardShares.ts
@@ -139,6 +139,11 @@ export function buildLabUserShares(rows: LabUsersRow[], namedModelUsers: number)
.map(({ lab, users }) => ({ lab, share: namedModelUsers > 0 ? (users / namedModelUsers) * 100 : 0 }))
}
+export function leadingLabs(shares: LabShare[]): ModelLab[] {
+ const topShare = Math.max(0, ...shares.map(({ share }) => share))
+ return topShare > 0 ? shares.filter(({ share }) => share === topShare).map(({ lab }) => lab) : []
+}
+
const HARNESS_ERROR_RATE_LIMIT = 8
// The most used harnesses, so a harness with a handful of calls cannot top the error rate chart.