Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

area/ui: add a new queryparam selectedSeries to query for cpu strips and flamechart #5544

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const MetricsContextMenu = ({
id={label.name}
onClick={() => {
onAddLabelMatcher({
key: transformUtilizationLabels(label.name, utilizationMetrics),
key: label.name,
value: label.value,
});
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {AnimatePresence, motion} from 'framer-motion';
import throttle from 'lodash.throttle';
import {useContextMenu} from 'react-contexify';

import {DateTimeRange, MetricsGraphSkeleton, useParcaContext} from '@parca/components';
import {DateTimeRange, MetricsGraphSkeleton, useParcaContext, useURLState} from '@parca/components';
import {Matcher} from '@parca/parser';
import {formatDate, formatForTimespan, getPrecision, valueFormatter} from '@parca/utilities';

Expand All @@ -36,7 +36,6 @@ interface CommonProps {
labels: {key: string; value: string} | Array<{key: string; value: string}>
) => void;
setTimeRange: (range: DateTimeRange) => void;
selectedSeriesMatchers?: Matcher[];
}

type RawUtilizationMetricsProps = CommonProps & {
Expand Down Expand Up @@ -91,7 +90,6 @@ const RawUtilizationMetrics = ({
width,
height,
margin,
selectedSeriesMatchers,
}: RawUtilizationMetricsProps): JSX.Element => {
const {timezone} = useParcaContext();
const graph = useRef(null);
Expand All @@ -101,6 +99,15 @@ const RawUtilizationMetrics = ({
const [pos, setPos] = useState([0, 0]);
const [isContextMenuOpen, setIsContextMenuOpen] = useState<boolean>(false);
const idForContextMenu = useId();
const [selectedSeries, setSelectedSeries] = useURLState<string>('selectedSeries');

const parsedSelectedSeries: Matcher[] = useMemo(() => {
if (selectedSeries === undefined) {
return [];
}

return JSON.parse(decodeURIComponent(selectedSeries));
}, [selectedSeries]);

const lineStroke = '1px';
const lineStrokeHover = '2px';
Expand Down Expand Up @@ -446,15 +453,10 @@ const RawUtilizationMetrics = ({
<g className="lines fill-transparent">
{series.map((s, i) => {
let isSelected = false;
if (selectedSeriesMatchers != null && selectedSeriesMatchers.length > 0) {
isSelected = selectedSeriesMatchers.every(m => {
if (parsedSelectedSeries != null && parsedSelectedSeries.length > 0) {
isSelected = parsedSelectedSeries.every(m => {
for (let i = 0; i < s.metric.length; i++) {
if (
s.metric[i].name
.replace('attributes_resource.', '')
.replace('attributes.', '') === m.key &&
s.metric[i].value === m.value
) {
if (s.metric[i].name === m.key && s.metric[i].value === m.value) {
return true;
}
}
Expand All @@ -479,13 +481,13 @@ const RawUtilizationMetrics = ({
yScale={yScale}
onClick={() => {
if (highlighted != null) {
addLabelMatcher(
highlighted.labels
.filter(l => l.name.startsWith('attributes_resource.'))
.map(l => ({
key: l.name.replace('attributes_resource.', ''),
setSelectedSeries(
JSON.stringify(
highlighted.labels.map(l => ({
key: l.name,
value: l.value,
}))
)
);
}
}}
Expand All @@ -506,7 +508,6 @@ const UtilizationMetrics = ({
addLabelMatcher,
setTimeRange,
utilizationMetricsLoading,
selectedSeriesMatchers,
}: Props): JSX.Element => {
const {isDarkMode} = useParcaContext();
const {width, height, margin, heightStyle} = useMetricsGraphDimensions(false, true);
Expand All @@ -530,7 +531,6 @@ const UtilizationMetrics = ({
width={width}
height={height}
margin={margin}
selectedSeriesMatchers={selectedSeriesMatchers}
/>
)}
</motion.div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {useMemo} from 'react';

import cx from 'classnames';

import {Label, QueryServiceClient} from '@parca/client';
Expand Down Expand Up @@ -135,11 +133,6 @@ export function MetricsGraphSection({
selectProfile(new MergedProfileSelection(mergeFrom, mergeTo, query));
};

const selectedMatchers = useMemo(
() => Query.parse(querySelection.expression).matchers,
[querySelection.expression]
);

return (
<div className={cx('relative', {'py-4': !showMetricsGraph})}>
{setDisplayHideMetricsGraphButton != null ? (
Expand Down Expand Up @@ -167,7 +160,6 @@ export function MetricsGraphSection({
addLabelMatcher={addLabelMatcher}
setTimeRange={handleTimeRangeChange}
utilizationMetricsLoading={utilizationMetricsLoading}
selectedSeriesMatchers={selectedMatchers}
/>
) : (
<>
Expand Down
Loading