From f95c8b785c322cfe60c8c30b57b0383513470e47 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Thu, 5 Mar 2020 17:53:41 +0100 Subject: [PATCH] Stackdriver: Migrate GCE default project (#22593) * Ensure default project * Remove debug logging * Fix broken test * Update snapshot --- pkg/tsdb/stackdriver/stackdriver.go | 2 -- .../datasource/stackdriver/components/Metrics.tsx | 1 - .../stackdriver/components/QueryEditor.test.tsx | 1 + .../stackdriver/components/QueryEditor.tsx | 1 + .../__snapshots__/QueryEditor.test.tsx.snap | 2 +- .../app/plugins/datasource/stackdriver/datasource.ts | 12 +++++++++++- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/tsdb/stackdriver/stackdriver.go b/pkg/tsdb/stackdriver/stackdriver.go index b90420e9f03..495e62de22c 100644 --- a/pkg/tsdb/stackdriver/stackdriver.go +++ b/pkg/tsdb/stackdriver/stackdriver.go @@ -102,10 +102,8 @@ func (e *StackdriverExecutor) getGCEDefaultProject(ctx context.Context, tsdbQuer gceDefaultProject, err := e.getDefaultProject(ctx) if err != nil { - slog.Debug("Stackdriver", "Auth", "Failed to use GCE auth: ", err) return nil, fmt.Errorf("Failed to retrieve default project from GCE metadata server. error: %v", err) } - slog.Debug("Stackdriver", "Auth", "Successfully use GCE auth: ", gceDefaultProject) queryResult.Meta.Set("defaultProject", gceDefaultProject) result.Results[refId] = queryResult diff --git a/public/app/plugins/datasource/stackdriver/components/Metrics.tsx b/public/app/plugins/datasource/stackdriver/components/Metrics.tsx index 2ae137ca1a5..686e528d2d6 100644 --- a/public/app/plugins/datasource/stackdriver/components/Metrics.tsx +++ b/public/app/plugins/datasource/stackdriver/components/Metrics.tsx @@ -111,7 +111,6 @@ export function Metrics(props: Props) { return services.length > 0 ? _.uniqBy(services, s => s.value) : []; }; - console.log('rerender', { service, metricType }); return ( <>
diff --git a/public/app/plugins/datasource/stackdriver/components/QueryEditor.test.tsx b/public/app/plugins/datasource/stackdriver/components/QueryEditor.test.tsx index c7a75dadbac..6350f9675b7 100644 --- a/public/app/plugins/datasource/stackdriver/components/QueryEditor.test.tsx +++ b/public/app/plugins/datasource/stackdriver/components/QueryEditor.test.tsx @@ -11,6 +11,7 @@ const props: Props = { datasource: { getProjects: () => Promise.resolve([]), getDefaultProject: () => Promise.resolve('projectName'), + ensureGCEDefaultProject: () => {}, getMetricTypes: () => Promise.resolve([]), getLabels: () => Promise.resolve([]), variables: [], diff --git a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx index 0ce4ad77fd2..b751284acb1 100644 --- a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx +++ b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx @@ -56,6 +56,7 @@ export class QueryEditor extends React.Component { async componentDidMount() { const { events, target, templateSrv, datasource } = this.props; + await datasource.ensureGCEDefaultProject(); if (!target.projectName) { target.projectName = datasource.getDefaultProject(); } diff --git a/public/app/plugins/datasource/stackdriver/components/__snapshots__/QueryEditor.test.tsx.snap b/public/app/plugins/datasource/stackdriver/components/__snapshots__/QueryEditor.test.tsx.snap index e6eeee7acf2..81fc2058be9 100644 --- a/public/app/plugins/datasource/stackdriver/components/__snapshots__/QueryEditor.test.tsx.snap +++ b/public/app/plugins/datasource/stackdriver/components/__snapshots__/QueryEditor.test.tsx.snap @@ -15,7 +15,7 @@ Array [ onClick={[Function]} > Select Project diff --git a/public/app/plugins/datasource/stackdriver/datasource.ts b/public/app/plugins/datasource/stackdriver/datasource.ts index 9251a21ec1d..670d31bd05c 100644 --- a/public/app/plugins/datasource/stackdriver/datasource.ts +++ b/public/app/plugins/datasource/stackdriver/datasource.ts @@ -41,6 +41,7 @@ export default class StackdriverDatasource extends DataSourceApi) { + await this.ensureGCEDefaultProject(); const queries = options.targets .filter((target: StackdriverQuery) => { return !target.hide && target.metricType; @@ -173,6 +174,7 @@ export default class StackdriverDatasource extends DataSourceApi { try { if (!projectName) {