Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.

Commit ecb8eb6

Browse files
authored
Merge pull request #180 from doitintl/issue-178
Solves #178
2 parents 1111932 + 8acf4bc commit ecb8eb6

File tree

8 files changed

+61978
-28
lines changed

8 files changed

+61978
-28
lines changed

dist/module.js

Lines changed: 61916 additions & 22 deletions
Large diffs are not rendered by default.

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/partials/config.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ <h6>Uploaded Key Details</h6>
110110
The project that the Queries will be run in if you are using a flat-rate pricing model.
111111
</info-popover>
112112
</div>
113+
<div class="gf-form">
114+
<label class="gf-form-label">Processing Location</label>
115+
<div class="gf-form-select-wrapper">
116+
<select class="gf-form-input gf-size-auto" ng-model="ctrl.current.jsonData.processingLocation"
117+
ng-options="f.value as f.text for f in ctrl.locations"
118+
ng-change="ctrl.refresh()"></select>
119+
</div>
120+
</div>
113121
<gf-form-switch class="gf-form" label="Send anonymous usage data" label-class="width-13" checked="ctrl.current.jsonData.sendUsageData" switch-class="max-width-6"></gf-form-switch>
114122
<label class="gf-form-label query-keyword pointer">
115123
</label>

src/bigquery_query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default class BigQueryQuery {
106106
target.format = target.format || "time_series";
107107
target.orderByCol = target.orderByCol || "1";
108108
target.orderBySort = target.orderBySort || "1";
109-
target.location = target.location || "US";
109+
target.location = target.location || undefined;
110110
target.timeColumn = target.timeColumn || "-- time --";
111111
target.timeColumnType = target.timeColumnType || "TIMESTAMP";
112112
target.metricColumn = target.metricColumn || "none";

src/config_ctrl.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {isCombinedModifierFlagSet} from "tslint";
44
export class BigQueryConfigCtrl {
55
private static templateUrl = "partials/config.html";
66
public authenticationTypes: any[];
7+
public locations: any[];
78
public inputDataValid: boolean;
89
public jsonText: string;
910
public validationErrors: string[] = [];
@@ -12,12 +13,14 @@ export class BigQueryConfigCtrl {
1213
private readonly defaultAuthenticationType: string;
1314
private readonly defaultSendUsageData: boolean;
1415
private readonly defaultFlatRateProject: string;
16+
private readonly defaultProcessingLocation: string;
1517

1618
/** @ngInject */
1719
constructor(datasourceSrv) {
1820
this.defaultAuthenticationType = "jwt";
1921
this.defaultSendUsageData = true;
2022
this.defaultFlatRateProject = undefined;
23+
this.defaultProcessingLocation = undefined;
2124
this.datasourceSrv = datasourceSrv;
2225
this.current.jsonData = this.current.jsonData || {};
2326
this.current.jsonData.authenticationType = this.current.jsonData
@@ -30,12 +33,37 @@ export class BigQueryConfigCtrl {
3033
if (this.current.jsonData.flatRateProject === undefined) {
3134
this.current.jsonData.flatRateProject = this.defaultFlatRateProject;
3235
}
36+
if (this.current.jsonData.processingLocations === undefined) {
37+
this.current.jsonData.processingLocations = this.defaultProcessingLocation;
38+
}
3339
this.current.secureJsonData = this.current.secureJsonData || {};
3440
this.current.secureJsonFields = this.current.secureJsonFields || {};
3541
this.authenticationTypes = [
3642
{ key: this.defaultAuthenticationType, value: "Google JWT File" },
3743
{ key: "gce", value: "GCE Default Service Account" }
3844
];
45+
this.locations = [
46+
{ text: "United States (US)", value: "US" },
47+
{ text: "European Union (EU)", value: "EU" },
48+
{ text: "Los Angeles (us-west2)", value: "us-west2" },
49+
{
50+
text: "Montréal (northamerica-northeast1)",
51+
value: "northamerica-northeast1"
52+
},
53+
{ text: "Northern Virginia (us-east4)", value: "us-east4" },
54+
{ text: "São Paulo (southamerica-east1)", value: "southamerica-east1" },
55+
{ text: "Finland (europe-north1)", value: "europe-north1" },
56+
{ text: "London (europe-west2)", value: "europe-west2" },
57+
{ text: "Frankfurt (europe-west3)", value: "europe-west3" },
58+
{ text: "Zürich (europe-west6)", value: "europe-west6" },
59+
{ text: "Hong Kong (asia-east2)", value: "asia-east2" },
60+
{ text: "Mumbai (asia-south1)", value: "asia-south1" },
61+
{ text: "Osaka (asia-northeast2)", value: "asia-northeast2" },
62+
{ text: "Taiwan (asia-east1)", value: "asia-east1" },
63+
{ text: "Tokyo (asia-northeast1)", value: "asia-northeast1" },
64+
{ text: "Singapore (asia-southeast1)", value: "asia-southeast1" },
65+
{ text: "Sydney (australia-southeast1)", value: "australia-southeast1" }
66+
];
3967
}
4068

4169
public onUpload(json) {

src/datasource.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export class BigQueryDatasource {
161161
private readonly url: string;
162162
private mixpanel;
163163
private runInProject: string;
164+
private processingLocation: string;
164165

165166
/** @ngInject */
166167
constructor(
@@ -194,6 +195,11 @@ export class BigQueryDatasource {
194195
this.jsonData.flatRateProject && this.jsonData.flatRateProject.length
195196
? this.jsonData.flatRateProject
196197
: this.projectName;
198+
this.processingLocation =
199+
this.jsonData.processingLocation &&
200+
this.jsonData.processingLocation.length
201+
? this.jsonData.processingLocation
202+
: undefined;
197203
}
198204

199205
public async query(options) {
@@ -472,10 +478,12 @@ export class BigQueryDatasource {
472478
private async doQueryRequest(query, requestId, maxRetries = 3) {
473479
const path = `v2/projects/${this.runInProject}/queries`;
474480
const url = this.url + `${this.baseUrl}${path}`;
481+
const location =
482+
this.queryModel.target.location || this.processingLocation || "US";
475483
return this.backendSrv
476484
.datasourceRequest({
477485
data: {
478-
location: this.queryModel.target.location,
486+
location,
479487
query,
480488
useLegacySql: false,
481489
useQueryCache: true
@@ -507,11 +515,13 @@ export class BigQueryDatasource {
507515
private async _waitForJobComplete(queryResults, requestId, jobId) {
508516
let sleepTimeMs = 100;
509517
console.log("New job id: ", jobId);
518+
const location =
519+
this.queryModel.target.location || this.processingLocation || "US";
510520
const path =
511521
`v2/projects/${this.runInProject}/queries/` +
512522
jobId +
513523
"?location=" +
514-
this.queryModel.target.location;
524+
location;
515525
while (!queryResults.data.jobComplete) {
516526
await sleep(sleepTimeMs);
517527
sleepTimeMs *= 2;
@@ -524,13 +534,15 @@ export class BigQueryDatasource {
524534

525535
private async _getQueryResults(queryResults, rows, requestId, jobId) {
526536
while (queryResults.data.pageToken) {
537+
const location =
538+
this.queryModel.target.location || this.processingLocation || "US";
527539
const path =
528540
`v2/projects/${this.runInProject}/queries/` +
529541
jobId +
530542
"?pageToken=" +
531543
queryResults.data.pageToken +
532544
"&location=" +
533-
this.queryModel.target.location;
545+
location;
534546
queryResults = await this.doRequest(`${this.baseUrl}${path}`, requestId);
535547
if (queryResults.length === 0) {
536548
return rows;

src/partials/config.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ <h6>Uploaded Key Details</h6>
110110
The project that the Queries will be run in if you are using a flat-rate pricing model.
111111
</info-popover>
112112
</div>
113+
<div class="gf-form">
114+
<label class="gf-form-label">Processing Location</label>
115+
<div class="gf-form-select-wrapper">
116+
<select class="gf-form-input gf-size-auto" ng-model="ctrl.current.jsonData.processingLocation"
117+
ng-options="f.value as f.text for f in ctrl.locations"
118+
ng-change="ctrl.refresh()"></select>
119+
</div>
120+
</div>
113121
<gf-form-switch class="gf-form" label="Send anonymous usage data" label-class="width-13" checked="ctrl.current.jsonData.sendUsageData" switch-class="max-width-6"></gf-form-switch>
114122
<label class="gf-form-label query-keyword pointer">
115123
</label>

src/query_ctrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class BigQueryQueryCtrl extends QueryCtrl {
2626
public queryModel: BigQueryQuery;
2727
public lastQueryMeta: QueryMeta;
2828
public lastQueryError: string;
29-
public locations:any[];
29+
public locations: any[];
3030
public showHelp: boolean;
3131
public projectSegment: any;
3232
public datasetSegment: any;

0 commit comments

Comments
 (0)