import React from 'react'; import { MetricDescriptor } from '../types'; import { Icon } from '@grafana/ui'; export interface Props { rawQuery: string; lastQueryError: string; metricDescriptor?: MetricDescriptor; } interface State { displayHelp: boolean; displaRawQuery: boolean; } export class Help extends React.Component { state: State = { displayHelp: false, displaRawQuery: false, }; onHelpClicked = () => { this.setState({ displayHelp: !this.state.displayHelp }); }; onRawQueryClicked = () => { this.setState({ displaRawQuery: !this.state.displaRawQuery }); }; shouldComponentUpdate(nextProps: Props) { return nextProps.metricDescriptor !== null; } render() { const { displayHelp, displaRawQuery } = this.state; const { rawQuery, lastQueryError } = this.props; return ( <>
{rawQuery && (
)}
{rawQuery && displaRawQuery && (
{rawQuery}
)} {displayHelp && (
Alias Patterns
Format the legend keys any way you want by using alias patterns. Format the legend keys any way you want by using alias patterns.

Example: {`${'{{metricDescriptor.name}} - {{metricDescriptor.label.instance_name}}'}`}
Result:   cpu/usage_time - server1-europe-west-1

Patterns
  • {`${'{{metricDescriptor.type}}'}`} = metric type e.g. compute.googleapis.com/instance/cpu/usage_time
  • {`${'{{metricDescriptor.name}}'}`} = name part of metric e.g. instance/cpu/usage_time
  • {`${'{{metricDescriptor.service}}'}`} = service part of metric e.g. compute
  • {`${'{{metricDescriptor.label.label_name}}'}`} = Metric label metadata e.g. metricDescriptor.label.instance_name
  • {`${'{{resource.label.label_name}}'}`} = Resource label metadata e.g. resource.label.zone
  • {`${'{{metadata.system_labels.name}}'}`} = Meta data system labels e.g. metadata.system_labels.name. For this to work, the needs to be included in the group by
  • {`${'{{metadata.user_labels.name}}'}`} = Meta data user labels e.g. metadata.user_labels.name. For this to work, the needs to be included in the group by
  • {`${'{{bucket}}'}`} = bucket boundary for distribution metrics when using a heatmap in Grafana
  • {`${'{{project}}'}`} = The project name that was specified in the query editor
  • {`${'{{service}}'}`} = The service id that was specified in the SLO query editor
  • {`${'{{slo}}'}`} = The SLO id that was specified in the SLO query editor
  • {`${'{{selector}}'}`} = The Selector function that was specified in the SLO query editor
)} {lastQueryError && (
{lastQueryError}
)} ); } }