grafana/public/app/plugins/datasource/stackdriver/components/Help.tsx

122 lines
4.2 KiB
TypeScript
Raw Normal View History

2018-12-20 23:55:02 +08:00
import React from 'react';
import { MetricDescriptor } from '../types';
2018-12-20 23:55:02 +08:00
export interface Props {
2018-12-22 04:38:46 +08:00
rawQuery: string;
2018-12-22 05:04:46 +08:00
lastQueryError: string;
metricDescriptor?: MetricDescriptor;
2018-12-20 23:55:02 +08:00
}
interface State {
displayHelp: boolean;
displaRawQuery: boolean;
}
export class Help extends React.Component<Props, State> {
state: State = {
displayHelp: false,
displaRawQuery: false,
};
onHelpClicked = () => {
2018-12-20 23:55:02 +08:00
this.setState({ displayHelp: !this.state.displayHelp });
};
2018-12-20 23:55:02 +08:00
onRawQueryClicked = () => {
2018-12-22 04:38:46 +08:00
this.setState({ displaRawQuery: !this.state.displaRawQuery });
};
2018-12-22 04:38:46 +08:00
shouldComponentUpdate(nextProps: Props) {
2018-12-22 04:38:46 +08:00
return nextProps.metricDescriptor !== null;
2018-12-20 23:55:02 +08:00
}
render() {
const { displayHelp, displaRawQuery } = this.state;
Stackdriver: Project selector (#22447) * clean PR #17366 * udpate vendor * [WIP] Implement projects management for stackdriver * [WIP] Implement projects management for stackdriver * [WIP] Implement projects management for stackdriver * Implement projects management for stackdriver * [WIP][Tests] Fix errors * clean anonymous struct * remove await * don't store project list * Add default project on query editor * gofmt * Fix tests * Move test data source to backend * Use segment instead of dropdown. remove ensure default project since it's not being used anymore. * Fix broken annotation editor * Load gceDefaultAccount only once when in the config page * Reset error message on auth type change * Add metric find query for projects * Remove debug code * Fix broken tests * Fix typings * Fix lint error * Slightly different approach - now having a distiction between config page default project, and project that is selectable from the dropdown in the query editor. * Fix broken tests * Attempt to fix strict ts errors * Prevent state from being set multiple times * Remove noOptionsMessage since it seems to be obosolete in react select * One more attempt to solve ts strict error * Interpolate project template variable. Make sure its loaded correctly when opening variable query editor first time * Implicit any fix * fix: typescript strict null check fixes * Return empty array in case project endpoint fails * Rename project to projectName to prevent clashing with legacy query prop * Fix broken test * fix: Stackdriver - template replace on filter label should have a regex format as that escapes the dots in the label name which is not valid. Co-authored-by: Labesse Kévin <kevin@labesse.me> Co-authored-by: Elias Cédric Laouiti <elias@abtasty.com> Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
2020-03-02 22:31:09 +08:00
const { rawQuery, lastQueryError } = this.props;
2018-12-20 23:55:02 +08:00
return (
2019-01-08 20:00:31 +08:00
<>
2018-12-22 04:38:46 +08:00
<div className="gf-form-inline">
<div className="gf-form" onClick={this.onHelpClicked}>
<label className="gf-form-label query-keyword pointer">
Show Help <i className={`fa fa-caret-${displayHelp ? 'down' : 'right'}`} />
2018-12-20 23:55:02 +08:00
</label>
</div>
2018-12-22 04:38:46 +08:00
{rawQuery && (
<div className="gf-form" onClick={this.onRawQueryClicked}>
2018-12-22 04:38:46 +08:00
<label className="gf-form-label query-keyword">
Raw Query <i className={`fa fa-caret-${displaRawQuery ? 'down' : 'right'}`} ng-show="ctrl.showHelp" />
2018-12-22 04:38:46 +08:00
</label>
</div>
)}
<div className="gf-form gf-form--grow">
<div className="gf-form-label gf-form-label--grow" />
</div>
2018-12-20 23:55:02 +08:00
</div>
{rawQuery && displaRawQuery && (
<div className="gf-form">
<pre className="gf-form-pre">{rawQuery}</pre>
</div>
)}
2018-12-22 04:38:46 +08:00
{displayHelp && (
2020-02-04 21:16:56 +08:00
<div className="gf-form grafana-info-box alert-info">
<div>
2018-12-22 04:38:46 +08:00
<h5>Alias Patterns</h5>Format the legend keys any way you want by using alias patterns. Format the legend
keys any way you want by using alias patterns.
<br /> <br />
2018-12-22 04:38:46 +08:00
Example:
<code>{`${'{{metricDescriptor.name}} - {{metricDescriptor.label.instance_name}}'}`}</code>
<br />
Result: &nbsp;&nbsp;<code>cpu/usage_time - server1-europe-west-1</code>
<br />
<br />
<strong>Patterns</strong>
<br />
<ul>
<li>
<code>{`${'{{metricDescriptor.type}}'}`}</code> = metric type e.g.
compute.googleapis.com/instance/cpu/usage_time
</li>
<li>
<code>{`${'{{metricDescriptor.name}}'}`}</code> = name part of metric e.g. instance/cpu/usage_time
</li>
<li>
<code>{`${'{{metricDescriptor.service}}'}`}</code> = service part of metric e.g. compute
</li>
<li>
<code>{`${'{{metricDescriptor.label.label_name}}'}`}</code> = Metric label metadata e.g.
metricDescriptor.label.instance_name
</li>
<li>
<code>{`${'{{resource.label.label_name}}'}`}</code> = Resource label metadata e.g. resource.label.zone
</li>
<li>
<code>{`${'{{metadata.system_labels.name}}'}`}</code> = Meta data system labels e.g.
metadata.system_labels.name. For this to work, the needs to be included in the group by
</li>
<li>
<code>{`${'{{metadata.user_labels.name}}'}`}</code> = Meta data user labels e.g.
metadata.user_labels.name. For this to work, the needs to be included in the group by
</li>
<li>
<code>{`${'{{bucket}}'}`}</code> = bucket boundary for distribution metrics when using a heatmap in
Grafana
</li>
2018-12-22 04:38:46 +08:00
</ul>
2020-02-04 21:16:56 +08:00
</div>
2018-12-22 04:38:46 +08:00
</div>
)}
2018-12-22 05:04:46 +08:00
{lastQueryError && (
<div className="gf-form">
<pre className="gf-form-pre alert alert-error">{lastQueryError}</pre>
</div>
)}
2019-01-08 20:00:31 +08:00
</>
2018-12-20 23:55:02 +08:00
);
}
}