Skip to content

Commit

Permalink
Fix for InfluxDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Leveille committed Aug 14, 2019
1 parent 1be83e5 commit a65b6d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
18 changes: 9 additions & 9 deletions check/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ var (
|> window(every: 1m)
|> unique(column: "fqn")
|> aggregateWindow(every: 1m, fn: count, columns: ["fqn"])`
influxdbQuery1Timeserie = `SELECT "value" FROM "randomint-1" WHERE ("worker" = '1' AND "node" = 'lg1') AND time >= now() - %s`
influxdbQuery100Timeseries = `SELECT "value" FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s`
influxdbQuery400Timeseries = `SELECT "value" FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s`
influxdbQuery1Timeserie = `SELECT "mean" FROM "1m"."randomint-1" WHERE ("worker" = '1' AND "node" = 'lg1') AND time >= now() - %s`
influxdbQuery100Timeseries = `SELECT "mean" FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s`
influxdbQuery400Timeseries = `SELECT "mean" FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s`
//find("lagrande.latency.lg1.*")|Stats:percentile(99)
influxdbQuery100TimeseriesP99 = `SELECT percentile("value", 99) FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s GROUP BY time(5s)`
influxdbQuery400TimeseriesP99 = `SELECT percentile("value", 99) FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s GROUP BY time(5s)`
influxdbQuery100TimeseriesMean = `SELECT mean("value") FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s GROUP BY time(5s)`
influxdbQuery400TimeseriesMean = `SELECT mean("value") FROM "randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s GROUP BY time(5s)`
influxdbQuery100TimeseriesP99 = `SELECT percentile("max", 99) FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s GROUP BY time(5s)`
influxdbQuery400TimeseriesP99 = `SELECT percentile("max", 99) FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s GROUP BY time(5s)`
influxdbQuery100TimeseriesMean = `SELECT mean("mean") FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" = 'lg1') AND time >= now() - %s GROUP BY time(5s)`
influxdbQuery400TimeseriesMean = `SELECT mean("mean") FROM "1m"."randomint-1" WHERE ("worker" =~ /1[0-9]{2}/ AND "node" =~ /lg[0-4]/) AND time >= now() - %s GROUP BY time(5s)`
)

// EvaluateInfluxDB will launch the AWS and InfluxDB queries to assess InfluxDB performances
Expand Down Expand Up @@ -63,8 +63,8 @@ func EvaluateInfluxDB() {
}
time.Sleep(2 * time.Second)

go datasource.GrafanaProxyInstance.FluxDBQuery("metrics-count", influxdbQueryMetricCount)
time.Sleep(2 * time.Second)
//go datasource.GrafanaProxyInstance.FluxDBQuery("metrics-count", influxdbQueryMetricCount)
//time.Sleep(2 * time.Second)
go datasource.GrafanaProxyInstance.SimpleInfluxDBQuery("1-ts-24-hour-range", influxdbQuery1Timeserie, "24h")
time.Sleep(2 * time.Second)
go datasource.GrafanaProxyInstance.SimpleInfluxDBQuery("1-ts-1-week-range", influxdbQuery1Timeserie, "7d")
Expand Down
9 changes: 7 additions & 2 deletions datasource/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var (
// Response body ~= "data":[[6000]],"meta"....
// Match everything from the double [[ until a ]
caqlResultRegex = regexp.MustCompile("data\":\\[\\[([^\\]]*)")
influxLastResultRegex = regexp.MustCompile(".*,([0-9]*)]]")
fluxLastResultRegex = regexp.MustCompile("(?s).*,([0-9]*)")
influxLastResultRegex = regexp.MustCompile(".*,\\[[0-9]*,([0-9\\.]*)\\]")
fluxLastResultRegex = regexp.MustCompile("(?s).*,([0-9\\.]*)")

// InfluxDB specific variables:
influxdbQueryURL = "%s/api/datasources/proxy/1/query?db=%s&q=%s%%20&epoch=%s" // Source 1 = InfluxDB current plugin (InfluxQL)
Expand Down Expand Up @@ -266,6 +266,10 @@ func (g *GrafanaProxy) doProxiedInfluxDBHTTPQuery(db string, queryString string,
match := influxLastResultRegex.FindStringSubmatch(stringBody)

if len(match) < 2 {
fmt.Println("No match error:")
fmt.Println(rangeQuery)
fmt.Println(stringBody)

return "nan", nil
}

Expand Down Expand Up @@ -342,6 +346,7 @@ func (g *GrafanaProxy) doProxiedFluxDBHTTPQuery(db string, queryString string) (
}

return match[1], nil

}

// {"query":"\ndashboardTime = -5m\nupperDashboardTime = 2019-07-24T20:32:04.653Z\n\nfrom(bucket: \"mydb/autogen\")\n |> range(start: -23m, stop: -3m)\n |> filter(fn: (r) => r.run == \"4\" and r.process == \"lagrande\" and (r._field == \"value\"))\n |> map(fn: (r) => ({\n _time: r._time,\n fqn: r.process + \".\" + r.node + \".\" + r._measurement + \".\" + r.worker\n }))\n |> keep(columns: [\"_time\", \"fqn\"])\n |> window(every: 1m)\n |> unique(column: \"fqn\")\n |> aggregateWindow(every: 1m, fn: count, columns: [\"fqn\"])","dialect":{"annotations":["group","datatype","default"]}}

0 comments on commit a65b6d5

Please sign in to comment.