Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions dist/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function (angular, _, dateMath, moment) {
instanceSettings.jsonData = instanceSettings.jsonData || {};
this.supportMetrics = true;
this.periodGranularity = instanceSettings.jsonData.periodGranularity;
this.periodOrigin = instanceSettings.jsonData.periodOrigin;

function replaceTemplateValues(obj,scopedVars, attrList) {
if (obj.type === 'in') {
Expand Down Expand Up @@ -60,6 +61,20 @@ function (angular, _, dateMath, moment) {
['year', moment.duration(1, 'year')]
];

var GRANULARITIESPERIODLOOKUP = {
'second': 'P1S',
'minute': 'P0H1M',
'fifteen_minute': 'P0H15M',
'thirty_minute': 'P0H30M',
'hour': 'P1H',
'day': 'P1D',
'week': 'P7D',
'month': 'P1M',
'quarter': 'P3M',
'year': 'P1Y'
};


var filterTemplateExpanders = {
"selector": _.partialRight(replaceTemplateValues, ['value']),
"regex": _.partialRight(replaceTemplateValues, ['pattern']),
Expand All @@ -81,11 +96,22 @@ function (angular, _, dateMath, moment) {
};

this.testDatasource = function() {
if(this.periodOrigin!=""){
if(!this.isIsoDate(this.periodOrigin)){
return { status: "error", message: "Origin time must be in ISO8601 (YYYY-MM-DDTHH:MM:SS.sssZ) format", title: "Error" };
}
}
return this._get('/druid/v2/datasources').then(function () {
return { status: "success", message: "Druid Data source is working", title: "Success" };
});
};

this.isIsoDate = function(str) {
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(str)) return false;
var d = new Date(str);
return d.toISOString()===str;
};

//Get list of available datasources
this.getDataSources = function() {
return this._get('/druid/v2/datasources').then(function (response) {
Expand Down Expand Up @@ -159,9 +185,12 @@ function (angular, _, dateMath, moment) {
//Round up to start of an interval
//Width of bar chars in Grafana is determined by size of the smallest interval
var roundedFrom = granularity === "all" ? from : roundUpStartTime(from, granularity);
if(dataSource.periodGranularity!=""){
if(granularity==='day'){
granularity = {"type": "period", "period": "P1D", "timeZone": dataSource.periodGranularity}
if (dataSource.periodGranularity != "") {
if(granularity in GRANULARITIESPERIODLOOKUP){
granularity = {"type": "period", "period": GRANULARITIESPERIODLOOKUP[granularity], "timeZone": dataSource.periodGranularity}
if (dataSource.periodOrigin != "") {
granularity["origin"] = dataSource.periodOrigin
}
}
}
return dataSource._doQuery(roundedFrom, to, granularity, target, options.scopedVars);
Expand Down
12 changes: 11 additions & 1 deletion dist/partials/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="gf-form-group">
<h3 class="page-heading">Druid Settings</h3>
<div class="gf-form max-width-70">
<span class="gf-form-label">Period Granularity</span>
<span class="gf-form-label width-10">Period Granularity</span>
<div class="gf-form-select-wrapper gf-form-select-wrapper--has-help-icon max-width-50">
<select class="gf-form-input" ng-model="ctrl.current.jsonData.periodGranularity"
spellcheck='false'>
Expand Down Expand Up @@ -119,6 +119,16 @@ <h3 class="page-heading">Druid Settings</h3>
<info-popover mode="right-absolute">This enables the to query hourly data in different timezone.</info-popover>
</div>
</div>
<div class="gf-form max-width-30">
<label class="gf-form-label width-10">
Period Origin
</label>
<input type="text" class="gf-form-input" ng-model="ctrl.current.jsonData.periodOrigin" spellcheck='false'>
<info-popover mode="right-absolute">This enables the to query to compute from a different epoch start, useful to
start week from Sunday.
</info-popover>
</input>
</div>
</div>


35 changes: 32 additions & 3 deletions src/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function (angular, _, dateMath, moment) {
instanceSettings.jsonData = instanceSettings.jsonData || {};
this.supportMetrics = true;
this.periodGranularity = instanceSettings.jsonData.periodGranularity;
this.periodOrigin = instanceSettings.jsonData.periodOrigin;

function replaceTemplateValues(obj,scopedVars, attrList) {
if (obj.type === 'in') {
Expand Down Expand Up @@ -60,6 +61,20 @@ function (angular, _, dateMath, moment) {
['year', moment.duration(1, 'year')]
];

var GRANULARITIESPERIODLOOKUP = {
'second': 'P1S',
'minute': 'P0H1M',
'fifteen_minute': 'P0H15M',
'thirty_minute': 'P0H30M',
'hour': 'P1H',
'day': 'P1D',
'week': 'P7D',
'month': 'P1M',
'quarter': 'P3M',
'year': 'P1Y'
};


var filterTemplateExpanders = {
"selector": _.partialRight(replaceTemplateValues, ['value']),
"regex": _.partialRight(replaceTemplateValues, ['pattern']),
Expand All @@ -81,11 +96,22 @@ function (angular, _, dateMath, moment) {
};

this.testDatasource = function() {
if(this.periodOrigin!=""){
if(!this.isIsoDate(this.periodOrigin)){
return { status: "error", message: "Origin time must be in ISO8601 (YYYY-MM-DDTHH:MM:SS.sssZ) format", title: "Error" };
}
}
return this._get('/druid/v2/datasources').then(function () {
return { status: "success", message: "Druid Data source is working", title: "Success" };
});
};

this.isIsoDate = function(str) {
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(str)) return false;
var d = new Date(str);
return d.toISOString()===str;
};

//Get list of available datasources
this.getDataSources = function() {
return this._get('/druid/v2/datasources').then(function (response) {
Expand Down Expand Up @@ -159,9 +185,12 @@ function (angular, _, dateMath, moment) {
//Round up to start of an interval
//Width of bar chars in Grafana is determined by size of the smallest interval
var roundedFrom = granularity === "all" ? from : roundUpStartTime(from, granularity);
if(dataSource.periodGranularity!=""){
if(granularity==='day'){
granularity = {"type": "period", "period": "P1D", "timeZone": dataSource.periodGranularity}
if (dataSource.periodGranularity != "") {
if(granularity in GRANULARITIESPERIODLOOKUP){
granularity = {"type": "period", "period": GRANULARITIESPERIODLOOKUP[granularity], "timeZone": dataSource.periodGranularity}
if (dataSource.periodOrigin != "") {
granularity["origin"] = dataSource.periodOrigin
}
}
}
return dataSource._doQuery(roundedFrom, to, granularity, target, options.scopedVars);
Expand Down
12 changes: 11 additions & 1 deletion src/partials/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="gf-form-group">
<h3 class="page-heading">Druid Settings</h3>
<div class="gf-form max-width-70">
<span class="gf-form-label">Period Granularity</span>
<span class="gf-form-label width-10">Period Granularity</span>
<div class="gf-form-select-wrapper gf-form-select-wrapper--has-help-icon max-width-50">
<select class="gf-form-input" ng-model="ctrl.current.jsonData.periodGranularity"
spellcheck='false'>
Expand Down Expand Up @@ -119,6 +119,16 @@ <h3 class="page-heading">Druid Settings</h3>
<info-popover mode="right-absolute">This enables the to query hourly data in different timezone.</info-popover>
</div>
</div>
<div class="gf-form max-width-30">
<label class="gf-form-label width-10">
Period Origin
</label>
<input type="text" class="gf-form-input" ng-model="ctrl.current.jsonData.periodOrigin" spellcheck='false'>
<info-popover mode="right-absolute">This enables the to query to compute from a different epoch start, useful to
start week from Sunday.
</info-popover>
</input>
</div>
</div>