Add depot, attendant, jetfire, optimus, ota services with kustomize overlays
This commit is contained in:
25
services/jetfire/utils/const.go
Normal file
25
services/jetfire/utils/const.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/fiskerinc/cloud-services/pkg/utils/envtool"
|
||||
)
|
||||
|
||||
var (
|
||||
//other cache constants
|
||||
TripTimeout = time.Duration(envtool.GetEnvInt64("JETFIRE_TRIP_TIMEOUT_MS", 600000)) * time.Millisecond
|
||||
|
||||
EmptySignal = math.NaN()
|
||||
|
||||
//bitwise flags for state updates.
|
||||
//Additional flags can be added for additional sink tables later on
|
||||
FeatureUpdateFlag uint = 0x1
|
||||
LatestUpdateFlag uint = 0x2
|
||||
|
||||
MaxVinLength = 20
|
||||
MaxTimestampLength = 12
|
||||
|
||||
FeatureVarsDefaults = "default-feature-vars.json"
|
||||
)
|
||||
11
services/jetfire/utils/errors.go
Normal file
11
services/jetfire/utils/errors.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrInsertFullBlock = errors.New("appending row into full block")
|
||||
ErrInsertWrongColumns = errors.New("appending buffer with incorrect number of columns")
|
||||
ErrInvalidAppendType = errors.New("appending invalid type to block")
|
||||
ErrNilClickhouseClient = errors.New("nil clickhouse client")
|
||||
ErrNilKafkaConsumer = errors.New("nil kafka consumer")
|
||||
)
|
||||
63
services/jetfire/utils/functions.go
Normal file
63
services/jetfire/utils/functions.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/fiskerinc/cloud-services/pkg/logger"
|
||||
"github.com/intel-go/fastjson"
|
||||
"github.com/sony/gobreaker"
|
||||
)
|
||||
|
||||
// Converts float64 (as decimal seconds in unix epoch) to Time.Time struct
|
||||
func FloatToTime(float float64) time.Time {
|
||||
s := int64(math.Floor(float))
|
||||
ns := int64((float - math.Floor(float)) * 1e9)
|
||||
return time.Unix(
|
||||
s,
|
||||
ns,
|
||||
)
|
||||
}
|
||||
|
||||
func TimeToFloat(timestamp time.Time) float64 {
|
||||
return float64(timestamp.UnixNano()) / 1e9
|
||||
}
|
||||
|
||||
func FixFloatTimestampScale(float float64) float64 {
|
||||
for float > 9999999999 {
|
||||
float /= 1000
|
||||
}
|
||||
return float
|
||||
}
|
||||
|
||||
// marchTimer increments the value at timer until newTime has been reached.
|
||||
// This is used to try to maintain consistent downsample and insertion periods.
|
||||
func MarchTimer(timer *time.Time, newTime *time.Time, delay time.Duration) {
|
||||
for timer.Before(*newTime) {
|
||||
*timer = timer.Add(delay)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadVarListFromFile(varsFile string) []string {
|
||||
data, err := os.ReadFile(varsFile)
|
||||
if err != nil {
|
||||
// when running tests, pwd is in the wrong directory to find the default json files.
|
||||
os.Chdir("..")
|
||||
data, err = os.ReadFile(varsFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
var result []string
|
||||
err = fastjson.Unmarshal(data, &result)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func BreakerStateChange(name string, from gobreaker.State, to gobreaker.State) {
|
||||
logger.Warn().Stack().Msgf("%s breaker change from %d to %d", name, from, to)
|
||||
}
|
||||
55
services/jetfire/utils/logging.go
Normal file
55
services/jetfire/utils/logging.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/fiskerinc/cloud-services/pkg/logger"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
var (
|
||||
outOfOrderSignalMap = make(map[string]uint)
|
||||
outOfOrderVINMap = make(map[string]uint)
|
||||
outOfOrderCount uint = 0
|
||||
outOfOrderLogDelay = time.Hour
|
||||
outOfOrderTime = time.Now().UTC()
|
||||
)
|
||||
|
||||
// This function is for aggregating and logging out of order incoming messages
|
||||
func LogOutOfOrderMsg(signal string, VIN string) {
|
||||
_, ok := outOfOrderSignalMap[signal]
|
||||
if !ok {
|
||||
outOfOrderSignalMap[signal] = 0
|
||||
}
|
||||
outOfOrderSignalMap[signal] += 1
|
||||
|
||||
_, ok = outOfOrderVINMap[VIN]
|
||||
if !ok {
|
||||
outOfOrderVINMap[VIN] = 0
|
||||
}
|
||||
outOfOrderVINMap[VIN] += 1
|
||||
outOfOrderCount += 1
|
||||
|
||||
if time.Since(outOfOrderTime) > outOfOrderLogDelay {
|
||||
|
||||
signalDict := zerolog.Dict()
|
||||
for k, v := range outOfOrderSignalMap {
|
||||
signalDict.Uint(k, v)
|
||||
}
|
||||
vinDict := zerolog.Dict()
|
||||
for k, v := range outOfOrderVINMap {
|
||||
vinDict.Uint(k, v)
|
||||
}
|
||||
|
||||
logger.Warn().Dict(
|
||||
"Signals", signalDict,
|
||||
).Dict(
|
||||
"VINs", vinDict,
|
||||
).Msgf("Received Out of Order Data! %d out-of-order messages", outOfOrderCount)
|
||||
|
||||
outOfOrderCount = 0
|
||||
outOfOrderTime = time.Now().UTC()
|
||||
clear(outOfOrderSignalMap)
|
||||
clear(outOfOrderVINMap)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user