From 2a494b4f75327e43080a666e9bc928808352d579 Mon Sep 17 00:00:00 2001 From: Christopher Henn Date: Tue, 19 Jun 2018 14:45:47 -0700 Subject: [PATCH] Support persisting "influxql" template variables --- chronograf.go | 4 ++-- influx/templates.go | 2 +- server/templates.go | 8 ++++---- ui/src/types/tempVars.ts | 3 +-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/chronograf.go b/chronograf.go index 3faeabe03..1fed8dbbb 100644 --- a/chronograf.go +++ b/chronograf.go @@ -159,7 +159,7 @@ type Range struct { // TemplateValue is a value use to replace a template in an InfluxQL query type TemplateValue struct { Value string `json:"value"` // Value is the specific value used to replace a template in an InfluxQL query - Type string `json:"type"` // Type can be tagKey, tagValue, fieldKey, csv, measurement, database, constant + Type string `json:"type"` // Type can be tagKey, tagValue, fieldKey, csv, measurement, database, constant, influxql Selected bool `json:"selected"` // Selected states that this variable has been picked to use for replacement Key string `json:"key,omitempty"` // Key is the key for the Value if the Template Type is 'map' } @@ -177,7 +177,7 @@ type TemplateID string type Template struct { TemplateVar ID TemplateID `json:"id"` // ID is the unique ID associated with this template - Type string `json:"type"` // Type can be fieldKeys, tagKeys, tagValues, CSV, constant, query, measurements, databases, map + Type string `json:"type"` // Type can be fieldKeys, tagKeys, tagValues, CSV, constant, query, measurements, databases, map, influxql Label string `json:"label"` // Label is a user-facing description of the Template Query *TemplateQuery `json:"query,omitempty"` // Query is used to generate the choices for a template } diff --git a/influx/templates.go b/influx/templates.go index fe6a24a40..86168f772 100644 --- a/influx/templates.go +++ b/influx/templates.go @@ -72,7 +72,7 @@ func RenderTemplate(query string, t chronograf.TemplateVar, now time.Time) (stri return strings.Replace(q, t.Var, `"`+t.Values[0].Value+`"`, -1), nil case "tagValue", "timeStamp": return strings.Replace(q, t.Var, `'`+t.Values[0].Value+`'`, -1), nil - case "csv", "constant": + case "csv", "constant", "influxql": return strings.Replace(q, t.Var, t.Values[0].Value, -1), nil } diff --git a/server/templates.go b/server/templates.go index e70c1dab9..41109b35d 100644 --- a/server/templates.go +++ b/server/templates.go @@ -15,14 +15,14 @@ func ValidTemplateRequest(template *chronograf.Template) error { switch template.Type { default: return fmt.Errorf("Unknown template type %s", template.Type) - case "query", "constant", "csv", "fieldKeys", "tagKeys", "tagValues", "measurements", "databases", "map": + case "query", "constant", "csv", "fieldKeys", "tagKeys", "tagValues", "measurements", "databases", "map", "influxql": } for _, v := range template.Values { switch v.Type { default: return fmt.Errorf("Unknown template variable type %s", v.Type) - case "csv", "fieldKey", "tagKey", "tagValue", "measurement", "database", "constant": + case "csv", "fieldKey", "tagKey", "tagValue", "measurement", "database", "constant", "influxql": } if template.Type == "map" && v.Key == "" { @@ -30,8 +30,8 @@ func ValidTemplateRequest(template *chronograf.Template) error { } } - if template.Type == "query" && template.Query == nil { - return fmt.Errorf("No query set for template of type 'query'") + if template.Type == "influxql" && template.Query == nil { + return fmt.Errorf("No query set for template of type 'influxql'") } return nil diff --git a/ui/src/types/tempVars.ts b/ui/src/types/tempVars.ts index 9d49f4a41..c51599edf 100644 --- a/ui/src/types/tempVars.ts +++ b/ui/src/types/tempVars.ts @@ -34,9 +34,8 @@ export enum TemplateType { TagKeys = 'tagKeys', TagValues = 'tagValues', CSV = 'csv', - Query = 'query', Databases = 'databases', - MetaQuery = 'metaQuery', + MetaQuery = 'influxql', } export interface Template {