mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: reimplementing service variable query type
This commit is contained in:
parent
795af5deed
commit
0ec4491a52
@ -23,6 +23,7 @@ export class QueryVariable implements Variable {
|
|||||||
tagValuesQuery: string;
|
tagValuesQuery: string;
|
||||||
tags: any[];
|
tags: any[];
|
||||||
skipUrlSync: boolean;
|
skipUrlSync: boolean;
|
||||||
|
definition: string;
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
type: 'query',
|
type: 'query',
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
getMetricTypesByService,
|
getMetricTypesByService,
|
||||||
getAlignmentOptionsByMetric,
|
getAlignmentOptionsByMetric,
|
||||||
getAggregationOptionsByMetric,
|
getAggregationOptionsByMetric,
|
||||||
|
extractServicesFromMetricDescriptors,
|
||||||
getLabelKeys,
|
getLabelKeys,
|
||||||
} from './functions';
|
} from './functions';
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ export default class StackdriverMetricFindQuery {
|
|||||||
async execute(query: any) {
|
async execute(query: any) {
|
||||||
try {
|
try {
|
||||||
switch (query.selectedQueryType) {
|
switch (query.selectedQueryType) {
|
||||||
|
case MetricFindQueryTypes.Services:
|
||||||
|
return this.handleServiceQuery();
|
||||||
case MetricFindQueryTypes.MetricTypes:
|
case MetricFindQueryTypes.MetricTypes:
|
||||||
return this.handleMetricTypesQuery(query);
|
return this.handleMetricTypesQuery(query);
|
||||||
case MetricFindQueryTypes.LabelKeys:
|
case MetricFindQueryTypes.LabelKeys:
|
||||||
@ -37,6 +40,16 @@ export default class StackdriverMetricFindQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleServiceQuery() {
|
||||||
|
const metricDescriptors = await this.datasource.getMetricTypes(this.datasource.projectName);
|
||||||
|
const services = extractServicesFromMetricDescriptors(metricDescriptors);
|
||||||
|
return services.map(s => ({
|
||||||
|
text: s.serviceShortName,
|
||||||
|
value: s.service,
|
||||||
|
expandable: true,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
async handleMetricTypesQuery({ selectedService }) {
|
async handleMetricTypesQuery({ selectedService }) {
|
||||||
if (!selectedService) {
|
if (!selectedService) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -12,7 +12,7 @@ const SimpleSelect: SFC<Props> = props => {
|
|||||||
return (
|
return (
|
||||||
<div className="gf-form max-width-21">
|
<div className="gf-form max-width-21">
|
||||||
<span className="gf-form-label width-10">{label}</span>
|
<span className="gf-form-label width-10">{label}</span>
|
||||||
<div className="gf-form-select-wrapper max-width-10">
|
<div className="gf-form-select-wrapper max-width-12">
|
||||||
<select className="gf-form-input" required onChange={onValueChange} value={value}>
|
<select className="gf-form-input" required onChange={onValueChange} value={value}>
|
||||||
{options.map(({ value, name }, i) => (
|
{options.map(({ value, name }, i) => (
|
||||||
<option key={i} value={value}>
|
<option key={i} value={value}>
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import uniqBy from 'lodash/uniqBy';
|
|
||||||
import { VariableQueryProps } from 'app/types/plugins';
|
import { VariableQueryProps } from 'app/types/plugins';
|
||||||
import SimpleSelect from './SimpleSelect';
|
import SimpleSelect from './SimpleSelect';
|
||||||
import { getMetricTypes, getLabelKeys } from '../functions';
|
import { getMetricTypes, getLabelKeys, extractServicesFromMetricDescriptors } from '../functions';
|
||||||
import { MetricFindQueryTypes, VariableQueryData } from '../types';
|
import { MetricFindQueryTypes, VariableQueryData } from '../types';
|
||||||
|
|
||||||
export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryProps, VariableQueryData> {
|
export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryProps, VariableQueryData> {
|
||||||
queryTypes: Array<{ value: string; name: string }> = [
|
queryTypes: Array<{ value: string; name: string }> = [
|
||||||
|
{ value: MetricFindQueryTypes.Services, name: 'Services' },
|
||||||
{ value: MetricFindQueryTypes.MetricTypes, name: 'Metric Types' },
|
{ value: MetricFindQueryTypes.MetricTypes, name: 'Metric Types' },
|
||||||
{ value: MetricFindQueryTypes.LabelKeys, name: 'Label Keys' },
|
{ value: MetricFindQueryTypes.LabelKeys, name: 'Label Keys' },
|
||||||
{ value: MetricFindQueryTypes.LabelValues, name: 'Label Values' },
|
{ value: MetricFindQueryTypes.LabelValues, name: 'Label Values' },
|
||||||
@ -34,7 +34,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
|
|||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const metricDescriptors = await this.props.datasource.getMetricTypes(this.props.datasource.projectName);
|
const metricDescriptors = await this.props.datasource.getMetricTypes(this.props.datasource.projectName);
|
||||||
const services = uniqBy(metricDescriptors, 'service').map(m => ({
|
const services = extractServicesFromMetricDescriptors(metricDescriptors).map(m => ({
|
||||||
value: m.service,
|
value: m.service,
|
||||||
name: m.serviceShortName,
|
name: m.serviceShortName,
|
||||||
}));
|
}));
|
||||||
@ -50,7 +50,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
|
|||||||
metricDescriptors,
|
metricDescriptors,
|
||||||
this.state.selectedMetricType,
|
this.state.selectedMetricType,
|
||||||
this.props.templateSrv.replace(this.state.selectedMetricType),
|
this.props.templateSrv.replace(this.state.selectedMetricType),
|
||||||
selectedService
|
this.props.templateSrv.replace(selectedService)
|
||||||
);
|
);
|
||||||
const state: any = {
|
const state: any = {
|
||||||
services,
|
services,
|
||||||
@ -76,7 +76,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
|
|||||||
this.state.metricDescriptors,
|
this.state.metricDescriptors,
|
||||||
this.state.selectedMetricType,
|
this.state.selectedMetricType,
|
||||||
this.props.templateSrv.replace(this.state.selectedMetricType),
|
this.props.templateSrv.replace(this.state.selectedMetricType),
|
||||||
event.target.value
|
this.props.templateSrv.replace(event.target.value)
|
||||||
);
|
);
|
||||||
const state: any = {
|
const state: any = {
|
||||||
selectedService: event.target.value,
|
selectedService: event.target.value,
|
||||||
@ -125,7 +125,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
|
|||||||
return (
|
return (
|
||||||
<SimpleSelect
|
<SimpleSelect
|
||||||
value={this.state.selectedService}
|
value={this.state.selectedService}
|
||||||
options={this.state.services}
|
options={this.insertTemplateVariables(this.state.services)}
|
||||||
onValueChange={e => this.onServiceChange(e)}
|
onValueChange={e => this.onServiceChange(e)}
|
||||||
label="Services"
|
label="Services"
|
||||||
/>
|
/>
|
||||||
@ -137,7 +137,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
|
|||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<SimpleSelect
|
<SimpleSelect
|
||||||
value={this.state.selectedService}
|
value={this.state.selectedService}
|
||||||
options={this.state.services}
|
options={this.insertTemplateVariables(this.state.services)}
|
||||||
onValueChange={e => this.onServiceChange(e)}
|
onValueChange={e => this.onServiceChange(e)}
|
||||||
label="Services"
|
label="Services"
|
||||||
/>
|
/>
|
||||||
@ -163,7 +163,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
|
|||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<SimpleSelect
|
<SimpleSelect
|
||||||
value={this.state.selectedService}
|
value={this.state.selectedService}
|
||||||
options={this.state.services}
|
options={this.insertTemplateVariables(this.state.services)}
|
||||||
onValueChange={e => this.onServiceChange(e)}
|
onValueChange={e => this.onServiceChange(e)}
|
||||||
label="Services"
|
label="Services"
|
||||||
/>
|
/>
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import uniqBy from 'lodash/uniqBy';
|
||||||
import { alignOptions, aggOptions } from './constants';
|
import { alignOptions, aggOptions } from './constants';
|
||||||
|
|
||||||
|
export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service');
|
||||||
|
|
||||||
export const getMetricTypesByService = (metricDescriptors, service) =>
|
export const getMetricTypesByService = (metricDescriptors, service) =>
|
||||||
metricDescriptors.filter(m => m.service === service);
|
metricDescriptors.filter(m => m.service === service);
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export enum MetricFindQueryTypes {
|
export enum MetricFindQueryTypes {
|
||||||
|
Services = 'services',
|
||||||
MetricTypes = 'metricTypes',
|
MetricTypes = 'metricTypes',
|
||||||
LabelKeys = 'labelKeys',
|
LabelKeys = 'labelKeys',
|
||||||
LabelValues = 'labelValues',
|
LabelValues = 'labelValues',
|
||||||
|
Loading…
Reference in New Issue
Block a user