1import { DataQuery, DataSourceJsonData, SelectableValue } from '@grafana/data';
2
3export enum AuthType {
4  JWT = 'jwt',
5  GCE = 'gce',
6}
7
8export const authTypes: Array<SelectableValue<string>> = [
9  { label: 'Google JWT File', value: AuthType.JWT },
10  { label: 'GCE Default Service Account', value: AuthType.GCE },
11];
12
13export enum MetricFindQueryTypes {
14  Projects = 'projects',
15  Services = 'services',
16  DefaultProject = 'defaultProject',
17  MetricTypes = 'metricTypes',
18  LabelKeys = 'labelKeys',
19  LabelValues = 'labelValues',
20  ResourceTypes = 'resourceTypes',
21  Aggregations = 'aggregations',
22  Aligners = 'aligners',
23  AlignmentPeriods = 'alignmentPeriods',
24  Selectors = 'selectors',
25  SLOServices = 'sloServices',
26  SLO = 'slo',
27}
28
29export interface CloudMonitoringVariableQuery extends DataQuery {
30  selectedQueryType: string;
31  selectedService: string;
32  selectedMetricType: string;
33  selectedSLOService: string;
34  labelKey: string;
35  projects: SelectableValue[];
36  sloServices: SelectableValue[];
37  projectName: string;
38}
39
40export interface VariableQueryData {
41  selectedQueryType: string;
42  metricDescriptors: MetricDescriptor[];
43  selectedService: string;
44  selectedMetricType: string;
45  selectedSLOService: string;
46  labels: string[];
47  labelKey: string;
48  metricTypes: Array<{ value: string; name: string }>;
49  services: SelectableValue[];
50  projects: SelectableValue[];
51  sloServices: SelectableValue[];
52  projectName: string;
53  loading: boolean;
54}
55
56export interface Aggregation {
57  crossSeriesReducer?: string;
58  groupBys?: string[];
59}
60
61export enum QueryType {
62  METRICS = 'metrics',
63  SLO = 'slo',
64}
65
66export enum EditorMode {
67  Visual = 'visual',
68  MQL = 'mql',
69}
70
71export enum PreprocessorType {
72  None = 'none',
73  Rate = 'rate',
74  Delta = 'delta',
75}
76
77export enum MetricKind {
78  METRIC_KIND_UNSPECIFIED = 'METRIC_KIND_UNSPECIFIED',
79  GAUGE = 'GAUGE',
80  DELTA = 'DELTA',
81  CUMULATIVE = 'CUMULATIVE',
82}
83
84export enum ValueTypes {
85  VALUE_TYPE_UNSPECIFIED = 'VALUE_TYPE_UNSPECIFIED',
86  BOOL = 'BOOL',
87  INT64 = 'INT64',
88  DOUBLE = 'DOUBLE',
89  STRING = 'STRING',
90  DISTRIBUTION = 'DISTRIBUTION',
91  MONEY = 'MONEY',
92}
93
94export enum AlignmentTypes {
95  ALIGN_DELTA = 'ALIGN_DELTA',
96  ALIGN_RATE = 'ALIGN_RATE',
97  ALIGN_INTERPOLATE = 'ALIGN_INTERPOLATE',
98  ALIGN_NEXT_OLDER = 'ALIGN_NEXT_OLDER',
99  ALIGN_MIN = 'ALIGN_MIN',
100  ALIGN_MAX = 'ALIGN_MAX',
101  ALIGN_MEAN = 'ALIGN_MEAN',
102  ALIGN_COUNT = 'ALIGN_COUNT',
103  ALIGN_SUM = 'ALIGN_SUM',
104  ALIGN_STDDEV = 'ALIGN_STDDEV',
105  ALIGN_COUNT_TRUE = 'ALIGN_COUNT_TRUE',
106  ALIGN_COUNT_FALSE = 'ALIGN_COUNT_FALSE',
107  ALIGN_FRACTION_TRUE = 'ALIGN_FRACTION_TRUE',
108  ALIGN_PERCENTILE_99 = 'ALIGN_PERCENTILE_99',
109  ALIGN_PERCENTILE_95 = 'ALIGN_PERCENTILE_95',
110  ALIGN_PERCENTILE_50 = 'ALIGN_PERCENTILE_50',
111  ALIGN_PERCENTILE_05 = 'ALIGN_PERCENTILE_05',
112  ALIGN_PERCENT_CHANGE = 'ALIGN_PERCENT_CHANGE',
113}
114
115export interface BaseQuery {
116  projectName: string;
117  perSeriesAligner?: string;
118  alignmentPeriod?: string;
119  aliasBy?: string;
120}
121
122export interface MetricQuery extends BaseQuery {
123  editorMode: EditorMode;
124  metricType: string;
125  crossSeriesReducer: string;
126  groupBys?: string[];
127  filters?: string[];
128  metricKind?: MetricKind;
129  valueType?: string;
130  view?: string;
131  query: string;
132  preprocessor?: PreprocessorType;
133}
134
135export interface SLOQuery extends BaseQuery {
136  selectorName: string;
137  serviceId: string;
138  serviceName: string;
139  sloId: string;
140  sloName: string;
141  goal?: number;
142}
143
144export interface CloudMonitoringQuery extends DataQuery {
145  datasourceId?: number; // Should not be necessary anymore
146  queryType: QueryType;
147  metricQuery: MetricQuery;
148  sloQuery?: SLOQuery;
149  intervalMs: number;
150  type: string;
151}
152
153export interface CloudMonitoringOptions extends DataSourceJsonData {
154  defaultProject?: string;
155  gceDefaultProject?: string;
156  authenticationType?: string;
157  clientEmail?: string;
158  tokenUri?: string;
159}
160
161export interface CloudMonitoringSecureJsonData {
162  privateKey?: string;
163}
164
165export interface AnnotationTarget {
166  projectName: string;
167  metricType: string;
168  refId: string;
169  filters: string[];
170  metricKind: MetricKind;
171  valueType: string;
172  title: string;
173  text: string;
174}
175
176export interface QueryMeta {
177  alignmentPeriod: string;
178  rawQuery: string;
179  rawQueryString: string;
180  metricLabels: { [key: string]: string[] };
181  resourceLabels: { [key: string]: string[] };
182  resourceTypes: string[];
183}
184
185export interface MetricDescriptor {
186  valueType: string;
187  metricKind: MetricKind;
188  type: string;
189  unit: string;
190  service: string;
191  serviceShortName: string;
192  displayName: string;
193  description: string;
194}
195
196export interface Segment {
197  type: string;
198  value: string;
199}
200
201export interface Filter {
202  key: string;
203  operator: string;
204  value: string;
205  condition?: string;
206}
207
208export interface CustomMetaData {
209  perSeriesAligner?: string;
210  alignmentPeriod?: string;
211}
212
213export interface PostResponse {
214  results: Record<string, any>;
215}
216