Commit b8c2ba33 by Erik Sundell

add typing for metric descriptor

parent 8867d8e9
...@@ -2,10 +2,11 @@ import React from 'react'; ...@@ -2,10 +2,11 @@ import React from 'react';
import _ from 'lodash'; import _ from 'lodash';
import appEvents from 'app/core/app_events'; import appEvents from 'app/core/app_events';
import { MetricDescriptor } from '../types';
import { MetricSelect } from 'app/core/components/Select/MetricSelect'; import { MetricSelect } from 'app/core/components/Select/MetricSelect';
export interface Props { export interface Props {
onChange: (metricDescriptor) => void; onChange: (metricDescriptor: MetricDescriptor) => void;
templateSrv: any; templateSrv: any;
datasource: any; datasource: any;
defaultProject: string; defaultProject: string;
...@@ -14,12 +15,12 @@ export interface Props { ...@@ -14,12 +15,12 @@ export interface Props {
} }
interface State { interface State {
metricDescriptors: any[]; metricDescriptors: MetricDescriptor[];
metrics: any[]; metrics: any[];
services: any[]; services: any[];
service: string; service: string;
metric: string; metric: string;
metricDescriptor: any; metricDescriptor: MetricDescriptor;
defaultProject: string; defaultProject: string;
} }
...@@ -84,7 +85,7 @@ export class Metrics extends React.Component<Props, State> { ...@@ -84,7 +85,7 @@ export class Metrics extends React.Component<Props, State> {
return this.state.metricDescriptors.find(md => md.type === this.props.templateSrv.replace(metricType)); return this.state.metricDescriptors.find(md => md.type === this.props.templateSrv.replace(metricType));
} }
getMetricsList(metricDescriptors) { getMetricsList(metricDescriptors: MetricDescriptor[]) {
const selectedMetricDescriptor = this.getSelectedMetricDescriptor(this.props.metricType); const selectedMetricDescriptor = this.getSelectedMetricDescriptor(this.props.metricType);
if (!selectedMetricDescriptor) { if (!selectedMetricDescriptor) {
return []; return [];
...@@ -122,7 +123,7 @@ export class Metrics extends React.Component<Props, State> { ...@@ -122,7 +123,7 @@ export class Metrics extends React.Component<Props, State> {
this.props.onChange({ ...metricDescriptor, type: value }); this.props.onChange({ ...metricDescriptor, type: value });
} }
getServicesList(metricDescriptors) { getServicesList(metricDescriptors: MetricDescriptor[]) {
const services = metricDescriptors.map(m => ({ const services = metricDescriptors.map(m => ({
value: m.service, value: m.service,
label: _.startCase(m.serviceShortName), label: _.startCase(m.serviceShortName),
......
...@@ -8,7 +8,7 @@ import { Alignments } from './Alignments'; ...@@ -8,7 +8,7 @@ import { Alignments } from './Alignments';
import { AlignmentPeriods } from './AlignmentPeriods'; import { AlignmentPeriods } from './AlignmentPeriods';
import { AliasBy } from './AliasBy'; import { AliasBy } from './AliasBy';
import { Help } from './Help'; import { Help } from './Help';
import { Target } from '../types'; import { Target, MetricDescriptor } from '../types';
import { getAlignmentPickerData } from '../functions'; import { getAlignmentPickerData } from '../functions';
export interface Props { export interface Props {
...@@ -92,7 +92,7 @@ export class QueryEditor extends React.Component<Props, State> { ...@@ -92,7 +92,7 @@ export class QueryEditor extends React.Component<Props, State> {
this.setState({ lastQuery, lastQueryError }); this.setState({ lastQuery, lastQueryError });
} }
onMetricTypeChange({ valueType, metricKind, type, unit }) { onMetricTypeChange({ valueType, metricKind, type, unit }: MetricDescriptor) {
const { templateSrv, onQueryChange, onExecuteQuery } = this.props; const { templateSrv, onQueryChange, onExecuteQuery } = this.props;
const { perSeriesAligner, alignOptions } = getAlignmentPickerData( const { perSeriesAligner, alignOptions } = getAlignmentPickerData(
{ valueType, metricKind, perSeriesAligner: this.state.perSeriesAligner }, { valueType, metricKind, perSeriesAligner: this.state.perSeriesAligner },
......
...@@ -2,6 +2,7 @@ import { stackdriverUnitMappings } from './constants'; ...@@ -2,6 +2,7 @@ import { stackdriverUnitMappings } from './constants';
import appEvents from 'app/core/app_events'; import appEvents from 'app/core/app_events';
import _ from 'lodash'; import _ from 'lodash';
import StackdriverMetricFindQuery from './StackdriverMetricFindQuery'; import StackdriverMetricFindQuery from './StackdriverMetricFindQuery';
import { MetricDescriptor } from './types';
export default class StackdriverDatasource { export default class StackdriverDatasource {
id: number; id: number;
...@@ -253,7 +254,7 @@ export default class StackdriverDatasource { ...@@ -253,7 +254,7 @@ export default class StackdriverDatasource {
} }
} }
async getMetricTypes(projectName: string) { async getMetricTypes(projectName: string): Promise<MetricDescriptor[]> {
try { try {
if (this.metricTypes.length === 0) { if (this.metricTypes.length === 0) {
const metricsApiPath = `v3/projects/${projectName}/metricDescriptors`; const metricsApiPath = `v3/projects/${projectName}/metricDescriptors`;
......
...@@ -55,3 +55,14 @@ export interface QueryMeta { ...@@ -55,3 +55,14 @@ export interface QueryMeta {
resourceLabels: { [key: string]: string[] }; resourceLabels: { [key: string]: string[] };
resourceTypes: string[]; resourceTypes: string[];
} }
export interface MetricDescriptor {
valueType: string;
metricKind: string;
type: string;
unit: string;
service: string;
serviceShortName: string;
displayName: string;
description: string;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment