Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate consistent query conditions using the same random seed #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/tsbs_generate_queries/databases/cassandra/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (d *Devops) GroupByOrderByLimit(qi query.Query) {
// WHERE time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour, hostname ORDER BY hour
func (d *Devops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
metrics, err := devops.GetCPUMetricsSlice(numMetrics)
interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
panicIfErr(err)

humanLabel := devops.GetDoubleGroupByLabel("Cassandra", numMetrics)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tsbs_generate_queries/databases/clickhouse/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ func (d *Devops) GroupByOrderByLimit(qi query.Query) {
// high-cpu-1
// high-cpu-all
func (d *Devops) HighCPUForHosts(qi query.Query, nHosts int) {
interval := d.Interval.MustRandWindow(devops.HighCPUDuration)
var hostWhereClause string
if nHosts == 0 {
hostWhereClause = ""
} else {
hostWhereClause = fmt.Sprintf("AND (%s)", d.getHostWhereString(nHosts))
}
interval := d.Interval.MustRandWindow(devops.HighCPUDuration)

sql := fmt.Sprintf(`
SELECT *
Expand Down
10 changes: 5 additions & 5 deletions cmd/tsbs_generate_queries/databases/clickhouse/devops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ func TestHighCPUForHosts(t *testing.T) {
desc: "zero hosts",
input: 0,
expectedHumanLabel: "ClickHouse CPU over threshold, all hosts",
expectedHumanDesc: "ClickHouse CPU over threshold, all hosts: 1970-01-01T00:16:22Z",
expectedHumanDesc: "ClickHouse CPU over threshold, all hosts: 1970-01-01T00:54:10Z",
expectedQuery: `
SELECT *
FROM cpu
PREWHERE (usage_user > 90.0) AND (created_at >= '1970-01-01 00:16:22') AND (created_at < '1970-01-01 12:16:22')
PREWHERE (usage_user > 90.0) AND (created_at >= '1970-01-01 00:54:10') AND (created_at < '1970-01-01 12:54:10')
`,
},
{
Expand All @@ -341,18 +341,18 @@ func TestHighCPUForHosts(t *testing.T) {
expectedQuery: `
SELECT *
FROM cpu
PREWHERE (usage_user > 90.0) AND (created_at >= '1970-01-01 00:47:30') AND (created_at < '1970-01-01 12:47:30') AND ((hostname = 'host_9'))
PREWHERE (usage_user > 90.0) AND (created_at >= '1970-01-01 00:47:30') AND (created_at < '1970-01-01 12:47:30') AND ((hostname = 'host_5'))
`,
},
{
desc: "5 hosts",
input: 5,
expectedHumanLabel: "ClickHouse CPU over threshold, 5 host(s)",
expectedHumanDesc: "ClickHouse CPU over threshold, 5 host(s): 1970-01-01T00:08:59Z",
expectedHumanDesc: "ClickHouse CPU over threshold, 5 host(s): 1970-01-01T00:17:45Z",
expectedQuery: `
SELECT *
FROM cpu
PREWHERE (usage_user > 90.0) AND (created_at >= '1970-01-01 00:08:59') AND (created_at < '1970-01-01 12:08:59') AND ((hostname = 'host_5' OR hostname = 'host_9' OR hostname = 'host_1' OR hostname = 'host_7' OR hostname = 'host_2'))
PREWHERE (usage_user > 90.0) AND (created_at >= '1970-01-01 00:17:45') AND (created_at < '1970-01-01 12:17:45') AND ((hostname = 'host_9' OR hostname = 'host_5' OR hostname = 'host_1' OR hostname = 'host_7' OR hostname = 'host_2'))
`,
},
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/tsbs_generate_queries/databases/mongo/devops-naive.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ func (d *NaiveDevops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRa
// WHERE time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour, hostname ORDER BY hour, hostname
func (d *NaiveDevops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
metrics, err := devops.GetCPUMetricsSlice(numMetrics)
panicIfErr(err)
interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
bucketNano := time.Hour.Nanoseconds()

pipelineQuery := []bson.M{
Expand Down
2 changes: 1 addition & 1 deletion cmd/tsbs_generate_queries/databases/mongo/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ func (d *Devops) MaxAllCPU(qi query.Query, nHosts int, duration time.Duration) {
// WHERE time >= '$HOUR_START' AND time < '$HOUR_END'
// GROUP BY hour, hostname ORDER BY hour, hostname
func (d *Devops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
metrics, err := devops.GetCPUMetricsSlice(numMetrics)
panicIfErr(err)
interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
docs := getTimeFilterDocs(interval)
bucketNano := time.Hour.Nanoseconds()

Expand Down
4 changes: 2 additions & 2 deletions cmd/tsbs_generate_queries/databases/siridb/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func (d *Devops) GroupByOrderByLimit(qi query.Query) {
//
// select mean(1h) from (`groupMetric1` | ...) between 'time1' and 'time2'
func (d *Devops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
metrics, err := devops.GetCPUMetricsSlice(numMetrics)
panicIfErr(err)
interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
whereMetrics := d.getMetricWhereString(metrics)

humanLabel := devops.GetDoubleGroupByLabel("SiriDB", numMetrics)
Expand Down Expand Up @@ -154,13 +154,13 @@ func (d *Devops) LastPointPerHost(qi query.Query) {
// nHosts>0:
// select filter(> 90) from `usage_user` & (`groupHost1` | ...) between 'time1' and 'time2'
func (d *Devops) HighCPUForHosts(qi query.Query, nHosts int) {
interval := d.Interval.MustRandWindow(devops.HighCPUDuration)
var whereHosts string
if nHosts == 0 {
whereHosts = ""
} else {
whereHosts = "& " + d.getHostWhereString(nHosts)
}
interval := d.Interval.MustRandWindow(devops.HighCPUDuration)

humanLabel, err := devops.GetHighCPULabel("SiriDB", nHosts)
panicIfErr(err)
Expand Down
20 changes: 10 additions & 10 deletions cmd/tsbs_generate_queries/databases/siridb/devops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ func TestGroupByTimeAndPrimaryTag(t *testing.T) {
desc: "one metric",
input: 1,
expectedHumanLabel: "SiriDB mean of 1 metrics, all hosts, random 12h0m0s by 1h",
expectedHumanDesc: "SiriDB mean of 1 metrics, all hosts, random 12h0m0s by 1h: 1970-01-01T00:47:30Z",
expectedHumanDesc: "SiriDB mean of 1 metrics, all hosts, random 12h0m0s by 1h: 1970-01-01T00:16:22Z",
expectedQuery: "select mean(1h) from (`usage_user`) " +
"between '1970-01-01T00:47:30Z' and '1970-01-01T12:47:30Z'",
"between '1970-01-01T00:16:22Z' and '1970-01-01T12:16:22Z'",
},
{
desc: "5 metrics",
input: 5,
expectedHumanLabel: "SiriDB mean of 5 metrics, all hosts, random 12h0m0s by 1h",
expectedHumanDesc: "SiriDB mean of 5 metrics, all hosts, random 12h0m0s by 1h: 1970-01-01T00:37:12Z",
expectedHumanDesc: "SiriDB mean of 5 metrics, all hosts, random 12h0m0s by 1h: 1970-01-01T00:54:10Z",
expectedQuery: "select mean(1h) " +
"from (`usage_user`|`usage_system`|`usage_idle`|`usage_nice`|`usage_iowait`) " +
"between '1970-01-01T00:37:12Z' and '1970-01-01T12:37:12Z'",
"between '1970-01-01T00:54:10Z' and '1970-01-01T12:54:10Z'",
},
{
desc: "more metrics then it exists",
Expand Down Expand Up @@ -280,26 +280,26 @@ func TestHighCPUForHosts(t *testing.T) {
desc: "zero hosts",
input: 0,
expectedHumanLabel: "SiriDB CPU over threshold, all hosts",
expectedHumanDesc: "SiriDB CPU over threshold, all hosts: 1970-01-01T00:16:22Z",
expectedHumanDesc: "SiriDB CPU over threshold, all hosts: 1970-01-01T00:54:10Z",
expectedQuery: "select filter(> 90) from `usage_user` " +
"between '1970-01-01T00:16:22Z' and '1970-01-01T12:16:22Z'",
"between '1970-01-01T00:54:10Z' and '1970-01-01T12:54:10Z'",
},
{
desc: "one host",
input: 1,
expectedHumanLabel: "SiriDB CPU over threshold, 1 host(s)",
expectedHumanDesc: "SiriDB CPU over threshold, 1 host(s): 1970-01-01T00:47:30Z",
expectedQuery: "select filter(> 90) from `usage_user` & (`host_9`) " +
expectedQuery: "select filter(> 90) from `usage_user` & (`host_5`) " +
"between '1970-01-01T00:47:30Z' and '1970-01-01T12:47:30Z'",
},
{
desc: "5 hosts",
input: 5,
expectedHumanLabel: "SiriDB CPU over threshold, 5 host(s)",
expectedHumanDesc: "SiriDB CPU over threshold, 5 host(s): 1970-01-01T00:08:59Z",
expectedHumanDesc: "SiriDB CPU over threshold, 5 host(s): 1970-01-01T00:17:45Z",
expectedQuery: "select filter(> 90) " +
"from `usage_user` & (`host_5`|`host_9`|`host_1`|`host_7`|`host_2`) " +
"between '1970-01-01T00:08:59Z' and '1970-01-01T12:08:59Z'",
"from `usage_user` & (`host_9`|`host_5`|`host_1`|`host_7`|`host_2`) " +
"between '1970-01-01T00:17:45Z' and '1970-01-01T12:17:45Z'",
},
{
desc: "more hosts then cardinality (11)",
Expand Down
2 changes: 1 addition & 1 deletion cmd/tsbs_generate_queries/databases/timescaledb/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ func (d *Devops) LastPointPerHost(qi query.Query) {
// AND time >= '$TIME_START' AND time < '$TIME_END'
// AND (hostname = '$HOST' OR hostname = '$HOST2'...)
func (d *Devops) HighCPUForHosts(qi query.Query, nHosts int) {
interval := d.Interval.MustRandWindow(devops.HighCPUDuration)
var hostWhereClause string
if nHosts == 0 {
hostWhereClause = ""
} else {
hostWhereClause = fmt.Sprintf("AND %s", d.getHostWhereString(nHosts))
}
interval := d.Interval.MustRandWindow(devops.HighCPUDuration)

sql := fmt.Sprintf(`SELECT * FROM cpu WHERE usage_user > 90.0 and time >= '%s' AND time < '%s' %s`,
interval.Start().Format(goTimeFmt), interval.End().Format(goTimeFmt), hostWhereClause)
Expand Down
12 changes: 6 additions & 6 deletions cmd/tsbs_generate_queries/databases/timescaledb/devops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,19 +473,19 @@ func TestHighCPUForHosts(t *testing.T) {
desc: "one host",
nHosts: 1,
expectedHumanLabel: "TimescaleDB CPU over threshold, 1 host(s)",
expectedHumanDesc: "TimescaleDB CPU over threshold, 1 host(s): 1970-01-01T00:47:30Z",
expectedHumanDesc: "TimescaleDB CPU over threshold, 1 host(s): 1970-01-01T00:54:10Z",
expectedHypertable: "cpu",
expectedSQLQuery: "SELECT * FROM cpu WHERE usage_user > 90.0 and time >= '1970-01-01 00:47:30.894865 +0000'" +
" AND time < '1970-01-01 12:47:30.894865 +0000' AND hostname IN ('host_9')",
expectedSQLQuery: "SELECT * FROM cpu WHERE usage_user > 90.0 and time >= '1970-01-01 00:54:10.138978 +0000'" +
" AND time < '1970-01-01 12:54:10.138978 +0000' AND hostname IN ('host_3')",
},
{
desc: "five hosts",
nHosts: 5,
expectedHumanLabel: "TimescaleDB CPU over threshold, 5 host(s)",
expectedHumanDesc: "TimescaleDB CPU over threshold, 5 host(s): 1970-01-01T00:08:59Z",
expectedHumanDesc: "TimescaleDB CPU over threshold, 5 host(s): 1970-01-01T00:37:12Z",
expectedHypertable: "cpu",
expectedSQLQuery: "SELECT * FROM cpu WHERE usage_user > 90.0 and time >= '1970-01-01 00:08:59.080812 +0000'" +
" AND time < '1970-01-01 12:08:59.080812 +0000' AND hostname IN ('host_5','host_9','host_1','host_7','host_2')",
expectedSQLQuery: "SELECT * FROM cpu WHERE usage_user > 90.0 and time >= '1970-01-01 00:37:12.342805 +0000'" +
" AND time < '1970-01-01 12:37:12.342805 +0000' AND hostname IN ('host_9','host_5','host_1','host_7','host_2')",
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/tsbs_generate_queries/databases/timestream/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ func (d *Devops) LastPointPerHost(qi query.Query) {
// AND time >= '$TIME_START' AND time < '$TIME_END'
// AND (hostname = '$HOST' OR hostname = '$HOST2'...)
func (d *Devops) HighCPUForHosts(qi query.Query, nHosts int) {
interval := d.Interval.MustRandWindow(devops.HighCPUDuration)
var hostWhereClause string
if nHosts == 0 {
hostWhereClause = ""
} else {
hostWhereClause = fmt.Sprintf("AND %s", d.getHostWhereString(nHosts))
}
interval := d.Interval.MustRandWindow(devops.HighCPUDuration)

sql := fmt.Sprintf(`
WITH usage_over_ninety AS (
Expand Down
17 changes: 9 additions & 8 deletions cmd/tsbs_generate_queries/databases/timestream/devops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package timestream

import (
"fmt"
"github.com/andreyvit/diff"
"github.com/timescale/tsbs/pkg/query"
"math/rand"
"strings"
"testing"
"time"

"github.com/andreyvit/diff"
"github.com/timescale/tsbs/pkg/query"

"github.com/timescale/tsbs/cmd/tsbs_generate_queries/uses/devops"
)

Expand Down Expand Up @@ -411,16 +412,16 @@ func TestHighCPUForHosts(t *testing.T) {
desc: "one host",
nHosts: 1,
expectedHumanLabel: "Timestream CPU over threshold, 1 host(s)",
expectedHumanDesc: "Timestream CPU over threshold, 1 host(s): 1970-01-01T00:47:30Z",
expectedHumanDesc: "Timestream CPU over threshold, 1 host(s): 1970-01-01T00:54:10Z",
expectedHypertable: "cpu",
expectedSQLQuery: `
WITH usage_over_ninety AS (
SELECT time,
hostname
FROM "b"."cpu"
WHERE measure_name = 'usage_user' AND measure_value::double > 90
AND time >= '1970-01-01 00:47:30.894865 +0000' AND time < '1970-01-01 12:47:30.894865 +0000'
AND (hostname = 'host_9')
AND time >= '1970-01-01 00:54:10.138978 +0000' AND time < '1970-01-01 12:54:10.138978 +0000'
AND (hostname = 'host_3')
)
SELECT *
FROM "b"."cpu" a
Expand All @@ -430,16 +431,16 @@ func TestHighCPUForHosts(t *testing.T) {
desc: "five hosts",
nHosts: 5,
expectedHumanLabel: "Timestream CPU over threshold, 5 host(s)",
expectedHumanDesc: "Timestream CPU over threshold, 5 host(s): 1970-01-01T00:08:59Z",
expectedHumanDesc: "Timestream CPU over threshold, 5 host(s): 1970-01-01T00:37:12Z",
expectedHypertable: "cpu",
expectedSQLQuery: `
WITH usage_over_ninety AS (
SELECT time,
hostname
FROM "b"."cpu"
WHERE measure_name = 'usage_user' AND measure_value::double > 90
AND time >= '1970-01-01 00:08:59.080812 +0000' AND time < '1970-01-01 12:08:59.080812 +0000'
AND (hostname = 'host_5' OR hostname = 'host_9' OR hostname = 'host_1' OR hostname = 'host_7' OR hostname = 'host_2')
AND time >= '1970-01-01 00:37:12.342805 +0000' AND time < '1970-01-01 12:37:12.342805 +0000'
AND (hostname = 'host_9' OR hostname = 'host_5' OR hostname = 'host_1' OR hostname = 'host_7' OR hostname = 'host_2')
)
SELECT *
FROM "b"."cpu" a
Expand Down