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

Added script switch button to the query panel. #41

Merged
merged 5 commits into from
Jun 3, 2022

Conversation

TarasPriadka
Copy link
Contributor

Added a dropdown menu with some predefined scripts to choose from.

Signed-off-by: Taras Priadka tpriadka@pixielabs.ai

Signed-off-by: Taras Priadka <tpriadka@pixielabs.ai>
};

export const options = [
{ label: 'scratch-pad' },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would Custom Query be more descriptive than Scratch Pad?

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 was going with the same name as on Pixie UI. Can change to Custom Query if that is more descriptive.

Copy link

Choose a reason for hiding this comment

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

Let's make it Custom Query, I think that is more clear to the Grafana audience

@TarasPriadka
Copy link
Contributor Author

TarasPriadka commented Jun 1, 2022

What is the best way to keep track of predefined scripts? Keeping all of them in the tsx file doesn't seem right. Should I configure yarn so that it copies example scripts into dist on build? @vihangm @nserrino

Signed-off-by: Taras Priadka <tpriadka@pixielabs.ai>
@nserrino
Copy link

nserrino commented Jun 2, 2022

What is the best way to keep track of predefined scripts? Keeping all of them in the tsx file doesn't seem right. Should I configure yarn so that it copies example scripts into dist on build? @vihangm @nserrino

I think we should have a directory, containing a JSON file for each predefined script

px.display(per_ns_df['time_', 'service', 'request_throughput'])
`,

'http-data-filtered': String.raw`# Copyright 2018- The Pixie Authors.
Copy link

Choose a reason for hiding this comment

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

We can remove the copyright in these

};

export const options = [
{ label: 'scratch-pad' },
Copy link

Choose a reason for hiding this comment

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

Let's make it Custom Query, I think that is more clear to the Grafana audience

'scratch-pad': '',
example: String.raw`
# Import Pixie's module for querying data.
import px
Copy link

Choose a reason for hiding this comment

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

Let's put some links to docs.px.dev in the comments at the top of this script, perhaps links to the Grafana tutorial and also how to write your own PxL script

px.display(per_ns_df['time_', 'service', 'request_throughput'])
`,

'http-data-filtered': String.raw`# Copyright 2018- The Pixie Authors.
Copy link

Choose a reason for hiding this comment

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

Let's have the title of this one be

Raw HTTP Events (Long Format)

So it's clear that it shouldn't be used with a timeseries and more clear about what the datasource is

#df = df[px.contains(df.pod, 'catalogue')]
#df = df[df.req_path == '/healthz']

# Avoid conversion to long format
Copy link

Choose a reason for hiding this comment

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

I know this isn't your comment, but I believe this is actually avoiding the conversion to wide format, not the other way around: https://grafana.com/docs/grafana/latest/developers/plugins/data-frames/

# Output the DataFrame
px.display(df)
`,
'http-errors-per-service': String.raw`
Copy link

Choose a reason for hiding this comment

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

Let's rename this to

HTTP Error Rate by Service (Wide Format)

Signed-off-by: Taras Priadka <tpriadka@pixielabs.ai>
@TarasPriadka TarasPriadka requested review from nserrino and htroisi June 3, 2022 18:05
Signed-off-by: Taras Priadka <tpriadka@pixielabs.ai>
@TarasPriadka TarasPriadka mentioned this pull request Jun 3, 2022
@@ -33,12 +34,26 @@ export class QueryEditor extends PureComponent<Props> {
onRunQuery();
}

onSelect(option: SelectableValue<number>) {
Copy link
Member

Choose a reason for hiding this comment

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

Kartik is working on adding some more dropdowns (for example, for column selection, groupbys). Let's name this onSelect something more specific to avoid confusion. Something like: onScriptSelect.

export const options = scriptsRaw.map((script: Script) => {
return {
label: script.name,
description: script.description,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a nice, small follow-up PR is to figure out how to incorporate/show this description when you're looking through scripts in the dropdown. This is just a UI improvement thing though, so just a nice-to-have (and shouldn't be done in this PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already done through Grafana UI component. Additionally it can display images near the selections, but I don't think we need that.

);

// Construct options list which is injested by Select component in
export const options = scriptsRaw.map((script: Script) => {
Copy link
Member

Choose a reason for hiding this comment

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

options is pretty vague here, so when it gets imported into query_editor.tsx, it can be unclear what options means, especially if there are potentially other dropdowns. Let's just rename this to scriptOptions.

const scriptsRaw: Script[] = [customQuery, exampleQuery, httpDataFiltered, httpErrorsPerService];

// Make a map for easier access of scripts
export const scripts = new Map(
Copy link
Member

Choose a reason for hiding this comment

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

As a general rule (only writing it once since it's the same thing elsewhere):

Even though TypeScript can often figure out the type of something for you, it's still a good idea to specify it explicitly when:

  • The symbol is exported and isn't a primitive or otherwise trivial type
  • The type may not be instantly obvious to the reader even if TypeScript inferred it correctly (this is clearly a Map, but I have to read surrounding code to realize it's actually a Map<string, Script> and not a Map<string, string>)
  • The contents of the object might be complex, and specifying the type will let the compiler tell you if you didn't fill it out properly.

In this specific case, export const scripts = new Map<string, Script>(...) would make it nice and clear.

export const scripts = new Map(
scriptsRaw.map((script) => {
return [script.name, script];
})
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this is a good candidate for shorthand syntax.

scriptsRaw.map((script) => [script.name, script]);


// Construct options list which is injested by Select component in
export const options = scriptsRaw.map((script: Script) => {
return {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: shorthand syntax also works for objects if you wrap them in parentheses, like this:

export const scriptOptions: Array<{ label: string, description: string }> = scriptsRaw.map((script) => ({
  label: script.name,
  description: script.description,
}));

Signed-off-by: Taras Priadka <tpriadka@pixielabs.ai>
@aimichelle aimichelle merged commit 736a760 into pixie-io:main Jun 3, 2022
@TarasPriadka TarasPriadka deleted the select-script branch June 3, 2022 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants