Skip to content

Commit

Permalink
feat(laravel-insights): Show count in caches (#86867)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurKnaus authored Mar 12, 2025
1 parent 27e8635 commit 7cd19d7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
52 changes: 31 additions & 21 deletions static/app/views/insights/pages/backend/laravel/cachesWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Link from 'sentry/components/links/link';
import {getChartColorPalette} from 'sentry/constants/chartPalette';
import {IconExpand} from 'sentry/icons';
import {t} from 'sentry/locale';
import {formatAbbreviatedNumber} from 'sentry/utils/formatters';
import {useApiQuery} from 'sentry/utils/queryClient';
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
import useOrganization from 'sentry/utils/useOrganization';
Expand All @@ -31,6 +32,7 @@ export function CachesWidget({query}: {query?: string}) {
const cachesRequest = useApiQuery<{
data: Array<{
'cache_miss_rate()': number;
'count()': number;
'project.id': string;
transaction: string;
}>;
Expand All @@ -41,7 +43,7 @@ export function CachesWidget({query}: {query?: string}) {
query: {
...pageFilterChartParams,
dataset: 'spansMetrics',
field: ['transaction', 'project.id', 'cache_miss_rate()'],
field: ['transaction', 'project.id', 'cache_miss_rate()', 'count()'],
query: `span.op:[cache.get_item,cache.get] ${query}`,
sort: '-cache_miss_rate()',
per_page: 4,
Expand Down Expand Up @@ -117,26 +119,34 @@ export function CachesWidget({query}: {query?: string}) {
);

const footer = hasData && (
<WidgetFooterTable>
{cachesRequest.data?.data.map((item, index) => (
<Fragment key={item.transaction}>
<div>
<SeriesColorIndicator
style={{
backgroundColor: colorPalette[index],
}}
/>
</div>
<div>
<Link
to={`/insights/backend/caches?project=${item['project.id']}&transaction=${item.transaction}`}
>
{item.transaction}
</Link>
</div>
<span>{(item['cache_miss_rate()'] * 100).toFixed(2)}%</span>
</Fragment>
))}
<WidgetFooterTable columns={4}>
{cachesRequest.data?.data.map((item, index) => {
const count = item['count()'];
const cacheMissRate = item['cache_miss_rate()'];
const missedCount = Math.floor(count * cacheMissRate);
return (
<Fragment key={item.transaction}>
<div>
<SeriesColorIndicator
style={{
backgroundColor: colorPalette[index],
}}
/>
</div>
<div>
<Link
to={`/insights/backend/caches?project=${item['project.id']}&transaction=${item.transaction}`}
>
{item.transaction}
</Link>
</div>
<span>
{formatAbbreviatedNumber(missedCount)} / {formatAbbreviatedNumber(count)}
</span>
<span>{(cacheMissRate * 100).toFixed(2)}%</span>
</Fragment>
);
})}
</WidgetFooterTable>
);

Expand Down
19 changes: 13 additions & 6 deletions static/app/views/insights/pages/backend/laravel/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,38 @@ export const ModalTableWrapper = styled(Panel)`
margin-top: ${space(2)};
`;

export const WidgetFooterTable = styled('div')`
const getColumns = (props: {columns?: number}) => {
return props.columns || 3;
};

export const WidgetFooterTable = styled('div')<{columns?: number}>`
display: grid;
grid-template-columns: max-content 1fr max-content;
grid-template-columns: max-content 1fr repeat(${p => getColumns(p) - 2}, max-content);
font-size: ${p => p.theme.fontSizeSmall};
& > * {
padding: ${space(1)} ${space(0.5)};
text-align: right;
}
& > *:nth-child(3n + 1) {
& > *:nth-child(${p => getColumns(p)}n + 1) {
position: relative;
text-align: left;
}
& > *:nth-child(3n + 2) {
& > *:nth-child(${p => getColumns(p)}n + 2) {
${p => p.theme.overflowEllipsis};
padding-left: ${space(1.5)};
min-width: 0px;
text-align: left;
}
& > *:nth-child(3n) {
& > *:nth-child(${p => getColumns(p)}n) {
padding-right: ${space(2)};
text-align: right;
}
& > *:not(:nth-last-child(-n + 3)) {
& > *:not(:nth-last-child(-n + ${p => getColumns(p)})) {
border-bottom: 1px solid ${p => p.theme.border};
}
`;
Expand Down

0 comments on commit 7cd19d7

Please sign in to comment.