Skip to content

Commit

Permalink
Merged in rrk/query-gen-db-pkg (pull request timescale#56)
Browse files Browse the repository at this point in the history
Create a databases package inside tsbs_generate_queries

Approved-by: Lee Hampton <leejhampton@gmail.com>
  • Loading branch information
RobAtticus committed May 23, 2018
2 parents 0bf1f86 + 66cbf46 commit d6d845e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cassandra

import (
"fmt"
Expand All @@ -9,22 +9,22 @@ import (
"bitbucket.org/440-labs/influxdb-comparisons/query"
)

// CassandraDevops produces Cassandra-specific queries for all the devops query types.
type CassandraDevops struct {
// Devops produces Cassandra-specific queries for all the devops query types.
type Devops struct {
*devops.Core
}

// NewCassandraDevops makes an CassandraDevops object ready to generate Queries.
func newCassandraDevopsCommon(start, end time.Time, scale int) *CassandraDevops {
return &CassandraDevops{devops.NewCore(start, end, scale)}
// NewDevops makes an Devops object ready to generate Queries.
func NewDevops(start, end time.Time, scale int) *Devops {
return &Devops{devops.NewCore(start, end, scale)}
}

// GenerateEmptyQuery returns an empty query.Cassandra
func (d *CassandraDevops) GenerateEmptyQuery() query.Query {
func (d *Devops) GenerateEmptyQuery() query.Query {
return query.NewCassandra()
}

func (d *CassandraDevops) getHostWhere(nHosts int) []string {
func (d *Devops) getHostWhere(nHosts int) []string {
hostnames := d.GetRandomHosts(nHosts)

tagSet := []string{}
Expand All @@ -45,7 +45,7 @@ func (d *CassandraDevops) getHostWhere(nHosts int) []string {
// WHERE (hostname = '$HOSTNAME_1' OR ... OR hostname = '$HOSTNAME_N')
// AND time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY minute ORDER BY minute ASC
func (d *CassandraDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
func (d *Devops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
interval := d.Interval.RandWindow(timeRange)
metrics := devops.GetCPUMetricsSlice(numMetrics)
tagSet := d.getHostWhere(nHosts)
Expand Down Expand Up @@ -74,7 +74,7 @@ func (d *CassandraDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, ti
// WHERE time < '$TIME'
// GROUP BY t ORDER BY t DESC
// LIMIT $LIMIT
func (d *CassandraDevops) GroupByOrderByLimit(qi query.Query) {
func (d *Devops) GroupByOrderByLimit(qi query.Query) {
interval := d.Interval.RandWindow(time.Hour)

humanLabel := "Cassandra max cpu over last 5 min-intervals (random end)"
Expand All @@ -100,7 +100,7 @@ func (d *CassandraDevops) GroupByOrderByLimit(qi query.Query) {
// FROM cpu
// WHERE time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour, hostname ORDER BY hour
func (d *CassandraDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
func (d *Devops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
interval := d.Interval.RandWindow(devops.DoubleGroupByDuration)
metrics := devops.GetCPUMetricsSlice(numMetrics)

Expand All @@ -125,7 +125,7 @@ func (d *CassandraDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics in
// FROM cpu WHERE (hostname = '$HOSTNAME_1' OR ... OR hostname = '$HOSTNAME_N')
// AND time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour ORDER BY hour
func (d *CassandraDevops) MaxAllCPU(qi query.Query, nHosts int) {
func (d *Devops) MaxAllCPU(qi query.Query, nHosts int) {
interval := d.Interval.RandWindow(devops.MaxAllDuration)
tagSet := d.getHostWhere(nHosts)

Expand All @@ -149,7 +149,7 @@ func (d *CassandraDevops) MaxAllCPU(qi query.Query, nHosts int) {
}

// LastPointPerHost finds the last row for every host in the dataset
func (d *CassandraDevops) LastPointPerHost(qi query.Query) {
func (d *Devops) LastPointPerHost(qi query.Query) {
humanLabel := "Cassandra last row per host"
q := qi.(*query.Cassandra)
q.HumanLabel = []byte(humanLabel)
Expand All @@ -172,7 +172,7 @@ func (d *CassandraDevops) LastPointPerHost(qi query.Query) {
// WHERE usage_user > 90.0
// AND time >= '$TIME_START' AND time < '$TIME_END'
// AND (hostname = '$HOST' OR hostname = '$HOST2'...)
func (d *CassandraDevops) HighCPUForHosts(qi query.Query, nHosts int) {
func (d *Devops) HighCPUForHosts(qi query.Query, nHosts int) {
interval := d.Interval.RandWindow(devops.HighCPUDuration)
tagSet := d.getHostWhere(nHosts)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package influx

import (
"fmt"
Expand All @@ -10,22 +10,22 @@ import (
"bitbucket.org/440-labs/influxdb-comparisons/query"
)

// InfluxDevops produces Influx-specific queries for all the devops query types.
type InfluxDevops struct {
// Devops produces Influx-specific queries for all the devops query types.
type Devops struct {
*devops.Core
}

// NewInfluxDevops makes an InfluxDevops object ready to generate Queries.
func newInfluxDevopsCommon(start, end time.Time, scale int) *InfluxDevops {
return &InfluxDevops{devops.NewCore(start, end, scale)}
// NewDevops makes an Devops object ready to generate Queries.
func NewDevops(start, end time.Time, scale int) *Devops {
return &Devops{devops.NewCore(start, end, scale)}
}

// GenerateEmptyQuery returns an empty query.HTTP
func (d *InfluxDevops) GenerateEmptyQuery() query.Query {
func (d *Devops) GenerateEmptyQuery() query.Query {
return query.NewHTTP()
}

func (d *InfluxDevops) getHostWhereWithHostnames(hostnames []string) string {
func (d *Devops) getHostWhereWithHostnames(hostnames []string) string {
hostnameClauses := []string{}
for _, s := range hostnames {
hostnameClauses = append(hostnameClauses, fmt.Sprintf("hostname = '%s'", s))
Expand All @@ -35,12 +35,12 @@ func (d *InfluxDevops) getHostWhereWithHostnames(hostnames []string) string {
return "(" + combinedHostnameClause + ")"
}

func (d *InfluxDevops) getHostWhereString(nHosts int) string {
func (d *Devops) getHostWhereString(nHosts int) string {
hostnames := d.GetRandomHosts(nHosts)
return d.getHostWhereWithHostnames(hostnames)
}

func (d *InfluxDevops) getSelectClausesAggMetrics(agg string, metrics []string) []string {
func (d *Devops) getSelectClausesAggMetrics(agg string, metrics []string) []string {
selectClauses := make([]string, len(metrics))
for i, m := range metrics {
selectClauses[i] = fmt.Sprintf("%s(%s)", agg, m)
Expand All @@ -58,7 +58,7 @@ func (d *InfluxDevops) getSelectClausesAggMetrics(agg string, metrics []string)
// WHERE (hostname = '$HOSTNAME_1' OR ... OR hostname = '$HOSTNAME_N')
// AND time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY minute ORDER BY minute ASC
func (d *InfluxDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
func (d *Devops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
interval := d.Interval.RandWindow(timeRange)
metrics := devops.GetCPUMetricsSlice(numMetrics)
selectClauses := d.getSelectClausesAggMetrics("max", metrics)
Expand All @@ -81,7 +81,7 @@ func (d *InfluxDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeR
// WHERE time < '$TIME'
// GROUP BY t ORDER BY t DESC
// LIMIT $LIMIT
func (d *InfluxDevops) GroupByOrderByLimit(qi query.Query) {
func (d *Devops) GroupByOrderByLimit(qi query.Query) {
interval := d.Interval.RandWindow(time.Hour)

where := fmt.Sprintf("WHERE time < '%s'", interval.EndString())
Expand All @@ -105,7 +105,7 @@ func (d *InfluxDevops) GroupByOrderByLimit(qi query.Query) {
// FROM cpu
// WHERE time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour, hostname ORDER BY hour, hostname
func (d *InfluxDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
func (d *Devops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
metrics := devops.GetCPUMetricsSlice(numMetrics)
interval := d.Interval.RandWindow(devops.DoubleGroupByDuration)
selectClauses := d.getSelectClausesAggMetrics("mean", metrics)
Expand All @@ -129,7 +129,7 @@ func (d *InfluxDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int)
// FROM cpu WHERE (hostname = '$HOSTNAME_1' OR ... OR hostname = '$HOSTNAME_N')
// AND time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour ORDER BY hour
func (d *InfluxDevops) MaxAllCPU(qi query.Query, nHosts int) {
func (d *Devops) MaxAllCPU(qi query.Query, nHosts int) {
interval := d.Interval.RandWindow(devops.MaxAllDuration)
whereHosts := d.getHostWhereString(nHosts)
selectClauses := d.getSelectClausesAggMetrics("max", devops.GetAllCPUMetrics())
Expand All @@ -147,7 +147,7 @@ func (d *InfluxDevops) MaxAllCPU(qi query.Query, nHosts int) {
}

// LastPointPerHost finds the last row for every host in the dataset
func (d *InfluxDevops) LastPointPerHost(qi query.Query) {
func (d *Devops) LastPointPerHost(qi query.Query) {
v := url.Values{}
v.Set("q", "SELECT * from cpu group by \"hostname\" order by time desc limit 1")

Expand All @@ -168,7 +168,7 @@ func (d *InfluxDevops) LastPointPerHost(qi query.Query) {
// WHERE usage_user > 90.0
// AND time >= '$TIME_START' AND time < '$TIME_END'
// AND (hostname = '$HOST' OR hostname = '$HOST2'...)
func (d *InfluxDevops) HighCPUForHosts(qi query.Query, nHosts int) {
func (d *Devops) HighCPUForHosts(qi query.Query, nHosts int) {
interval := d.Interval.RandWindow(devops.HighCPUDuration)
var hostWhereClause string
if nHosts == 0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package mongo

import (
"encoding/gob"
Expand All @@ -19,18 +19,18 @@ func init() {
gob.Register([]bson.M{})
}

// MongoNaiveDevops produces Mongo-specific queries for the devops use case.
type MongoNaiveDevops struct {
// NaiveDevops produces Mongo-specific queries for the devops use case.
type NaiveDevops struct {
*devops.Core
}

// NewMongoNaiveDevops makes an MongoNaiveDevops object ready to generate Queries.
func newMongoNaiveDevopsCommon(start, end time.Time, scale int) *MongoNaiveDevops {
return &MongoNaiveDevops{devops.NewCore(start, end, scale)}
// NewNaiveDevops makes an NaiveDevops object ready to generate Queries.
func NewNaiveDevops(start, end time.Time, scale int) *NaiveDevops {
return &NaiveDevops{devops.NewCore(start, end, scale)}
}

// GenerateEmptyQuery returns an empty query.Mongo
func (d *MongoNaiveDevops) GenerateEmptyQuery() query.Query {
func (d *NaiveDevops) GenerateEmptyQuery() query.Query {
return query.NewMongo()
}

Expand All @@ -43,7 +43,7 @@ func (d *MongoNaiveDevops) GenerateEmptyQuery() query.Query {
// WHERE (hostname = '$HOSTNAME_1' OR ... OR hostname = '$HOSTNAME_N')
// AND time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY minute ORDER BY minute ASC
func (d *MongoNaiveDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
func (d *NaiveDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
interval := d.Interval.RandWindow(timeRange)
hostnames := d.GetRandomHosts(nHosts)
metrics := devops.GetCPUMetricsSlice(numMetrics)
Expand Down Expand Up @@ -104,7 +104,7 @@ func (d *MongoNaiveDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, t
// FROM cpu
// WHERE time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour, hostname ORDER BY hour, hostname
func (d *MongoNaiveDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
func (d *NaiveDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
interval := d.Interval.RandWindow(devops.DoubleGroupByDuration)
metrics := devops.GetCPUMetricsSlice(numMetrics)
bucketNano := time.Hour.Nanoseconds()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package mongo

import (
"encoding/gob"
Expand All @@ -20,18 +20,18 @@ func init() {
gob.Register([]bson.M{})
}

// MongoDevops produces Mongo-specific queries for the devops use case.
type MongoDevops struct {
// Devops produces Mongo-specific queries for the devops use case.
type Devops struct {
*devops.Core
}

// NewMongoDevops makes an MongoDevops object ready to generate Queries.
func newMongoDevopsCommon(start, end time.Time, scale int) *MongoDevops {
return &MongoDevops{devops.NewCore(start, end, scale)}
// NewDevops makes an Devops object ready to generate Queries.
func NewDevops(start, end time.Time, scale int) *Devops {
return &Devops{devops.NewCore(start, end, scale)}
}

// GenerateEmptyQuery returns an empty query.Mongo
func (d *MongoDevops) GenerateEmptyQuery() query.Query {
func (d *Devops) GenerateEmptyQuery() query.Query {
return query.NewMongo()
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func getTimeFilterDocs(interval utils.TimeInterval) []interface{} {
// WHERE (hostname = '$HOSTNAME_1' OR ... OR hostname = '$HOSTNAME_N')
// AND time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY minute ORDER BY minute ASC
func (d *MongoDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
func (d *Devops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
interval := d.Interval.RandWindow(timeRange)
hostnames := d.GetRandomHosts(nHosts)
metrics := devops.GetCPUMetricsSlice(numMetrics)
Expand Down Expand Up @@ -168,7 +168,7 @@ func (d *MongoDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRa
// FROM cpu WHERE (hostname = '$HOSTNAME_1' OR ... OR hostname = '$HOSTNAME_N')
// AND time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour ORDER BY hour
func (d *MongoDevops) MaxAllCPU(qi query.Query, nHosts int) {
func (d *Devops) MaxAllCPU(qi query.Query, nHosts int) {
interval := d.Interval.RandWindow(devops.MaxAllDuration)
hostnames := d.GetRandomHosts(nHosts)
docs := getTimeFilterDocs(interval)
Expand Down Expand Up @@ -236,7 +236,7 @@ func (d *MongoDevops) MaxAllCPU(qi query.Query, nHosts int) {
// FROM cpu
// WHERE time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour, hostname ORDER BY hour, hostname
func (d *MongoDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
func (d *Devops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
interval := d.Interval.RandWindow(devops.DoubleGroupByDuration)
metrics := devops.GetCPUMetricsSlice(numMetrics)
docs := getTimeFilterDocs(interval)
Expand Down Expand Up @@ -316,7 +316,7 @@ func (d *MongoDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
// WHERE usage_user > 90.0
// AND time >= '$TIME_START' AND time < '$TIME_END'
// AND (hostname = '$HOST' OR hostname = '$HOST2'...)
func (d *MongoDevops) HighCPUForHosts(qi query.Query, nHosts int) {
func (d *Devops) HighCPUForHosts(qi query.Query, nHosts int) {
interval := d.Interval.RandWindow(devops.HighCPUDuration)
hostnames := d.GetRandomHosts(nHosts)
docs := getTimeFilterDocs(interval)
Expand Down Expand Up @@ -366,7 +366,7 @@ func (d *MongoDevops) HighCPUForHosts(qi query.Query, nHosts int) {
}

// LastPointPerHost finds the last row for every host in the dataset
func (d *MongoDevops) LastPointPerHost(qi query.Query) {
func (d *Devops) LastPointPerHost(qi query.Query) {
pipelineQuery := []bson.M{
{"$match": bson.M{"measurement": "cpu"}},
{
Expand Down Expand Up @@ -447,7 +447,7 @@ func (d *MongoDevops) LastPointPerHost(qi query.Query) {
// WHERE time < '$TIME'
// GROUP BY t ORDER BY t DESC
// LIMIT $LIMIT
func (d *MongoDevops) GroupByOrderByLimit(qi query.Query) {
func (d *Devops) GroupByOrderByLimit(qi query.Query) {
interval := d.Interval.RandWindow(time.Hour)
interval = utils.NewTimeInterval(d.Interval.Start, interval.End)
docs := getTimeFilterDocs(interval)
Expand Down
Loading

0 comments on commit d6d845e

Please sign in to comment.