Add hacks to make AGB work with the frontend

pull/10616/head
Tim Raymond 2017-06-09 15:53:55 -04:00
parent 5418592df8
commit a7cc6040d3
3 changed files with 35 additions and 8 deletions

View File

@ -179,15 +179,15 @@ func (t BasicTemplateVar) String() string {
}
type GroupByVar struct {
Var string `json:"tempVar"` // the name of the variable as present in the query
Duration time.Duration `json:"duration"` // the Duration supplied by the query
Resolution uint `json:"resolution"` // the available screen resolution to render the results of this query
ReportingInterval time.Duration `json:"reportingInterval"` // the interval at which data is reported to this series
Var string `json:"tempVar"` // the name of the variable as present in the query
Duration time.Duration `json:"duration,omitempty"` // the Duration supplied by the query
Resolution uint `json:"resolution"` // the available screen resolution to render the results of this query
ReportingInterval time.Duration `json:"reportingInterval,omitempty"` // the interval at which data is reported to this series
}
// Exec is responsible for extracting the Duration from the query
func (g *GroupByVar) Exec(query string) {
whereClause := "where time > now() - "
whereClause := "WHERE time > now() - "
start := strings.Index(query, whereClause)
if start == -1 {
// no where clause
@ -216,6 +216,12 @@ func (g *GroupByVar) Exec(query string) {
}
func (g *GroupByVar) String() string {
intervalNS := g.ReportingInterval.Nanoseconds()
// prevent division by zero
if intervalNS == 0 || g.Resolution == 0 {
return " "
}
//TODO(timraymond): ascertain group by resolution
duration := g.Duration.Nanoseconds() / g.ReportingInterval.Nanoseconds() * int64(g.Resolution)
return "group by time(" + strconv.Itoa(int(duration)/1000000) + "s)"
@ -285,6 +291,7 @@ func (t *TemplateVars) UnmarshalJSON(text []byte) error {
// ensure that we really have a GroupByVar
if agb.Resolution != 0 {
agb.ReportingInterval = 10 * time.Second
(*t) = append(*t, &agb)
continue
}

View File

@ -259,8 +259,17 @@ class DashboardPage extends Component {
],
}
const templatesIncludingDashTime =
(dashboard && dashboard.templates.concat(dashboardTime)) || []
const autoGroupBy = {
id: 'autoGroupBy',
type: 'constant',
tempVar: ':autoGroupBy:',
resolution: 1000,
values: [],
}
const templatesIncludingDashTime = (dashboard &&
dashboard.templates.concat(dashboardTime) &&
dashboard.templates.concat(autoGroupBy)) || []
const {selectedCell, isEditMode, isTemplating} = this.state

View File

@ -116,13 +116,24 @@ const AutoRefresh = ComposedComponent => {
const timeSeriesPromises = queries.map(query => {
const {host, database, rp} = query
const templatesWithResolution = templates.map((temp) => {
if (temp.tempVar === ':autoGroupBy:') {
if (resolution) {
return {...temp, resolution}
}
return {...temp, resolution: 1000}
}
return {...temp}
})
return fetchTimeSeriesAsync(
{
source: host,
db: database,
rp,
query,
tempVars: removeUnselectedTemplateValues(templates),
tempVars: removeUnselectedTemplateValues(templatesWithResolution),
resolution,
},
editQueryStatus