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

Commit 744e7d4

Browse files
authored
Merge pull request #159 from doitintl/issue-157
Fixes #157
2 parents 3307dd6 + 2fa7e11 commit 744e7d4

File tree

7 files changed

+59
-30
lines changed

7 files changed

+59
-30
lines changed

dist/module.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59057,6 +59057,7 @@ function () {
5905759057
this.validationErrors = [];
5905859058
this.defaultAuthenticationType = "jwt";
5905959059
this.defaultSendUsageData = true;
59060+
this.defaultFlatRateProject = undefined;
5906059061
this.datasourceSrv = datasourceSrv;
5906159062
this.current.jsonData = this.current.jsonData || {};
5906259063
this.current.jsonData.authenticationType = this.current.jsonData.authenticationType ? this.current.jsonData.authenticationType : this.defaultAuthenticationType;
@@ -59065,6 +59066,10 @@ function () {
5906559066
this.current.jsonData.sendUsageData = this.defaultSendUsageData;
5906659067
}
5906759068

59069+
if (this.current.jsonData.flatRateProject === undefined) {
59070+
this.current.jsonData.flatRateProject = this.defaultFlatRateProject;
59071+
}
59072+
5906859073
this.current.secureJsonData = this.current.secureJsonData || {};
5906959074
this.current.secureJsonFields = this.current.secureJsonFields || {};
5907059075
this.authenticationTypes = [{
@@ -59270,11 +59275,13 @@ function () {
5927059275
})();
5927159276

5927259277
this.mixpanel = __webpack_require__(/*! mixpanel-browser */ "../node_modules/mixpanel-browser/build/mixpanel.cjs.js");
59273-
this.mixpanel.init("86fa5c838013959cc6867dc884958f7e");
5927459278

5927559279
if (this.jsonData.sendUsageData !== false) {
59280+
this.mixpanel.init("86fa5c838013959cc6867dc884958f7e");
5927659281
this.mixpanel.track("datasource.create");
5927759282
}
59283+
59284+
this.runInProject = this.jsonData.flatRateProject && this.jsonData.flatRateProject.length ? this.jsonData.flatRateProject : this.projectName;
5927859285
}
5927959286

5928059287
BigQueryDatasource.formatBigqueryError = function (error) {
@@ -59770,7 +59777,7 @@ function () {
5977059777
BigQueryDatasource.prototype.annotationQuery = function (options) {
5977159778
var _this = this;
5977259779

59773-
var path = "v2/projects/" + this.projectName + "/queries";
59780+
var path = "v2/projects/" + this.runInProject + "/queries";
5977459781
var url = this.url + ("" + this.baseUrl + path);
5977559782

5977659783
if (!options.annotation.rawQuery) {
@@ -59856,7 +59863,7 @@ function () {
5985659863
var _this = this;
5985759864

5985859865
return tslib_1.__generator(this, function (_a) {
59859-
path = "v2/projects/" + this.projectName + "/queries";
59866+
path = "v2/projects/" + this.runInProject + "/queries";
5986059867
url = this.url + ("" + this.baseUrl + path);
5986159868
return [2
5986259869
/*return*/
@@ -59884,6 +59891,10 @@ function () {
5988459891
return _this.doQueryRequest(query, requestId, maxRetries - 1);
5988559892
}
5988659893

59894+
if (error.cancelled === true) {
59895+
return [];
59896+
}
59897+
5988759898
return BigQueryDatasource._handleError(error);
5988859899
})];
5988959900
});
@@ -59898,7 +59909,7 @@ function () {
5989859909
case 0:
5989959910
sleepTimeMs = 100;
5990059911
console.log("New job id: ", jobId);
59901-
path = "v2/projects/" + this.projectName + "/queries/" + jobId;
59912+
path = "v2/projects/" + this.runInProject + "/queries/" + jobId;
5990259913
_a.label = 1;
5990359914

5990459915
case 1:
@@ -59943,7 +59954,7 @@ function () {
5994359954
if (!queryResults.data.pageToken) return [3
5994459955
/*break*/
5994559956
, 2];
59946-
path = "v2/projects/" + this.projectName + "/queries/" + jobId + "?pageToken=" + queryResults.data.pageToken;
59957+
path = "v2/projects/" + this.runInProject + "/queries/" + jobId + "?pageToken=" + queryResults.data.pageToken;
5994759958
return [4
5994859959
/*yield*/
5994959960
, this.doRequest("" + this.baseUrl + path, requestId)];

dist/module.js.map

Lines changed: 1 addition & 5 deletions
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,14 @@ <h6>Uploaded Key Details</h6>
103103
<p class="gf-form-label" ng-hide="ctrl.current.secureJsonFields.privateKey || ctrl.current.jsonData.authenticationType !== ctrl.defaultAuthenticationType"><i
104104
class="fa fa-save"></i> Do not forget to save your changes after uploading a file.</p>
105105

106-
107-
<gf-form-switch class="gf-form" label="Send anonymous usage data" label-class="width-9" checked="ctrl.current.jsonData.sendUsageData" switch-class="max-width-6"></gf-form-switch>
106+
<div class="gf-form max-width-30">
107+
<span class="gf-form-label width-13">Flat Rate Project</span>
108+
<input type="text" class="gf-form-input" ng-model='ctrl.current.jsonData.flatRateProject'></input>
109+
<info-popover mode="right-absolute">
110+
The project that the Queries will be run in if you are using a flat-rate pricing model.
111+
</info-popover>
112+
</div>
113+
<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>
108114
<label class="gf-form-label query-keyword pointer">
109115
</label>
110116

src/config_ctrl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ export class BigQueryConfigCtrl {
1111
private current: any;
1212
private readonly defaultAuthenticationType: string;
1313
private readonly defaultSendUsageData: boolean;
14+
private readonly defaultFlatRateProject: string;
1415

1516
/** @ngInject */
1617
constructor(datasourceSrv) {
1718
this.defaultAuthenticationType = "jwt";
1819
this.defaultSendUsageData = true;
20+
this.defaultFlatRateProject = undefined;
1921
this.datasourceSrv = datasourceSrv;
2022
this.current.jsonData = this.current.jsonData || {};
2123
this.current.jsonData.authenticationType = this.current.jsonData
@@ -25,6 +27,10 @@ export class BigQueryConfigCtrl {
2527
if (this.current.jsonData.sendUsageData === undefined) {
2628
this.current.jsonData.sendUsageData = this.defaultSendUsageData;
2729
}
30+
if (this.current.jsonData.flatRateProject === undefined) {
31+
this.current.jsonData.flatRateProject = this.defaultFlatRateProject;
32+
}
33+
2834
this.current.secureJsonData = this.current.secureJsonData || {};
2935
this.current.secureJsonFields = this.current.secureJsonFields || {};
3036
this.authenticationTypes = [

src/datasource.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class BigQueryDatasource {
145145
private readonly baseUrl: string;
146146
private readonly url: string;
147147
private mixpanel;
148+
private runInProject: string;
148149

149150
/** @ngInject */
150151
constructor(
@@ -174,6 +175,10 @@ export class BigQueryDatasource {
174175
this.mixpanel.init("86fa5c838013959cc6867dc884958f7e");
175176
this.mixpanel.track("datasource.create");
176177
}
178+
this.runInProject =
179+
this.jsonData.flatRateProject && this.jsonData.flatRateProject.length
180+
? this.jsonData.flatRateProject
181+
: this.projectName;
177182
}
178183

179184
public async query(options) {
@@ -242,31 +247,27 @@ export class BigQueryDatasource {
242247
return ResponseParser.parseDataQuery(response, query.format);
243248
});
244249
});
245-
return this.$q.all(allQueryPromise).then(
246-
(responses): any => {
250+
return this.$q.all(allQueryPromise).then((responses): any => {
247251
const data = [];
248-
for (const response of responses) {
249-
if (response.type && response.type === "table") {
250-
data.push(response);
252+
for (const response of responses) {
253+
if (response.type && response.type === "table") {
254+
data.push(response);
251255
} else {
252256
for (const dp of response) {
253257
data.push(dp);
254258
}
255-
}
256259
}
260+
}
257261
for (const d of data) {
258-
if (
259-
typeof d.target !== "undefined" &&
260-
d.target.search(Shifted) > -1
261-
) {
262+
if (typeof d.target !== "undefined" && d.target.search(Shifted) > -1) {
262263
const res = BigQueryDatasource._getShiftPeriod(
263264
d.target.substring(d.target.lastIndexOf("_") + 1, d.target.length)
264265
);
265266
const shiftPeriod = res[0];
266267
const shiftVal = res[1];
267268
for(let i = 0; i < d.datapoints.length; i++){
268269
d.datapoints[i][1] = moment(d.datapoints[i][1])
269-
.subtract(shiftVal, shiftPeriod)
270+
.subtract(shiftVal, shiftPeriod)
270271
.valueOf();
271272
}
272273
}
@@ -388,7 +389,7 @@ export class BigQueryDatasource {
388389
}
389390

390391
public annotationQuery(options) {
391-
const path = `v2/projects/${this.projectName}/queries`;
392+
const path = `v2/projects/${this.runInProject}/queries`;
392393
const url = this.url + `${this.baseUrl}${path}`;
393394
if (!options.annotation.rawQuery) {
394395
return this.$q.reject({
@@ -452,7 +453,7 @@ export class BigQueryDatasource {
452453
}
453454

454455
private async doQueryRequest(query, requestId, maxRetries = 3) {
455-
const path = `v2/projects/${this.projectName}/queries`;
456+
const path = `v2/projects/${this.runInProject}/queries`;
456457
const url = this.url + `${this.baseUrl}${path}`;
457458
return this.backendSrv
458459
.datasourceRequest({
@@ -488,7 +489,7 @@ export class BigQueryDatasource {
488489
private async _waitForJobComplete(queryResults, requestId, jobId) {
489490
let sleepTimeMs = 100;
490491
console.log("New job id: ", jobId);
491-
const path = `v2/projects/${this.projectName}/queries/` + jobId;
492+
const path = `v2/projects/${this.runInProject}/queries/` + jobId;
492493
while (!queryResults.data.jobComplete) {
493494
await sleep(sleepTimeMs);
494495
sleepTimeMs *= 2;
@@ -502,7 +503,7 @@ export class BigQueryDatasource {
502503
private async _getQueryResults(queryResults, rows, requestId, jobId) {
503504
while (queryResults.data.pageToken) {
504505
const path =
505-
`v2/projects/${this.projectName}/queries/` +
506+
`v2/projects/${this.runInProject}/queries/` +
506507
jobId +
507508
"?pageToken=" +
508509
queryResults.data.pageToken;

src/partials/config.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,14 @@ <h6>Uploaded Key Details</h6>
103103
<p class="gf-form-label" ng-hide="ctrl.current.secureJsonFields.privateKey || ctrl.current.jsonData.authenticationType !== ctrl.defaultAuthenticationType"><i
104104
class="fa fa-save"></i> Do not forget to save your changes after uploading a file.</p>
105105

106-
107-
<gf-form-switch class="gf-form" label="Send anonymous usage data" label-class="width-9" checked="ctrl.current.jsonData.sendUsageData" switch-class="max-width-6"></gf-form-switch>
106+
<div class="gf-form max-width-30">
107+
<span class="gf-form-label width-13">Flat Rate Project</span>
108+
<input type="text" class="gf-form-input" ng-model='ctrl.current.jsonData.flatRateProject'></input>
109+
<info-popover mode="right-absolute">
110+
The project that the Queries will be run in if you are using a flat-rate pricing model.
111+
</info-popover>
112+
</div>
113+
<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>
108114
<label class="gf-form-label query-keyword pointer">
109115
</label>
110116

src/specs/datasource.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import ResponseParser, { IResultFormat } from "../response_parser";
66
describe("BigQueryDatasource", () => {
77
const instanceSettings = {
88
name: "bigquery",
9-
jsonData: { authenticationType: "jwt", sendUsageData: false }
9+
jsonData: {
10+
authenticationType: "jwt",
11+
sendUsageData: false,
12+
}
1013
};
1114
const backendSrv = {};
1215
const templateSrv = {

0 commit comments

Comments
 (0)