-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Prometheus: Add capability to filter label names by metric in template variable editor #70452
Conversation
… are failing in drone, but not locally
public/app/plugins/datasource/prometheus/components/VariableQueryEditor.tsx
Outdated
Show resolved
Hide resolved
@@ -164,15 +171,21 @@ export const PromVariableQueryEditor = ({ onChange, query, datasource }: Props) | |||
} | |||
}; | |||
|
|||
const onLabelNamesMatchChange = (regex: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we want to only call onchange with the blur event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue so, running a query on change only works on prometheus instances where you don't mind running extra or partial queries. Onblur gives you time to write whatever regex/metric names you want without pinging the server before you're ready.
/** | ||
* Call onchange for metric change if metrics names (regex) query type | ||
* Debounce this because to not call the API for every keystroke. | ||
*/ | ||
const onMetricChange = debounce((value: string) => { | ||
const onMetricChange = (value: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the debounce not working correctly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't debouncing, it would just delay each execution 300ms, so three keystrokes would cause 3 queries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
@@ -967,7 +967,7 @@ export class PrometheusDatasource | |||
// this is used to get label keys, a.k.a label names | |||
// it is used in metric_find_query.ts | |||
// and in Tempo here grafana/public/app/plugins/datasource/tempo/QueryEditor/ServiceGraphSection.tsx | |||
async getTagKeys(options?: any) { | |||
async getTagKeys(options?: { series: string[] }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏆 🎉
public/app/plugins/datasource/prometheus/components/VariableQueryEditor.test.tsx
Outdated
Show resolved
Hide resolved
…eryEditor.test.tsx Co-authored-by: Brendan O'Handley <brendan.ohandley@grafana.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…e variable editor (#70452) * Adds new text input in prometheus template variable UI that allows label names function to filter values by metric. Co-authored-by: Brendan O'Handley <brendan.ohandley@grafana.com>
…e variable editor (#70452) * Adds new text input in prometheus template variable UI that allows label names function to filter values by metric. Co-authored-by: Brendan O'Handley <brendan.ohandley@grafana.com>
What is this feature?
Currently if you want to use the label names in the variable editor, you have to use ALL of them. Which can be a tad much for many use-cases:
![image](https://private-user-images.githubusercontent.com/109082771/248000707-2d137ab7-1e99-4224-a009-522762a9773d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxODkwMjIsIm5iZiI6MTcyMjE4ODcyMiwicGF0aCI6Ii8xMDkwODI3NzEvMjQ4MDAwNzA3LTJkMTM3YWI3LTFlOTktNDIyNC1hMDA5LTUyMjc2MmE5NzczZC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzI4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyOFQxNzQ1MjJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zN2UwYmRmOGM5ZDNlYTliYWUwNWFiODRhNGFlYTlmYmZjMzFhYTYwN2NjZTBjZmUwOGZiM2ZmMTM4YTIyOTU4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.1iD54XgAmyjFw75d_HmW5Hla7SdbS4bQIHZP0NmF7_M)
The "label names" function in Grafana is an interface for the prometheus /api/v1/labels endpoint. The new input field introduced in this PR provides a way to optionally provide a value for the
match[]
parameter.Why do we need this feature?
To help Prometheus users build templated dashboards. People can have many thousands of labels, at which point dumping them all into a variable is not great UX. This allows folks to limit the labels returned to whatever metric names match the provided regex. Example: If I want the labels from
node_arp_entries
, andprometheus_build_info
, I can write a query ofnode_arp_entries|prometheus_build_info
which will return all the labels from those metrics.Who is this feature for?
Prometheus users with lots of labels.
Which issue(s) does this PR fix?:
Fixes #70451
Special notes for your reviewer:
Also I wanted it to work with partial strings, for example
node_arp_entr
would be sent as.*node_arp_entr.*
, if users want it to match multiple things likenode_arp_|prometheus_build_
they'll need to build a proper regexnode_arp_.*|prometheus_build_.*
, which will output.*node_arp_.*|prometheus_build_.*.*
, which looks weird but still should return the proper results, except this might require folks to assert the start and end of the strings explicitly (^node_arp_.*|^prometheus_build_entries$
) to prevent any metrics that containnode_arp_
but don't start with it.Edit: Another UI I can imagine is we provide repeatable inputs, each with another match[] parameter.
Please check that: