Skip to content

Commit 9354001

Browse files
authored
feat(starfish): Add releases to db module (#48782)
- This adds releases to the DB module - This changes the first and last seen to use the TimeSince component - Changes first seen to be more technically correct
1 parent d14a0f9 commit 9354001

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

static/app/views/starfish/modules/databaseModule/panel/index.tsx

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ import Badge from 'sentry/components/badge';
88
import {Button} from 'sentry/components/button';
99
import ButtonBar from 'sentry/components/buttonBar';
1010
import MarkLine from 'sentry/components/charts/components/markLine';
11+
import TimeSince from 'sentry/components/timeSince';
12+
import Version from 'sentry/components/version';
13+
import VersionHoverCard from 'sentry/components/versionHoverCard';
1114
import {IconChevron} from 'sentry/icons';
1215
import {t} from 'sentry/locale';
1316
import {space} from 'sentry/styles/space';
1417
import {Series, SeriesDataUnit} from 'sentry/types/echarts';
18+
import useOrganization from 'sentry/utils/useOrganization';
1519
import usePageFilters from 'sentry/utils/usePageFilters';
1620
import Chart from 'sentry/views/starfish/components/chart';
1721
import Detail from 'sentry/views/starfish/components/detailPanel';
@@ -21,6 +25,8 @@ import QueryTransactionTable, {
2125
} from 'sentry/views/starfish/modules/databaseModule/panel/queryTransactionTable';
2226
import SimilarQueryView from 'sentry/views/starfish/modules/databaseModule/panel/similarQueryView';
2327
import {
28+
useQueryExampleTransaction,
29+
useQueryGetEvent,
2430
useQueryPanelEventCount,
2531
useQueryPanelGraph,
2632
useQueryPanelSparklines,
@@ -97,6 +103,7 @@ function QueryDetailBody({
97103
}: DbQueryDetailProps) {
98104
const theme = useTheme();
99105
const pageFilter = usePageFilters();
106+
const organization = useOrganization();
100107
const {startTime, endTime} = getDateFilters(pageFilter);
101108
const isNew = row.newish === 1;
102109
const isOld = row.retired === 1;
@@ -132,12 +139,25 @@ function QueryDetailBody({
132139
const {isLoading: isEventCountLoading, data: eventCountData} =
133140
useQueryPanelEventCount(row);
134141

142+
const {isLoading: isExampleLoading, data: exampleTransaction} =
143+
useQueryExampleTransaction(row);
144+
145+
const {isLoading: isFirstExampleLoading, data: firstSeenExample} = useQueryGetEvent(
146+
exampleTransaction?.[0]?.first
147+
);
148+
const {isLoading: isLastExampleLoading, data: lastSeenExample} = useQueryGetEvent(
149+
exampleTransaction?.[0]?.latest
150+
);
151+
135152
const isDataLoading =
136153
isLoading ||
137154
isTableLoading ||
138155
isEventCountLoading ||
139156
isRowLoading ||
140157
isP75GraphLoading ||
158+
isExampleLoading ||
159+
isFirstExampleLoading ||
160+
isLastExampleLoading ||
141161
isSparklinesLoading;
142162

143163
const eventCountMap = keyBy(eventCountData, 'transaction');
@@ -225,14 +245,48 @@ function QueryDetailBody({
225245
{t('First Seen')}
226246
{row.newish === 1 && <Badge type="new" text="new" />}
227247
</SubHeader>
228-
<SubSubHeader>{row.firstSeen}</SubSubHeader>
248+
{Math.abs(moment(row.firstSeen).diff(startTime, 'minutes')) < 360 ? (
249+
<SubSubHeader>
250+
More than <TimeSince date={row.firstSeen} />{' '}
251+
</SubSubHeader>
252+
) : (
253+
<span>
254+
<SubSubHeader>
255+
<TimeSince date={row.firstSeen} />{' '}
256+
</SubSubHeader>
257+
{firstSeenExample?.release && (
258+
<VersionHoverCard
259+
organization={organization}
260+
projectSlug="sentry"
261+
releaseVersion={firstSeenExample.release.version}
262+
showUnderline
263+
underlineColor="linkUnderline"
264+
>
265+
<Version version={String(firstSeenExample.release.version)} truncate />
266+
</VersionHoverCard>
267+
)}
268+
</span>
269+
)}
229270
</FlexRowItem>
230271
<FlexRowItem>
231272
<SubHeader>
232273
{t('Last Seen')}
233274
{row.retired === 1 && <Badge type="warning" text="old" />}
234275
</SubHeader>
235-
<SubSubHeader>{row.lastSeen}</SubSubHeader>
276+
<SubSubHeader>
277+
<TimeSince date={row.lastSeen} />
278+
</SubSubHeader>
279+
{lastSeenExample?.release && (
280+
<VersionHoverCard
281+
organization={organization}
282+
projectSlug="sentry"
283+
releaseVersion={lastSeenExample.release.version}
284+
showUnderline
285+
underlineColor="linkUnderline"
286+
>
287+
<Version version={String(lastSeenExample.release.version)} truncate />
288+
</VersionHoverCard>
289+
)}
236290
</FlexRowItem>
237291
<FlexRowItem>
238292
<SubHeader>{t('Total Time')}</SubHeader>

static/app/views/starfish/modules/databaseModule/queries.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,32 @@ export const useQueryPanelTable = (
354354
});
355355
};
356356

357+
export const useQueryExampleTransaction = (
358+
row: DataRow
359+
): DefinedUseQueryResult<{first: string; latest: string}[]> => {
360+
const pageFilter = usePageFilters();
361+
const {startTime, endTime} = getDateFilters(pageFilter);
362+
const dateFilters = getDateQueryFilter(startTime, endTime);
363+
const query = `
364+
SELECT
365+
minIf(transaction_id, equals(timestamp, '${row.lastSeen}')) as latest,
366+
minIf(transaction_id, equals(timestamp, '${row.firstSeen}')) as first
367+
FROM spans_experimental_starfish
368+
WHERE
369+
${DEFAULT_WHERE}
370+
${dateFilters} AND
371+
group_id = '${row.group_id}'
372+
HAVING latest > 0 and first > 0
373+
LIMIT 10
374+
`;
375+
return useQuery({
376+
queryKey: ['getExampleTransaction', row.group_id],
377+
queryFn: () => fetch(`${HOST}/?query=${query}`).then(res => res.json()),
378+
retry: true,
379+
initialData: [],
380+
});
381+
};
382+
357383
export const useQueryPanelSparklines = (
358384
row: DataRow,
359385
sortKey: string | undefined,

0 commit comments

Comments
 (0)