2022-04-22 14:33:13 +01:00
import { css } from '@emotion/css' ;
2022-10-25 13:05:21 -05:00
import debounce from 'debounce-promise' ;
2022-02-07 15:18:17 +01:00
import React , { useCallback , useState } from 'react' ;
2022-04-22 14:33:13 +01:00
import Highlighter from 'react-highlight-words' ;
2023-04-12 17:22:35 +02:00
import { GrafanaTheme2 , SelectableValue , toOption } from '@grafana/data' ;
2022-10-24 17:12:36 +02:00
import { EditorField , EditorFieldGroup } from '@grafana/experimental' ;
2023-05-01 17:29:35 -04:00
import { config } from '@grafana/runtime' ;
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
import { AsyncSelect , Button , FormatOptionLabelMeta , Icon , useStyles2 } from '@grafana/ui' ;
2023-05-01 17:29:35 -04:00
import { SelectMenuOptions } from '@grafana/ui/src/components/Select/SelectMenu' ;
2022-04-22 14:33:13 +01:00
2022-10-25 13:05:21 -05:00
import { PrometheusDatasource } from '../../datasource' ;
2022-11-09 13:54:51 -06:00
import { regexifyLabelValuesQueryString } from '../shared/parsingUtils' ;
2022-10-25 13:05:21 -05:00
import { QueryBuilderLabelFilter } from '../shared/types' ;
2022-04-22 14:33:13 +01:00
import { PromVisualQuery } from '../types' ;
2022-02-07 15:18:17 +01:00
2023-05-01 17:29:35 -04:00
import { MetricsModal } from './metrics-modal/MetricsModal' ;
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
import { tracking } from './metrics-modal/state/helpers' ;
2023-05-01 17:29:35 -04:00
2022-02-07 15:18:17 +01:00
// We are matching words split with space
const splitSeparator = ' ' ;
2022-01-31 07:57:14 +01:00
export interface Props {
2023-04-12 17:22:35 +02:00
metricLookupDisabled : boolean ;
2022-01-31 07:57:14 +01:00
query : PromVisualQuery ;
onChange : ( query : PromVisualQuery ) = > void ;
2022-02-03 11:40:19 +01:00
onGetMetrics : ( ) = > Promise < SelectableValue [ ] > ;
2022-10-25 13:05:21 -05:00
datasource : PrometheusDatasource ;
labelsFilters : QueryBuilderLabelFilter [ ] ;
2022-01-31 07:57:14 +01:00
}
2022-11-08 08:37:11 -06:00
export const PROMETHEUS_QUERY_BUILDER_MAX_RESULTS = 1000 ;
2022-10-25 13:05:21 -05:00
2023-05-01 17:29:35 -04:00
const prometheusMetricEncyclopedia = config . featureToggles . prometheusMetricEncyclopedia ;
2023-04-12 17:22:35 +02:00
export function MetricSelect ( {
datasource ,
query ,
onChange ,
onGetMetrics ,
labelsFilters ,
metricLookupDisabled ,
} : Props ) {
2022-02-07 15:18:17 +01:00
const styles = useStyles2 ( getStyles ) ;
2022-01-31 07:57:14 +01:00
const [ state , setState ] = useState < {
metrics? : Array < SelectableValue < any > > ;
isLoading? : boolean ;
2023-05-01 17:29:35 -04:00
metricsModalOpen? : boolean ;
initialMetrics? : string [ ] ;
2022-01-31 07:57:14 +01:00
} > ( { } ) ;
2022-02-07 15:18:17 +01:00
const customFilterOption = useCallback ( ( option : SelectableValue < any > , searchQuery : string ) = > {
const label = option . label ? ? option . value ;
if ( ! label ) {
return false ;
}
2022-04-28 12:25:51 +02:00
// custom value is not a string label but a react node
if ( ! label . toLowerCase ) {
return true ;
}
2022-02-07 15:18:17 +01:00
const searchWords = searchQuery . split ( splitSeparator ) ;
return searchWords . reduce ( ( acc , cur ) = > acc && label . toLowerCase ( ) . includes ( cur . toLowerCase ( ) ) , true ) ;
} , [ ] ) ;
const formatOptionLabel = useCallback (
( option : SelectableValue < any > , meta : FormatOptionLabelMeta < any > ) = > {
// For newly created custom value we don't want to add highlight
if ( option [ '__isNew__' ] ) {
return option . label ;
}
return (
< Highlighter
searchWords = { meta . inputValue . split ( splitSeparator ) }
textToHighlight = { option . label ? ? '' }
2022-02-16 09:40:04 +01:00
highlightClassName = { styles . highlight }
2022-02-07 15:18:17 +01:00
/ >
) ;
} ,
2022-02-16 09:40:04 +01:00
[ styles . highlight ]
2022-02-07 15:18:17 +01:00
) ;
2022-10-25 13:05:21 -05:00
/ * *
* Reformat the query string and label filters to return all valid results for current query editor state
* /
const formatKeyValueStringsForLabelValuesQuery = (
query : string ,
labelsFilters? : QueryBuilderLabelFilter [ ]
) : string = > {
const queryString = regexifyLabelValuesQueryString ( query ) ;
2023-05-08 11:33:30 -05:00
return formatPrometheusLabelFiltersToString ( queryString , labelsFilters ) ;
2022-10-25 13:05:21 -05:00
} ;
/ * *
* Gets label_values response from prometheus API for current autocomplete query string and any existing labels filters
* /
const getMetricLabels = ( query : string ) = > {
// Since some customers can have millions of metrics, whenever the user changes the autocomplete text we want to call the backend and request all metrics that match the current query string
const results = datasource . metricFindQuery ( formatKeyValueStringsForLabelValuesQuery ( query , labelsFilters ) ) ;
return results . then ( ( results ) = > {
2022-11-08 08:37:11 -06:00
if ( results . length > PROMETHEUS_QUERY_BUILDER_MAX_RESULTS ) {
results . splice ( 0 , results . length - PROMETHEUS_QUERY_BUILDER_MAX_RESULTS ) ;
2022-10-25 13:05:21 -05:00
}
return results . map ( ( result ) = > {
return {
label : result.text ,
value : result.text ,
} ;
} ) ;
} ) ;
} ;
2023-04-12 17:22:35 +02:00
// When metric and label lookup is disabled we won't request labels
const metricLookupDisabledSearch = ( ) = > Promise . resolve ( [ ] ) ;
2023-04-03 09:07:17 -05:00
const debouncedSearch = debounce (
( query : string ) = > getMetricLabels ( query ) ,
datasource . getDebounceTimeInMilliseconds ( )
) ;
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
2023-05-01 17:29:35 -04:00
// No type found for the common select props so typing as any
// https://github.com/grafana/grafana/blob/main/packages/grafana-ui/src/components/Select/SelectBase.tsx/#L212-L263
// eslint-disable-next-line
const CustomOption = ( props : any ) = > {
const option = props . data ;
2022-10-25 13:05:21 -05:00
2023-05-01 17:29:35 -04:00
if ( option . value === 'BrowseMetrics' ) {
const isFocused = props . isFocused ? styles . focus : '' ;
return (
< div
{ . . . props . innerProps }
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
ref = { props . innerRef }
className = { ` ${ styles . customOptionWidth } metric-encyclopedia-open ` }
2023-05-01 17:29:35 -04:00
onKeyDown = { ( e ) = > {
// if there is no metric and the m.e. is enabled, open the modal
if ( e . code === 'Enter' ) {
setState ( { . . . state , metricsModalOpen : true } ) ;
2022-01-31 07:57:14 +01:00
}
} }
2023-05-01 17:29:35 -04:00
>
{
2023-05-11 12:52:59 -04:00
< div className = { ` ${ styles . customOption } ${ isFocused } metric-encyclopedia-open ` } >
2023-05-01 17:29:35 -04:00
< div >
2023-05-11 12:52:59 -04:00
< div className = "metric-encyclopedia-open" > { option . label } < / div >
< div className = { ` ${ styles . customOptionDesc } metric-encyclopedia-open ` } > { option . description } < / div >
2023-05-01 17:29:35 -04:00
< / div >
< Button
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
fill = "text"
2023-05-01 17:29:35 -04:00
size = "sm"
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
variant = "secondary"
2023-05-01 17:29:35 -04:00
onClick = { ( ) = > setState ( { . . . state , metricsModalOpen : true } ) }
2023-05-11 12:52:59 -04:00
className = "metric-encyclopedia-open"
2023-05-01 17:29:35 -04:00
>
Open
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
< Icon name = "arrow-right" / >
2023-05-01 17:29:35 -04:00
< / Button >
< / div >
}
< / div >
) ;
}
return SelectMenuOptions ( props ) ;
} ;
return (
< >
{ prometheusMetricEncyclopedia && ! datasource . lookupsDisabled && state . metricsModalOpen && (
< MetricsModal
datasource = { datasource }
isOpen = { state . metricsModalOpen }
onClose = { ( ) = > setState ( { . . . state , metricsModalOpen : false } ) }
query = { query }
onChange = { onChange }
initialMetrics = { state . initialMetrics ? ? [ ] }
2022-01-31 07:57:14 +01:00
/ >
2023-05-01 17:29:35 -04:00
) }
< EditorFieldGroup >
< EditorField label = "Metric" >
< AsyncSelect
inputId = "prometheus-metric-select"
className = { styles . select }
value = { query . metric ? toOption ( query . metric ) : undefined }
placeholder = { 'Select metric' }
allowCustomValue
formatOptionLabel = { formatOptionLabel }
filterOption = { customFilterOption }
onOpenMenu = { async ( ) = > {
if ( metricLookupDisabled ) {
return ;
}
setState ( { isLoading : true } ) ;
const metrics = await onGetMetrics ( ) ;
const initialMetrics : string [ ] = metrics . map ( ( m ) = > m . value ) ;
if ( metrics . length > PROMETHEUS_QUERY_BUILDER_MAX_RESULTS ) {
metrics . splice ( 0 , metrics . length - PROMETHEUS_QUERY_BUILDER_MAX_RESULTS ) ;
}
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
if ( prometheusMetricEncyclopedia ) {
2023-05-01 17:29:35 -04:00
// pass the initial metrics, possibly filtered by labels into the Metrics Modal
const metricsModalOption : SelectableValue [ ] = [
{
value : 'BrowseMetrics' ,
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
label : 'Metrics explorer' ,
2023-05-01 17:29:35 -04:00
description : 'Browse and filter metrics and metadata with a fuzzy search' ,
} ,
] ;
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
// pass the initial metrics into the Metrics Modal
2023-05-01 17:29:35 -04:00
setState ( {
metrics : [ . . . metricsModalOption , . . . metrics ] ,
isLoading : undefined ,
initialMetrics : initialMetrics ,
} ) ;
} else {
setState ( { metrics , isLoading : undefined } ) ;
}
} }
loadOptions = { metricLookupDisabled ? metricLookupDisabledSearch : debouncedSearch }
isLoading = { state . isLoading }
defaultOptions = { state . metrics }
onChange = { ( { value } ) = > {
if ( value ) {
// if there is no metric and the m.e. is enabled, open the modal
if ( prometheusMetricEncyclopedia && value === 'BrowseMetrics' ) {
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
tracking ( 'grafana_prometheus_metric_encyclopedia_open' , null , '' , query ) ;
2023-05-01 17:29:35 -04:00
setState ( { . . . state , metricsModalOpen : true } ) ;
} else {
onChange ( { . . . query , metric : value } ) ;
}
}
} }
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
components = { prometheusMetricEncyclopedia ? { Option : CustomOption } : { } }
2023-05-01 17:29:35 -04:00
/ >
< / EditorField >
< / EditorFieldGroup >
< / >
2022-01-31 07:57:14 +01:00
) ;
}
2022-02-07 15:18:17 +01:00
const getStyles = ( theme : GrafanaTheme2 ) = > ( {
2022-01-31 07:57:14 +01:00
select : css `
min - width : 125px ;
` ,
2022-02-16 09:40:04 +01:00
highlight : css `
2022-02-07 15:18:17 +01:00
label : select__match - highlight ;
background : inherit ;
padding : inherit ;
2022-05-23 15:53:45 +02:00
color : $ { theme . colors . warning . contrastText } ;
background - color : $ { theme . colors . warning . main } ;
2022-02-07 15:18:17 +01:00
` ,
2023-05-01 17:29:35 -04:00
customOption : css `
padding : 8px ;
display : flex ;
justify - content : space - between ;
cursor : pointer ;
: hover {
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
background - color : $ { theme . colors . emphasize ( theme . colors . background . primary , 0.1 ) } ;
2023-05-01 17:29:35 -04:00
}
` ,
customOptionlabel : css `
color : $ { theme . colors . text . primary } ;
` ,
customOptionDesc : css `
color : $ { theme . colors . text . secondary } ;
font - size : $ { theme . typography . size . xs } ;
opacity : 50 % ;
` ,
focus : css `
Prometheus: Metric encyclopedia ux collab design (#68421)
* add class for full story click event on open modal
* move feedback link to modal top under header
* move results amount to bottom left
* move settings into modal, change language from exclude to include
* add metadata to backend search, use toggletip for settings, clean code
* style input row, remove labels and update settings button design
* remove alphabet search as requested by design
* display selected metric
* update style warning message for labels filtered metrics
* organize results footer
* update table design w fixed width and sticky header
* allow focus row on tab and use key Enter to select metric on keydown
* add rudderstack event for disable text wrap
* add messages for no metrics found, labels, search and none in data source.
* filter by type placeholder
* add min width to custom select option
* add text wrap for long metric names
* Have 4px margin b/w the search row and the 'currently selected' text. 16px between 'currently selected text' and the table
* Add some padding inside the first table header row (8 pixels on all sides)
* font-size of 12px for additional settings text
* 4px padding between additional settings text
* 24px margin between the last table cell and the pagination row
* # of Results per page font size 0.85rem
* 8px margin b/w the '# of results per page' and the dropdown
* fix test
* add infer type setting for testing
* use title on icon instead of wrapping in tooltip to fix test
* fix icon issue
* italicize inferred types, update setting text and add icon
* add space for label filters alert message
* make open button style consistent with advanced datasource picker
* keep copy for open modal button
* refactor rudderstack interactions and add inferType
* add event tracking for opening the modal
* galen's feedback, fix select horizontal scroll and results perpg bug
* ismail's feedback for metric types
* revert button in option for accessibility(galen) and style button with ghost mode
* change name to Metrics explorer
* fix hover/focus styles
* ismail's feedbcak, refactor hints, return empty string, remove @return
* Fix icon hovering: put tooltips back in over titles on icon
* make results not expand to fill table space and fix width for modal open option button
2023-05-26 12:39:34 -04:00
background - color : $ { theme . colors . emphasize ( theme . colors . background . primary , 0.1 ) } ;
` ,
customOptionWidth : css `
min - width : 400px ;
2023-05-01 17:29:35 -04:00
` ,
2022-01-31 07:57:14 +01:00
} ) ;
2023-05-08 11:33:30 -05:00
export const formatPrometheusLabelFiltersToString = (
queryString : string ,
labelsFilters : QueryBuilderLabelFilter [ ] | undefined
) : string = > {
const filterArray = labelsFilters ? formatPrometheusLabelFilters ( labelsFilters ) : [ ] ;
return ` label_values({__name__=~".* ${ queryString } " ${ filterArray ? filterArray . join ( '' ) : '' } },__name__) ` ;
} ;
export const formatPrometheusLabelFilters = ( labelsFilters : QueryBuilderLabelFilter [ ] ) : string [ ] = > {
return labelsFilters . map ( ( label ) = > {
return ` , ${ label . label } =" ${ label . value } " ` ;
} ) ;
} ;