func (d *Devops) GroupByTimeAndPrimaryTag(qi query.Query, numMetrics int) {
	interval := d.Interval.MustRandWindow(devops.DoubleGroupByDuration)
	metrics, err := devops.GetCPUMetricsSlice(numMetrics)
	panicIfErr(err)
	humanLabel := devops.GetDoubleGroupByLabel("Cassandra", numMetrics)
	humanDesc := fmt.Sprintf("%s: %s", humanLabel, interval.StartString())
	d.fillInQuery(qi, humanLabel, humanDesc, "avg", metrics, interval, nil)
	q := qi.(*query.Cassandra)
	q.GroupByDuration = time.Hour
}
GroupByTimeAndPrimaryTag selects the AVG of numMetrics metrics under 'cpu' per device per hour for a day,
e.g. in pseudo-SQL:

SELECT AVG(metric1), ..., AVG(metricN)
FROM cpu
WHERE time >= '$HOUR_START' AND time < '$HOUR_END'
GROUP BY hour, hostname ORDER BY hour
package cassandra
import (
	"fmt"
	"time"
	"github.com/timescale/tsbs/cmd/tsbs_generate_queries/uses/devops"
	"github.com/timescale/tsbs/internal/utils"
	"github.com/timescale/tsbs/pkg/query"
)
func panicIfErr(err error) {
	if err != nil {
		panic(err.Error())
	}
}
type Devops struct {
	*BaseGenerator
	*devops.Core
}
func (d *Devops) getHostWhereWithHostnames(hostnames []string) []string {
	tagSet := []string{}
	for _, hostname := range hostnames {
		tag := "hostname=" + hostname
		tagSet = append(tagSet, tag)
	}
	return tagSet
}
func (d *Devops) getHostWhere(nHosts int) []string {
	hostnames, err := d.GetRandomHosts(nHosts)
	panicIfErr(err)
	return d.getHostWhereWithHostnames(hostnames)
}
func (d *Devops) GroupByTime(qi query.Query, nHosts, numMetrics int, timeRange time.Duration) {
	interval := d.Interval.MustRandWindow(timeRange)
	metrics, err := devops.GetCPUMetricsSlice(numMetrics)
	panicIfErr(err)
	tagSet := d.getHostWhere(nHosts)
	tagSets := [][]string{}
	tagSets = append(tagSets, tagSet)
	humanLabel := fmt.Sprintf("Cassandra %d cpu metric(s), random %4d hosts, random %s by 1m", numMetrics, nHosts, timeRange)
	humanDesc := fmt.Sprintf("%s: %s", humanLabel, interval.StartString())
	d.fillInQuery(qi, humanLabel, humanDesc, "max", metrics, interval, tagSets)
	q := qi.(*query.Cassandra)
	q.GroupByDuration = time.Minute
}
func (d *Devops) GroupByOrderByLimit(qi query.Query) {
	interval := d.Interval.MustRandWindow(time.Hour)
	interval, err := utils.NewTimeInterval(d.Interval.Start(), interval.End())
	if err != nil {
		panic(err.Error())
	}
	humanLabel := "Cassandra max cpu over last 5 min-intervals (random end)"
	humanDesc := fmt.Sprintf("%s: %s", humanLabel, d.Interval.StartString())
	d.fillInQuery(qi, humanLabel, humanDesc, "max", []string{"usage_user"}, interval, nil)
	q := qi.(*query.Cassandra)
	q.GroupByDuration = time.Minute
	q.OrderBy = []byte("timestamp_ns DESC")
	q.Limit = 5
}