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

Pyroscope: Send start/end with profile types query #77523

Merged
merged 13 commits into from Jan 4, 2024
Merged

Conversation

bryanhuhta
Copy link
Contributor

What is this feature?

Adds start/end when making a ProfileTypes query from Pyroscope.

Why do we need this feature?

we need to pass start and end to Pyroscope when asking for profile types in order to accommodate users that may either have not sent profiling data in a long time or have a change what kind profiling data they send. This allows Pyroscope to query the correct time window and return accurate data. Prior to this change, Pyroscope would only return whatever information was in the head block of the ingesters.

Which issue(s) does this PR fix?:

Related: grafana/pyroscope#2230 (Fixes, but I don't want the auto close).

Special notes for your reviewer:

There is a PR to improve the ProfileTypes API and correctly handle start/end parameters. (grafana/pyroscope#2617). This PR needs to be merged first.

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

Copy link
Contributor

@joey-grafana joey-grafana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appears to work nicely 👍

Will need to fix some tests though!

@joey-grafana
Copy link
Contributor

@bryanhuhta you will still need to add backend code to send start/end to Pyroscope

@bryanhuhta
Copy link
Contributor Author

@bryanhuhta you will still need to add backend code to send start/end to Pyroscope

I added backend code in Pyroscope to handle start/end in grafana/pyroscope#2617. Is there any other backend code I might need to consider?

I got distracted with a few other things last week, I'm circling back now to get tests here fixed up and get this merged in.

@bryanhuhta bryanhuhta requested a review from a team as a code owner November 13, 2023 23:41
@bryanhuhta bryanhuhta requested review from tskarhed and L-M-K-B and removed request for a team November 13, 2023 23:41
@joey-grafana
Copy link
Contributor

Hey yeah so we are getting the start and end time on the frontend and it seems to be already done in Pyroscope API, but the start/end from the frontend is not actually being used in the Pyroscope API call i.e. the start/end needs to be added to the Pyroscope backend code.

@joey-grafana joey-grafana self-requested a review November 15, 2023 15:57
@bryanhuhta bryanhuhta requested a review from a team as a code owner November 29, 2023 22:50
@bryanhuhta bryanhuhta requested review from zserge, mildwonkey and nikimanoledaki and removed request for a team November 29, 2023 22:50
Copy link
Contributor

@joey-grafana joey-grafana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are requesting the ProfileTypes API a lot of times, is there a particular reason for this or is the UI re-rendering a lot?

Screenshot 2023-11-30 at 15 00 34

pkg/tsdb/grafana-pyroscope-datasource/instance.go Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@@ -65,6 +65,8 @@ export function VariableQueryEditor(props: QueryEditorProps<PyroscopeDataSource,
props.onChange({ ...props.query, profileTypeId: val });
}
}}
from={props.range?.from.valueOf() || Date.now().valueOf() - 1000 * 60 * 60 * 24}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we're going back a day here but providing start/end of 0 in <QueryEditor />?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy-pasted this from the <LabelRow /> part, assuming we wanted similar behavior.

<LabelRow
value={props.query.labelName}
datasource={props.datasource}
profileTypeId={props.query.profileTypeId}
onChange={(val) => {
if (props.query.type === 'labelValue') {
props.onChange({ ...props.query, labelName: val });
}
}}
from={props.range?.from.valueOf() || Date.now().valueOf() - 1000 * 60 * 60 * 24}
to={props.range?.to.valueOf() || Date.now().valueOf()}
/>

@bryanhuhta
Copy link
Contributor Author

We are requesting the ProfileTypes API a lot of times, is there a particular reason for this or is the UI re-rendering a lot?

This is a regression I caused. I suspect it's stemming from this function being changed to take start/end:

export function useProfileTypes(datasource: PyroscopeDataSource, start: number, end: number) {
const [profileTypes, setProfileTypes] = useState<ProfileTypeMessage[]>();
useEffect(() => {
(async () => {
const profileTypes = await datasource.getProfileTypes(start, end);
setProfileTypes(profileTypes);
})();
}, [datasource, start, end]);
return profileTypes;
}

These start/end values might be props changing by callers, causing the useEffect to be called several extra times.

const profileTypes = useProfileTypes(datasource, range?.from.valueOf() || 0, range?.to.valueOf() || 0);

const profileTypes = useProfileTypes(props.datasource, props.from, props.to);

Though, I'm not a React expert and that's only my current working theory. I do need to fix this before this PR is OK to merge.

Copy link
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale Issue with no recent activity label Dec 31, 2023
@aocenas
Copy link
Member

aocenas commented Jan 2, 2024

@bryanhuhta if the rerenders are because of the time range it's probably because if you use range now-1h <-> now for example then every time something rerenders the times also change and so you end up with this being called any time anything else changes. So I would say this should be memorized in a way where the time we use isn't millisecond precision as we probably don't need to refresh that on every millisecond anyway. So it could be truncated to most recent minute or something like that.

@github-actions github-actions bot removed the stale Issue with no recent activity label Jan 3, 2024
@bryanhuhta
Copy link
Contributor Author

After 97a55a0, this PR should be ready to go. We no longer make a series of queries as the time range changes slightly during page load.

Copy link
Contributor

@joey-grafana joey-grafana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing those remaining issues! LGTM 👍

@aocenas aocenas merged commit e64cb85 into main Jan 4, 2024
16 checks passed
@aocenas aocenas deleted the sg-profile-types branch January 4, 2024 15:35
@aocenas aocenas changed the title Pyroscope Data Source: Send start/end with profile types query Pyroscope: Send start/end with profile types query Jan 4, 2024
@summerwollin summerwollin modified the milestones: 10.3.x, 10.3.0 Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants