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

Commit

Permalink
Merge pull request #159 from doitintl/issue-157
Browse files Browse the repository at this point in the history
Fixes #157
  • Loading branch information
avivl authored Oct 31, 2019
2 parents 3307dd6 + 2fa7e11 commit 744e7d4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 30 deletions.
21 changes: 16 additions & 5 deletions dist/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -59057,6 +59057,7 @@ function () {
this.validationErrors = [];
this.defaultAuthenticationType = "jwt";
this.defaultSendUsageData = true;
this.defaultFlatRateProject = undefined;
this.datasourceSrv = datasourceSrv;
this.current.jsonData = this.current.jsonData || {};
this.current.jsonData.authenticationType = this.current.jsonData.authenticationType ? this.current.jsonData.authenticationType : this.defaultAuthenticationType;
Expand All @@ -59065,6 +59066,10 @@ function () {
this.current.jsonData.sendUsageData = this.defaultSendUsageData;
}

if (this.current.jsonData.flatRateProject === undefined) {
this.current.jsonData.flatRateProject = this.defaultFlatRateProject;
}

this.current.secureJsonData = this.current.secureJsonData || {};
this.current.secureJsonFields = this.current.secureJsonFields || {};
this.authenticationTypes = [{
Expand Down Expand Up @@ -59270,11 +59275,13 @@ function () {
})();

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

if (this.jsonData.sendUsageData !== false) {
this.mixpanel.init("86fa5c838013959cc6867dc884958f7e");
this.mixpanel.track("datasource.create");
}

this.runInProject = this.jsonData.flatRateProject && this.jsonData.flatRateProject.length ? this.jsonData.flatRateProject : this.projectName;
}

BigQueryDatasource.formatBigqueryError = function (error) {
Expand Down Expand Up @@ -59770,7 +59777,7 @@ function () {
BigQueryDatasource.prototype.annotationQuery = function (options) {
var _this = this;

var path = "v2/projects/" + this.projectName + "/queries";
var path = "v2/projects/" + this.runInProject + "/queries";
var url = this.url + ("" + this.baseUrl + path);

if (!options.annotation.rawQuery) {
Expand Down Expand Up @@ -59856,7 +59863,7 @@ function () {
var _this = this;

return tslib_1.__generator(this, function (_a) {
path = "v2/projects/" + this.projectName + "/queries";
path = "v2/projects/" + this.runInProject + "/queries";
url = this.url + ("" + this.baseUrl + path);
return [2
/*return*/
Expand Down Expand Up @@ -59884,6 +59891,10 @@ function () {
return _this.doQueryRequest(query, requestId, maxRetries - 1);
}

if (error.cancelled === true) {
return [];
}

return BigQueryDatasource._handleError(error);
})];
});
Expand All @@ -59898,7 +59909,7 @@ function () {
case 0:
sleepTimeMs = 100;
console.log("New job id: ", jobId);
path = "v2/projects/" + this.projectName + "/queries/" + jobId;
path = "v2/projects/" + this.runInProject + "/queries/" + jobId;
_a.label = 1;

case 1:
Expand Down Expand Up @@ -59943,7 +59954,7 @@ function () {
if (!queryResults.data.pageToken) return [3
/*break*/
, 2];
path = "v2/projects/" + this.projectName + "/queries/" + jobId + "?pageToken=" + queryResults.data.pageToken;
path = "v2/projects/" + this.runInProject + "/queries/" + jobId + "?pageToken=" + queryResults.data.pageToken;
return [4
/*yield*/
, this.doRequest("" + this.baseUrl + path, requestId)];
Expand Down
6 changes: 1 addition & 5 deletions dist/module.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dist/partials/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ <h6>Uploaded Key Details</h6>
<p class="gf-form-label" ng-hide="ctrl.current.secureJsonFields.privateKey || ctrl.current.jsonData.authenticationType !== ctrl.defaultAuthenticationType"><i
class="fa fa-save"></i> Do not forget to save your changes after uploading a file.</p>


<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>
<div class="gf-form max-width-30">
<span class="gf-form-label width-13">Flat Rate Project</span>
<input type="text" class="gf-form-input" ng-model='ctrl.current.jsonData.flatRateProject'></input>
<info-popover mode="right-absolute">
The project that the Queries will be run in if you are using a flat-rate pricing model.
</info-popover>
</div>
<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>
<label class="gf-form-label query-keyword pointer">
</label>

Expand Down
6 changes: 6 additions & 0 deletions src/config_ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export class BigQueryConfigCtrl {
private current: any;
private readonly defaultAuthenticationType: string;
private readonly defaultSendUsageData: boolean;
private readonly defaultFlatRateProject: string;

/** @ngInject */
constructor(datasourceSrv) {
this.defaultAuthenticationType = "jwt";
this.defaultSendUsageData = true;
this.defaultFlatRateProject = undefined;
this.datasourceSrv = datasourceSrv;
this.current.jsonData = this.current.jsonData || {};
this.current.jsonData.authenticationType = this.current.jsonData
Expand All @@ -25,6 +27,10 @@ export class BigQueryConfigCtrl {
if (this.current.jsonData.sendUsageData === undefined) {
this.current.jsonData.sendUsageData = this.defaultSendUsageData;
}
if (this.current.jsonData.flatRateProject === undefined) {
this.current.jsonData.flatRateProject = this.defaultFlatRateProject;
}

this.current.secureJsonData = this.current.secureJsonData || {};
this.current.secureJsonFields = this.current.secureJsonFields || {};
this.authenticationTypes = [
Expand Down
31 changes: 16 additions & 15 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export class BigQueryDatasource {
private readonly baseUrl: string;
private readonly url: string;
private mixpanel;
private runInProject: string;

/** @ngInject */
constructor(
Expand Down Expand Up @@ -174,6 +175,10 @@ export class BigQueryDatasource {
this.mixpanel.init("86fa5c838013959cc6867dc884958f7e");
this.mixpanel.track("datasource.create");
}
this.runInProject =
this.jsonData.flatRateProject && this.jsonData.flatRateProject.length
? this.jsonData.flatRateProject
: this.projectName;
}

public async query(options) {
Expand Down Expand Up @@ -242,31 +247,27 @@ export class BigQueryDatasource {
return ResponseParser.parseDataQuery(response, query.format);
});
});
return this.$q.all(allQueryPromise).then(
(responses): any => {
return this.$q.all(allQueryPromise).then((responses): any => {
const data = [];
for (const response of responses) {
if (response.type && response.type === "table") {
data.push(response);
for (const response of responses) {
if (response.type && response.type === "table") {
data.push(response);
} else {
for (const dp of response) {
data.push(dp);
}
}
}
}
for (const d of data) {
if (
typeof d.target !== "undefined" &&
d.target.search(Shifted) > -1
) {
if (typeof d.target !== "undefined" && d.target.search(Shifted) > -1) {
const res = BigQueryDatasource._getShiftPeriod(
d.target.substring(d.target.lastIndexOf("_") + 1, d.target.length)
);
const shiftPeriod = res[0];
const shiftVal = res[1];
for(let i = 0; i < d.datapoints.length; i++){
d.datapoints[i][1] = moment(d.datapoints[i][1])
.subtract(shiftVal, shiftPeriod)
.subtract(shiftVal, shiftPeriod)
.valueOf();
}
}
Expand Down Expand Up @@ -388,7 +389,7 @@ export class BigQueryDatasource {
}

public annotationQuery(options) {
const path = `v2/projects/${this.projectName}/queries`;
const path = `v2/projects/${this.runInProject}/queries`;
const url = this.url + `${this.baseUrl}${path}`;
if (!options.annotation.rawQuery) {
return this.$q.reject({
Expand Down Expand Up @@ -452,7 +453,7 @@ export class BigQueryDatasource {
}

private async doQueryRequest(query, requestId, maxRetries = 3) {
const path = `v2/projects/${this.projectName}/queries`;
const path = `v2/projects/${this.runInProject}/queries`;
const url = this.url + `${this.baseUrl}${path}`;
return this.backendSrv
.datasourceRequest({
Expand Down Expand Up @@ -488,7 +489,7 @@ export class BigQueryDatasource {
private async _waitForJobComplete(queryResults, requestId, jobId) {
let sleepTimeMs = 100;
console.log("New job id: ", jobId);
const path = `v2/projects/${this.projectName}/queries/` + jobId;
const path = `v2/projects/${this.runInProject}/queries/` + jobId;
while (!queryResults.data.jobComplete) {
await sleep(sleepTimeMs);
sleepTimeMs *= 2;
Expand All @@ -502,7 +503,7 @@ export class BigQueryDatasource {
private async _getQueryResults(queryResults, rows, requestId, jobId) {
while (queryResults.data.pageToken) {
const path =
`v2/projects/${this.projectName}/queries/` +
`v2/projects/${this.runInProject}/queries/` +
jobId +
"?pageToken=" +
queryResults.data.pageToken;
Expand Down
10 changes: 8 additions & 2 deletions src/partials/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ <h6>Uploaded Key Details</h6>
<p class="gf-form-label" ng-hide="ctrl.current.secureJsonFields.privateKey || ctrl.current.jsonData.authenticationType !== ctrl.defaultAuthenticationType"><i
class="fa fa-save"></i> Do not forget to save your changes after uploading a file.</p>


<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>
<div class="gf-form max-width-30">
<span class="gf-form-label width-13">Flat Rate Project</span>
<input type="text" class="gf-form-input" ng-model='ctrl.current.jsonData.flatRateProject'></input>
<info-popover mode="right-absolute">
The project that the Queries will be run in if you are using a flat-rate pricing model.
</info-popover>
</div>
<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>
<label class="gf-form-label query-keyword pointer">
</label>

Expand Down
5 changes: 4 additions & 1 deletion src/specs/datasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import ResponseParser, { IResultFormat } from "../response_parser";
describe("BigQueryDatasource", () => {
const instanceSettings = {
name: "bigquery",
jsonData: { authenticationType: "jwt", sendUsageData: false }
jsonData: {
authenticationType: "jwt",
sendUsageData: false,
}
};
const backendSrv = {};
const templateSrv = {
Expand Down

0 comments on commit 744e7d4

Please sign in to comment.