package inputs
import (
"bufio"
"fmt"
"io"
"os"
"time"
)
const (
FormatCassandra = "cassandra"
FormatClickhouse = "clickhouse"
FormatInflux = "influx"
FormatMongo = "mongo"
FormatSiriDB = "siridb"
FormatTimescaleDB = "timescaledb"
FormatAkumuli = "akumuli"
FormatCrateDB = "cratedb"
)
const (
defaultTimeStart = "2016-01-01T00:00:00Z"
defaultTimeEnd = "2016-01-02T00:00:00Z"
errUnknownFormatFmt = "unknown format: '%s'"
)
var formats = []string{
FormatCassandra,
FormatClickhouse,
FormatInflux,
FormatMongo,
FormatSiriDB,
FormatTimescaleDB,
FormatAkumuli,
FormatCrateDB,
}
func isIn(s string, arr []string) bool {
for _, x := range arr {
if s == x {
return true
}
}
return false
}
const (
useCaseCPUOnly = "cpu-only"
useCaseCPUSingle = "cpu-single"
useCaseDevops = "devops"
useCaseIoT = "iot"
)
var useCaseChoices = []string{
useCaseCPUOnly,
useCaseCPUSingle,
useCaseDevops,
useCaseIoT,
}
func ParseUTCTime(s string) (time.Time, error) {
t, err := time.Parse(time.RFC3339, s)
if err != nil {
return time.Time{}, err
}
return t.UTC(), nil
}
const defaultWriteSize = 4 << 20
func getBufferedWriter(filename string, fallback io.Writer) (*bufio.Writer, error) {
if len(filename) > 0 {
file, err := os.Create(filename)
if err != nil {
return nil, fmt.Errorf("cannot open file for write %s: %v", filename, err)
}
return bufio.NewWriterSize(file, defaultWriteSize), nil
}
return bufio.NewWriterSize(fallback, defaultWriteSize), nil
}
func validateGroups(groupID, totalGroupsNum uint) error {
if totalGroupsNum == 0 {
return fmt.Errorf(errTotalGroupsZero)
}
if groupID >= totalGroupsNum {
return fmt.Errorf(errInvalidGroupsFmt, groupID, totalGroupsNum)
}
return nil
}