Update rawtext in queryconfig to be null and not omitempty

pull/10616/head
Chris Goller 2017-04-07 17:32:10 -05:00
parent 0c32c53069
commit 313f7e94ca
8 changed files with 13 additions and 18 deletions

View File

@ -245,7 +245,7 @@ type QueryConfig struct {
Tags map[string][]string `json:"tags"`
GroupBy GroupBy `json:"groupBy"`
AreTagsAccepted bool `json:"areTagsAccepted"`
RawText string `json:"rawText,omitempty"`
RawText *string `json:"rawText"`
}
// KapacitorNode adds arguments and properties to an alert

View File

@ -15,7 +15,7 @@ func Convert(influxQL string) (chronograf.QueryConfig, error) {
}
raw := chronograf.QueryConfig{
RawText: influxQL,
RawText: &influxQL,
Fields: []chronograf.Field{},
GroupBy: chronograf.GroupBy{
Tags: []string{},

View File

@ -11,16 +11,17 @@ func TestConvert(t *testing.T) {
tests := []struct {
name string
influxQL string
RawText string
want chronograf.QueryConfig
wantErr bool
}{
{
name: "Test named count field",
influxQL: `SELECT moving_average(mean("count"),14) FROM "usage_computed"."autogen".unique_clusters_by_day WHERE time > now() - 90d AND product = 'influxdb' group by time(1d)`,
RawText: `SELECT moving_average(mean("count"),14) FROM "usage_computed"."autogen".unique_clusters_by_day WHERE time > now() - 90d AND product = 'influxdb' group by time(1d)`,
want: chronograf.QueryConfig{
RawText: `SELECT moving_average(mean("count"),14) FROM "usage_computed"."autogen".unique_clusters_by_day WHERE time > now() - 90d AND product = 'influxdb' group by time(1d)`,
Fields: []chronograf.Field{},
Tags: map[string][]string{},
Fields: []chronograf.Field{},
Tags: map[string][]string{},
GroupBy: chronograf.GroupBy{
Tags: []string{},
},
@ -34,6 +35,9 @@ func TestConvert(t *testing.T) {
t.Errorf("Convert() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.RawText != "" {
tt.want.RawText = &tt.RawText
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Convert() = %#v, want %#v", got, tt.want)
}

View File

@ -217,7 +217,7 @@ func (c *Client) kapaClient(ctx context.Context) (*client.Client, error) {
}
func toTask(q chronograf.QueryConfig) client.TaskType {
if q.RawText == "" {
if q.RawText == nil || *q.RawText == "" {
return client.StreamTask
}
return client.BatchTask

View File

@ -8,7 +8,7 @@ import (
// Data returns the tickscript data section for querying
func Data(rule chronograf.AlertRule) (string, error) {
if rule.Query.RawText != "" {
if rule.Query.RawText != nil && *rule.Query.RawText != "" {
batch := `
var data = batch
|query('''

View File

@ -44,7 +44,6 @@ func TestGenerate(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}
gen := Alert{}
@ -90,7 +89,6 @@ func TestThreshold(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}
@ -509,7 +507,6 @@ func TestThresholdDetail(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}
@ -657,7 +654,6 @@ func TestThresholdInsideRange(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}
@ -804,7 +800,6 @@ func TestThresholdOutsideRange(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}
@ -950,7 +945,6 @@ func TestThresholdNoAggregate(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}
@ -1088,7 +1082,6 @@ func TestRelative(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}
@ -1246,7 +1239,6 @@ func TestRelativeChange(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}
@ -1401,7 +1393,6 @@ func TestDeadman(t *testing.T) {
Tags: []string{"host", "cluster_id"},
},
AreTagsAccepted: true,
RawText: "",
},
}

View File

@ -246,7 +246,7 @@ func Test_newDashboardResponse(t *testing.T) {
{
Command: "SELECT donors from hill_valley_preservation_society where time > '1985-10-25 08:00:00'",
QueryConfig: chronograf.QueryConfig{
RawText: "SELECT donors from hill_valley_preservation_society where time > '1985-10-25 08:00:00'",
RawText: &[]string{"SELECT donors from hill_valley_preservation_society where time > '1985-10-25 08:00:00'"}[0],
Fields: []chronograf.Field{},
GroupBy: chronograf.GroupBy{
Tags: []string{},

View File

@ -14,7 +14,7 @@ func ToQueryConfig(query string) chronograf.QueryConfig {
return qc
}
return chronograf.QueryConfig{
RawText: query,
RawText: &query,
Fields: []chronograf.Field{},
GroupBy: chronograf.GroupBy{
Tags: []string{},