SD UI: Better total target count display when using keep_dropped_targets option

Fixes https://github.com/prometheus/prometheus/issues/16586

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2025-05-16 11:07:55 +02:00
parent 2690761582
commit 5f1c6226e2

View File

@ -39,6 +39,9 @@ type ScrapePool = {
targets: TargetLabels[]; targets: TargetLabels[];
active: number; active: number;
total: number; total: number;
// Can be different from "total" if the "keep_dropped_targets" setting is used
// to limit the number of dropped targets for which the server keeps details.
serverTotal: number;
}; };
type ScrapePools = { type ScrapePools = {
@ -62,11 +65,11 @@ const droppedTargetKVSearch = new KVSearch<DroppedTarget>({
const buildPoolsData = ( const buildPoolsData = (
poolNames: string[], poolNames: string[],
activeTargets: Target[], targetsData: TargetsResult,
droppedTargets: DroppedTarget[],
search: string, search: string,
stateFilter: (string | null)[] stateFilter: (string | null)[]
): ScrapePools => { ): ScrapePools => {
const { activeTargets, droppedTargets, droppedTargetCounts } = targetsData;
const pools: ScrapePools = {}; const pools: ScrapePools = {};
for (const pn of poolNames) { for (const pn of poolNames) {
@ -74,6 +77,7 @@ const buildPoolsData = (
targets: [], targets: [],
active: 0, active: 0,
total: 0, total: 0,
serverTotal: droppedTargetCounts[pn] || 0,
}; };
} }
@ -88,6 +92,7 @@ const buildPoolsData = (
pool.active++; pool.active++;
pool.total++; pool.total++;
pool.serverTotal++;
} }
const filteredActiveTargets = const filteredActiveTargets =
@ -160,9 +165,7 @@ const ScrapePoolList: FC<ScrapePoolListProp> = ({
// Based on the selected pool (if any), load the list of targets. // Based on the selected pool (if any), load the list of targets.
const { const {
data: { data: { data: targetsData },
data: { activeTargets, droppedTargets },
},
} = useSuspenseAPIQuery<TargetsResult>({ } = useSuspenseAPIQuery<TargetsResult>({
path: `/targets`, path: `/targets`,
params: { params: {
@ -180,19 +183,11 @@ const ScrapePoolList: FC<ScrapePoolListProp> = ({
() => () =>
buildPoolsData( buildPoolsData(
selectedPool ? [selectedPool] : poolNames, selectedPool ? [selectedPool] : poolNames,
activeTargets, targetsData,
droppedTargets,
debouncedSearch, debouncedSearch,
stateFilter stateFilter
), ),
[ [selectedPool, poolNames, targetsData, debouncedSearch, stateFilter]
selectedPool,
poolNames,
activeTargets,
droppedTargets,
debouncedSearch,
stateFilter,
]
); );
const allPoolNames = Object.keys(allPools); const allPoolNames = Object.keys(allPools);
const shownPoolNames = showEmptyPools const shownPoolNames = showEmptyPools
@ -250,22 +245,23 @@ const ScrapePoolList: FC<ScrapePoolListProp> = ({
<Text>{poolName}</Text> <Text>{poolName}</Text>
<Group gap="xs"> <Group gap="xs">
<Text c="gray.6"> <Text c="gray.6">
{pool.active} / {pool.total} {pool.active} / {pool.serverTotal}
</Text> </Text>
<RingProgress <RingProgress
size={25} size={25}
thickness={5} thickness={5}
sections={ sections={
pool.total === 0 pool.serverTotal === 0
? [] ? []
: [ : [
{ {
value: (pool.active / pool.total) * 100, value: (pool.active / pool.serverTotal) * 100,
color: "green.4", color: "green.4",
}, },
{ {
value: value:
((pool.total - pool.active) / pool.total) * ((pool.serverTotal - pool.active) /
pool.serverTotal) *
100, 100,
color: "blue.6", color: "blue.6",
}, },
@ -276,6 +272,19 @@ const ScrapePoolList: FC<ScrapePoolListProp> = ({
</Group> </Group>
</Accordion.Control> </Accordion.Control>
<Accordion.Panel> <Accordion.Panel>
{pool.total !== pool.serverTotal && (
<Alert
title="Only showing partial dropped targets"
icon={<IconInfoCircle />}
color="yellow"
mb="sm"
>
{pool.serverTotal - pool.total} further dropped targets are
not shown here because the server only kept details on a
maximum of {pool.total - pool.active} dropped targets (
<code>keep_dropped_targets</code> configuration setting).
</Alert>
)}
{pool.total === 0 ? ( {pool.total === 0 ? (
<Alert title="No targets" icon={<IconInfoCircle />}> <Alert title="No targets" icon={<IconInfoCircle />}>
No targets in this scrape pool. No targets in this scrape pool.