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

update http header #4

Open
wants to merge 7 commits into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions cmd/generate_data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"os"
"os/signal"
"runtime/pprof"

"github.com/blagojts/viper"
"github.com/cnosdb/tsdb-comparisons/internal/inputs"
"github.com/cnosdb/tsdb-comparisons/internal/utils"
Expand All @@ -35,25 +35,25 @@ var (
// Parse args:
func init() {
config.AddToFlagSet(pflag.CommandLine)

pflag.String("profile-file", "", "File to which to write go profiling data")

pflag.Parse()

err := utils.SetupConfigFile()

if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}

if err := viper.Unmarshal(&config.BaseConfig); err != nil {
panic(fmt.Errorf("unable to decode base config: %s", err))
}

if err := viper.Unmarshal(&config); err != nil {
panic(fmt.Errorf("unable to decode config: %s", err))
}

profileFile = viper.GetString("profile-file")
}

Expand All @@ -75,25 +75,25 @@ func startMemoryProfile(profileFile string) func() {
if err != nil {
log.Fatal("could not create memory profile: ", err)
}

stop := func() {
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal("could not write memory profile: ", err)
}
f.Close()
}

// Catches ctrl+c signals
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c

fmt.Fprintln(os.Stderr, "\ncaught interrupt, stopping profile")
stop()

os.Exit(0)
}()

return stop
}
8 changes: 4 additions & 4 deletions cmd/generate_queries/databases/cnosdb/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/url"
"time"

"github.com/cnosdb/tsdb-comparisons/cmd/generate_queries/uses/iot"
"github.com/cnosdb/tsdb-comparisons/cmd/generate_queries/utils"
"github.com/cnosdb/tsdb-comparisons/pkg/query"
Expand Down Expand Up @@ -35,15 +35,15 @@ func (g *BaseGenerator) fillInQuery(qi query.Query, humanLabel, humanDesc, cnosq
// NewIoT creates a new iot use case query generator.
func (g *BaseGenerator) NewIoT(start, end time.Time, scale int) (utils.QueryGenerator, error) {
core, err := iot.NewCore(start, end, scale)

if err != nil {
return nil, err
}

devops := &IoT{
BaseGenerator: g,
Core: core,
}

return devops, nil
}
58 changes: 29 additions & 29 deletions cmd/generate_queries/databases/cnosdb/iot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"time"

"github.com/cnosdb/tsdb-comparisons/cmd/generate_queries/databases"
"github.com/cnosdb/tsdb-comparisons/cmd/generate_queries/uses/iot"
"github.com/cnosdb/tsdb-comparisons/pkg/query"
Expand All @@ -31,7 +31,7 @@ func (i *IoT) getTrucksWhereWithNames(names []string) string {
for _, s := range names {
nameClauses = append(nameClauses, fmt.Sprintf("\"name\" = '%s'", s))
}

combinedHostnameClause := strings.Join(nameClauses, " or ")
return "(" + combinedHostnameClause + ")"
}
Expand All @@ -52,27 +52,27 @@ func (i *IoT) LastLocByTruck(qi query.Query, nTrucks int) {
ORDER BY "time"
LIMIT 1`,
i.getTruckWhereString(nTrucks))

humanLabel := "cnosdb last location by specific truck"
humanDesc := fmt.Sprintf("%s: random %4d trucks", humanLabel, nTrucks)

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

// LastLocPerTruck finds all the truck locations along with truck and driver names.
func (i *IoT) LastLocPerTruck(qi query.Query) {

cnosql := fmt.Sprintf(`SELECT "latitude", "longitude"
FROM "readings"
WHERE "fleet"='%s'
GROUP BY "name","driver"
ORDER BY "time"
LIMIT 1`,
i.GetRandomFleet())

humanLabel := "cnosdb last location per truck"
humanDesc := humanLabel

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -85,10 +85,10 @@ func (i *IoT) TrucksWithLowFuel(qi query.Query) {
ORDER BY "time" DESC
LIMIT 1`,
i.GetRandomFleet())

humanLabel := "cnosdb trucks with low fuel"
humanDesc := fmt.Sprintf("%s: under 10 percent", humanLabel)

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -104,10 +104,10 @@ func (i *IoT) TrucksWithHighLoad(qi query.Query) {
GROUP BY "name"
ORDER BY "time" DESC`,
i.GetRandomFleet())

humanLabel := "cnosdb trucks with high load"
humanDesc := fmt.Sprintf("%s: over 90 percent", humanLabel)

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -125,10 +125,10 @@ func (i *IoT) StationaryTrucks(qi query.Query) {
interval.Start().Format(time.RFC3339),
interval.End().Format(time.RFC3339),
i.GetRandomFleet())

humanLabel := "cnosdb stationary trucks"
humanDesc := fmt.Sprintf("%s: with low avg velocity in last 10 minutes", humanLabel)

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -149,10 +149,10 @@ func (i *IoT) TrucksWithLongDrivingSessions(qi query.Query) {
interval.End().Format(time.RFC3339),
// Calculate number of 10 min intervals that is the max driving duration for the session if we rest 5 mins per hour.
tenMinutePeriods(5, iot.LongDrivingSessionDuration))

humanLabel := "cnosdb trucks with longer driving sessions"
humanDesc := fmt.Sprintf("%s: stopped less than 20 mins in 4 hour period", humanLabel)

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -173,10 +173,10 @@ func (i *IoT) TrucksWithLongDailySessions(qi query.Query) {
interval.End().Format(time.RFC3339),
// Calculate number of 10 min intervals that is the max driving duration for the session if we rest 35 mins per hour.
tenMinutePeriods(35, iot.DailyDrivingDuration))

humanLabel := "cnosdb trucks with longer daily sessions"
humanDesc := fmt.Sprintf("%s: drove more than 10 hours in the last 24 hours", humanLabel)

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -186,10 +186,10 @@ func (i *IoT) AvgVsProjectedFuelConsumption(qi query.Query) {
FROM "readings"
WHERE "velocity" > 1
GROUP BY "fleet"`

humanLabel := "cnosdb average vs projected fuel consumption per fleet"
humanDesc := humanLabel

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -209,10 +209,10 @@ func (i *IoT) AvgDailyDrivingDuration(qi query.Query) {
start,
end,
)

humanLabel := "cnosdb average driver driving duration per day"
humanDesc := humanLabel

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand Down Expand Up @@ -244,10 +244,10 @@ func (i *IoT) AvgDailyDrivingSession(qi query.Query) {
start,
end,
)

humanLabel := "cnosdb average driver driving session without stopping per day"
humanDesc := humanLabel

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -258,10 +258,10 @@ func (i *IoT) AvgLoad(qi query.Query) {
FROM "diagnostics"
GROUP BY "name", "fleet", "model")
GROUP BY "fleet", "model"`

humanLabel := "cnosdb average load per truck model per fleet"
humanDesc := humanLabel

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -281,10 +281,10 @@ func (i *IoT) DailyTruckActivity(qi query.Query) {
start,
end,
)

humanLabel := "cnosdb daily truck activity per fleet per model"
humanDesc := humanLabel

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand All @@ -308,10 +308,10 @@ func (i *IoT) TruckBreakdownFrequency(qi query.Query) {
start,
end,
)

humanLabel := "cnosdb truck breakdown frequency per model"
humanDesc := humanLabel

i.fillInQuery(qi, humanLabel, humanDesc, cnosql)
}

Expand Down
Loading