From 50e7ac8d65aaeda3a248ec22c4135d8ce00a986a Mon Sep 17 00:00:00 2001 From: Isabella Siu Date: Tue, 25 Jan 2022 13:10:14 -0500 Subject: [PATCH] CloudMonitoring: use @grafana/google-sdk (#44398) --- package.json | 1 + .../components/ConfigEditor/ConfigEditor.tsx | 68 +-------------- .../components/ConfigEditor/JWTConfig.tsx | 82 ------------------- .../components/QueryEditor.tsx | 4 +- .../datasource/cloud-monitoring/constants.ts | 7 +- .../datasource/cloud-monitoring/types.ts | 12 +-- yarn.lock | 8 ++ 7 files changed, 23 insertions(+), 159 deletions(-) delete mode 100644 public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/JWTConfig.tsx diff --git a/package.json b/package.json index f55bc80781f..362f188151b 100644 --- a/package.json +++ b/package.json @@ -235,6 +235,7 @@ "@grafana/data": "workspace:*", "@grafana/e2e-selectors": "workspace:*", "@grafana/experimental": "0.0.2-canary.11", + "@grafana/google-sdk": "0.0.2", "@grafana/runtime": "workspace:*", "@grafana/schema": "workspace:*", "@grafana/slate-react": "0.22.10-grafana", diff --git a/public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/ConfigEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/ConfigEditor.tsx index 86ba6719f37..f710279fa9e 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/ConfigEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/ConfigEditor/ConfigEditor.tsx @@ -1,75 +1,15 @@ -import { DataSourcePluginOptionsEditorProps, onUpdateDatasourceJsonDataOptionSelect } from '@grafana/data'; -import { Alert, InlineField, Select } from '@grafana/ui'; import React, { PureComponent } from 'react'; - -import { AuthType, authTypes, CloudMonitoringOptions, CloudMonitoringSecureJsonData } from '../../types'; -import { JWTConfig } from './JWTConfig'; +import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; +import { CloudMonitoringOptions, CloudMonitoringSecureJsonData } from '../../types'; +import { ConnectionConfig } from '@grafana/google-sdk'; export type Props = DataSourcePluginOptionsEditorProps; export class ConfigEditor extends PureComponent { render() { - const { options, onOptionsChange } = this.props; - const { secureJsonFields, jsonData } = options; - - if (!jsonData.hasOwnProperty('authenticationType')) { - jsonData.authenticationType = AuthType.JWT; - } - return ( <> -

Authentication

-
- - - - ))} - - - - Do not forget to save your changes after uploading a file - - - ); -} - -export const getStyles = (theme: GrafanaTheme) => css` - margin: ${theme.spacing.md} 0 0; -`; diff --git a/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.tsx index 71a9e40e97e..a4124efbd09 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/QueryEditor.tsx @@ -5,12 +5,12 @@ import React, { PureComponent } from 'react'; import { QUERY_TYPES, SELECT_WIDTH } from '../constants'; import CloudMonitoringDatasource from '../datasource'; -import { CloudMonitoringQuery, EditorMode, MetricQuery, QueryType, SLOQuery } from '../types'; +import { CloudMonitoringQuery, EditorMode, MetricQuery, QueryType, SLOQuery, CloudMonitoringOptions } from '../types'; import { MetricQueryEditor, QueryEditorRow, SLOQueryEditor } from './'; import { defaultQuery } from './MetricQueryEditor'; import { defaultQuery as defaultSLOQuery } from './SLO/SLOQueryEditor'; -export type Props = QueryEditorProps; +export type Props = QueryEditorProps; export class QueryEditor extends PureComponent { async UNSAFE_componentWillMount() { diff --git a/public/app/plugins/datasource/cloud-monitoring/constants.ts b/public/app/plugins/datasource/cloud-monitoring/constants.ts index 5e3280f948f..e87bcd7e092 100644 --- a/public/app/plugins/datasource/cloud-monitoring/constants.ts +++ b/public/app/plugins/datasource/cloud-monitoring/constants.ts @@ -1,4 +1,5 @@ -import { AuthType, MetricKind, QueryType, ValueTypes } from './types'; +import { MetricKind, QueryType, ValueTypes } from './types'; +import { GoogleAuthType } from '@grafana/google-sdk'; // not super excited about using uneven numbers, but this makes it align perfectly with rows that has two fields export const INPUT_WIDTH = 71; @@ -6,8 +7,8 @@ export const LABEL_WIDTH = 19; export const INNER_LABEL_WIDTH = 14; export const SELECT_WIDTH = 28; export const AUTH_TYPES = [ - { value: 'Google JWT File', key: AuthType.JWT }, - { value: 'GCE Default Service Account', key: AuthType.GCE }, + { value: 'Google JWT File', key: GoogleAuthType.JWT }, + { value: 'GCE Default Service Account', key: GoogleAuthType.GCE }, ]; export const ALIGNMENTS = [ diff --git a/public/app/plugins/datasource/cloud-monitoring/types.ts b/public/app/plugins/datasource/cloud-monitoring/types.ts index 347490a7844..7f456d4ec7b 100644 --- a/public/app/plugins/datasource/cloud-monitoring/types.ts +++ b/public/app/plugins/datasource/cloud-monitoring/types.ts @@ -1,13 +1,9 @@ import { DataQuery, DataSourceJsonData, SelectableValue } from '@grafana/data'; - -export enum AuthType { - JWT = 'jwt', - GCE = 'gce', -} +import { GoogleAuthType } from '@grafana/google-sdk'; export const authTypes: Array> = [ - { label: 'Google JWT File', value: AuthType.JWT }, - { label: 'GCE Default Service Account', value: AuthType.GCE }, + { label: 'Google JWT File', value: GoogleAuthType.JWT }, + { label: 'GCE Default Service Account', value: GoogleAuthType.GCE }, ]; export enum MetricFindQueryTypes { @@ -153,7 +149,7 @@ export interface CloudMonitoringQuery extends DataQuery { export interface CloudMonitoringOptions extends DataSourceJsonData { defaultProject?: string; gceDefaultProject?: string; - authenticationType?: string; + authenticationType: GoogleAuthType; clientEmail?: string; tokenUri?: string; } diff --git a/yarn.lock b/yarn.lock index 0c5281ba1fe..34d6efbdaec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3846,6 +3846,13 @@ __metadata: languageName: node linkType: hard +"@grafana/google-sdk@npm:0.0.2": + version: 0.0.2 + resolution: "@grafana/google-sdk@npm:0.0.2" + checksum: a4dfe7a31a9fd8aabe8daf997d43a034226a2e366e23257080c6a2c5980f8e57e7bec74ba508ac2d860e247ea7734d91bcd6b71ca5a61fa6277344778640532f + languageName: node + linkType: hard + "@grafana/runtime@workspace:*, @grafana/runtime@workspace:packages/grafana-runtime": version: 0.0.0-use.local resolution: "@grafana/runtime@workspace:packages/grafana-runtime" @@ -19761,6 +19768,7 @@ __metadata: "@grafana/e2e-selectors": "workspace:*" "@grafana/eslint-config": 2.5.1 "@grafana/experimental": 0.0.2-canary.11 + "@grafana/google-sdk": 0.0.2 "@grafana/runtime": "workspace:*" "@grafana/schema": "workspace:*" "@grafana/slate-react": 0.22.10-grafana