Don't commit errors and warnings to cache
This commit is contained in:
parent
ff880489e6
commit
2d187750fb
4 changed files with 43 additions and 7 deletions
|
|
@ -8,14 +8,16 @@ import (
|
|||
"github.com/andig/evcc/server"
|
||||
"github.com/andig/evcc/server/updater"
|
||||
"github.com/andig/evcc/util"
|
||||
"github.com/andig/evcc/util/pipe"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
log = util.NewLogger("main")
|
||||
cfgFile string
|
||||
ignoreParams = []string{"warn", "error", "fatal"} // don't add to cache
|
||||
log = util.NewLogger("main")
|
||||
cfgFile string
|
||||
)
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
|
|
@ -134,7 +136,7 @@ func run(cmd *cobra.Command, args []string) {
|
|||
|
||||
// value cache
|
||||
cache := util.NewCache()
|
||||
go cache.Run(tee.Attach())
|
||||
go cache.Run(pipe.NewDropper(ignoreParams...).Pipe(tee.Attach()))
|
||||
|
||||
// setup loadpoints
|
||||
site := loadConfig(conf)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/andig/evcc/push"
|
||||
"github.com/andig/evcc/server"
|
||||
"github.com/andig/evcc/util"
|
||||
"github.com/andig/evcc/util/pipe"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
|
@ -30,11 +31,11 @@ func configureDatabase(conf server.InfluxConfig, loadPoints []*core.LoadPoint, i
|
|||
)
|
||||
|
||||
// eliminate duplicate values
|
||||
dedupe := server.NewDeduplicator(30*time.Minute, "socCharge")
|
||||
dedupe := pipe.NewDeduplicator(30*time.Minute, "socCharge")
|
||||
in = dedupe.Pipe(in)
|
||||
|
||||
// reduce number of values written to influx
|
||||
limiter := server.NewLimiter(5 * time.Second)
|
||||
limiter := pipe.NewLimiter(5 * time.Second)
|
||||
in = limiter.Pipe(in)
|
||||
|
||||
go influx.Run(loadPoints, in)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package server
|
||||
package pipe
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
|
@ -100,3 +100,36 @@ func (l *Limiter) Pipe(in <-chan util.Param) <-chan util.Param {
|
|||
go l.pipe(in, out)
|
||||
return out
|
||||
}
|
||||
|
||||
// Dropper allows filtering of channel data by given criteria
|
||||
type Dropper struct {
|
||||
filter []string
|
||||
}
|
||||
|
||||
// NewDropper creates Dropper
|
||||
func NewDropper(filter ...string) Piper {
|
||||
return &Dropper{filter}
|
||||
}
|
||||
|
||||
func (l *Dropper) pipe(in <-chan util.Param, out chan<- util.Param) {
|
||||
for p := range in {
|
||||
var remove bool
|
||||
for _, filtered := range l.filter {
|
||||
if p.Key == filtered {
|
||||
remove = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !remove {
|
||||
out <- p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pipe creates a new filtered output channel for given input channel
|
||||
func (l *Dropper) Pipe(in <-chan util.Param) <-chan util.Param {
|
||||
out := make(chan util.Param)
|
||||
go l.pipe(in, out)
|
||||
return out
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package server
|
||||
package pipe
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
Loading…
Add table
Add a link
Reference in a new issue