Add hacks to make AGB work with the frontend
parent
5418592df8
commit
a7cc6040d3
|
@ -180,14 +180,14 @@ func (t BasicTemplateVar) String() string {
|
||||||
|
|
||||||
type GroupByVar struct {
|
type GroupByVar struct {
|
||||||
Var string `json:"tempVar"` // the name of the variable as present in the query
|
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
|
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
|
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
|
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
|
// Exec is responsible for extracting the Duration from the query
|
||||||
func (g *GroupByVar) Exec(query string) {
|
func (g *GroupByVar) Exec(query string) {
|
||||||
whereClause := "where time > now() - "
|
whereClause := "WHERE time > now() - "
|
||||||
start := strings.Index(query, whereClause)
|
start := strings.Index(query, whereClause)
|
||||||
if start == -1 {
|
if start == -1 {
|
||||||
// no where clause
|
// no where clause
|
||||||
|
@ -216,6 +216,12 @@ func (g *GroupByVar) Exec(query string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupByVar) String() 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
|
//TODO(timraymond): ascertain group by resolution
|
||||||
duration := g.Duration.Nanoseconds() / g.ReportingInterval.Nanoseconds() * int64(g.Resolution)
|
duration := g.Duration.Nanoseconds() / g.ReportingInterval.Nanoseconds() * int64(g.Resolution)
|
||||||
return "group by time(" + strconv.Itoa(int(duration)/1000000) + "s)"
|
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
|
// ensure that we really have a GroupByVar
|
||||||
if agb.Resolution != 0 {
|
if agb.Resolution != 0 {
|
||||||
|
agb.ReportingInterval = 10 * time.Second
|
||||||
(*t) = append(*t, &agb)
|
(*t) = append(*t, &agb)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,8 +259,17 @@ class DashboardPage extends Component {
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
const templatesIncludingDashTime =
|
const autoGroupBy = {
|
||||||
(dashboard && dashboard.templates.concat(dashboardTime)) || []
|
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
|
const {selectedCell, isEditMode, isTemplating} = this.state
|
||||||
|
|
||||||
|
|
|
@ -116,13 +116,24 @@ const AutoRefresh = ComposedComponent => {
|
||||||
|
|
||||||
const timeSeriesPromises = queries.map(query => {
|
const timeSeriesPromises = queries.map(query => {
|
||||||
const {host, database, rp} = 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(
|
return fetchTimeSeriesAsync(
|
||||||
{
|
{
|
||||||
source: host,
|
source: host,
|
||||||
db: database,
|
db: database,
|
||||||
rp,
|
rp,
|
||||||
query,
|
query,
|
||||||
tempVars: removeUnselectedTemplateValues(templates),
|
tempVars: removeUnselectedTemplateValues(templatesWithResolution),
|
||||||
resolution,
|
resolution,
|
||||||
},
|
},
|
||||||
editQueryStatus
|
editQueryStatus
|
||||||
|
|
Loading…
Reference in New Issue