Skip to content

Commit

Permalink
added support for weekly aggregates with period origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravshah committed Nov 1, 2019
1 parent 3de0539 commit 0384d55
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 38 deletions.
33 changes: 21 additions & 12 deletions dist/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ function (angular, _, dateMath, moment) {
['year', moment.duration(1, 'year')]
];

var GRANULARITIESPERIODLOOKUP = {
'second': '1S',
'minute': '0H1M',
'fifteen_minute': '0H15M',
'thirty_minute': '0H30M',
'hour': '1H',
'day': '1D',
'week': '7D',
'month': '1M',
'quarter': '3M',
'year': '1Y'

This comment has been minimized.

Copy link
@ShilpaSivanesan

ShilpaSivanesan Nov 2, 2019

All the values in GRANULARITIESPERIODLOOKUP should start with period P, like P1D, P7D

This comment has been minimized.

Copy link
@Gauravshah

Gauravshah Nov 2, 2019

Author Member

👍

};


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

this.testDatasource = function() {
if(this.dataSource.periodOrigin!=""){
if(!this.isIsoDate(this.dataSource.periodOrigin)){
return { status: "error", message: "Origin time must be in ISO8601 format", title: "Success" };
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 () {
Expand Down Expand Up @@ -172,17 +186,12 @@ function (angular, _, dateMath, moment) {
//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 != "") {
granularity = {"type": "period", "timeZone": dataSource.periodGranularity}
if (granularity === 'day') {
granularity["period"] = "P1D"
} else if (granularity === 'week') {
granularity["period"] = "P1W"
} else if (granularity === 'month') {
granularity["period"] = "P1M"
}
if(granularity in GRANULARITIESPERIODLOOKUP){
granularity = {"type": "period", "period": GRANULARITIESPERIODLOOKUP[granularity], "timeZone": dataSource.periodGranularity}
if (dataSource.periodOrigin != "") {
granularity["origin"] = dataSource.periodOrigin
granularity["origin"] = dataSource.periodOrigin
}
}
}
return dataSource._doQuery(roundedFrom, to, granularity, target, options.scopedVars);
});
Expand Down
17 changes: 10 additions & 7 deletions 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,12 +119,15 @@ <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-70">
<span class="gf-form-label">Period Origin</span>
<div class="gf-form-select-wrapper gf-form-select-wrapper--has-help-icon max-width-50">
<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>
</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>

Expand Down
33 changes: 21 additions & 12 deletions src/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ function (angular, _, dateMath, moment) {
['year', moment.duration(1, 'year')]
];

var GRANULARITIESPERIODLOOKUP = {
'second': '1S',
'minute': '0H1M',
'fifteen_minute': '0H15M',
'thirty_minute': '0H30M',
'hour': '1H',
'day': '1D',
'week': '7D',
'month': '1M',
'quarter': '3M',
'year': '1Y'
};


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

this.testDatasource = function() {
if(this.dataSource.periodOrigin!=""){
if(!this.isIsoDate(this.dataSource.periodOrigin)){
return { status: "error", message: "Origin time must be in ISO8601 format", title: "Success" };
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 () {
Expand Down Expand Up @@ -172,17 +186,12 @@ function (angular, _, dateMath, moment) {
//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 != "") {
granularity = {"type": "period", "timeZone": dataSource.periodGranularity}
if (granularity === 'day') {
granularity["period"] = "P1D"
} else if (granularity === 'week') {
granularity["period"] = "P1W"
} else if (granularity === 'month') {
granularity["period"] = "P1M"
}
if(granularity in GRANULARITIESPERIODLOOKUP){
granularity = {"type": "period", "period": GRANULARITIESPERIODLOOKUP[granularity], "timeZone": dataSource.periodGranularity}
if (dataSource.periodOrigin != "") {
granularity["origin"] = dataSource.periodOrigin
granularity["origin"] = dataSource.periodOrigin
}
}
}
return dataSource._doQuery(roundedFrom, to, granularity, target, options.scopedVars);
});
Expand Down
17 changes: 10 additions & 7 deletions 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,12 +119,15 @@ <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-70">
<span class="gf-form-label">Period Origin</span>
<div class="gf-form-select-wrapper gf-form-select-wrapper--has-help-icon max-width-50">
<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>
</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>

Expand Down

0 comments on commit 0384d55

Please sign in to comment.