Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
adds ability to set cache expiration from pulsed cli
Browse files Browse the repository at this point in the history
  • Loading branch information
pittma committed Sep 3, 2015
1 parent c8371e1 commit 805264f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func MaxRunningPlugins(m int) controlOpt {
}
}

func CacheExpiration(t time.Duration) controlOpt {
return func(c *pluginControl) {
client.CacheExpiration = t
}
}

// New returns a new pluginControl instance
func New(opts ...controlOpt) *pluginControl {

Expand Down
8 changes: 5 additions & 3 deletions control/plugin/client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"github.com/intelsdi-x/pulse/core"
)

// the time limit for which a cache entry is valid.
var CacheExpiration time.Duration

var (
cacheExpiration = time.Duration(500 * time.Millisecond)
metricCache = cache{
metricCache = cache{
table: make(map[string]*cachecell),
}
cacheLog = log.WithField("_module", "client-cache")
Expand All @@ -32,7 +34,7 @@ func (c *cache) get(key string) core.Metric {
cell *cachecell
ok bool
)
if cell, ok = c.table[key]; ok && time.Since(cell.time) < cacheExpiration {
if cell, ok = c.table[key]; ok && time.Since(cell.time) < CacheExpiration {
cell.hits++
cacheLog.WithFields(log.Fields{
"namespace": key,
Expand Down
1 change: 1 addition & 0 deletions control/plugin/client/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestCache(t *testing.T) {
CacheExpiration = time.Duration(500 * time.Millisecond)
Convey("puts and gets a metric", t, func() {
mc := &cache{
table: make(map[string]*cachecell),
Expand Down
15 changes: 14 additions & 1 deletion pulse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"runtime"
"syscall"
"time"

log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
Expand Down Expand Up @@ -56,6 +57,12 @@ var (
Usage: "Auto discover paths separated by colons.",
EnvVar: "PULSE_AUTOLOAD_PATH",
}
flCache = cli.StringFlag{
Name: "cache-expiration",
Usage: "The time limit for which a metric cache entry is valid",
EnvVar: "PULSE_CACHE_EXPIRATION",
Value: "500ms",
}
gitversion string
)

Expand All @@ -80,7 +87,7 @@ func main() {
app.Name = "pulsed"
app.Version = gitversion
app.Usage = "A powerful telemetry agent framework"
app.Flags = []cli.Flag{flAPIDisabled, flAPIPort, flLogLevel, flLogPath, flMaxProcs, flPluginVersion, flNumberOfPLs}
app.Flags = []cli.Flag{flAPIDisabled, flAPIPort, flLogLevel, flLogPath, flMaxProcs, flPluginVersion, flNumberOfPLs, flCache}

app.Action = action
app.Run(os.Args)
Expand All @@ -102,6 +109,11 @@ func action(ctx *cli.Context) {
apiPort := ctx.Int("api-port")
autodiscoverPath := ctx.String("auto-discover")
maxRunning := ctx.Int("max-running-plugins")
cachestr := ctx.String("cache-expiration")
cache, err := time.ParseDuration(cachestr)
if err != nil {
log.Fatal(fmt.Sprintf("invalid cache-expiration format: %s", cachestr))
}

log.Info("Starting pulsed (version: ", gitversion, ")")

Expand Down Expand Up @@ -161,6 +173,7 @@ func action(ctx *cli.Context) {

c := control.New(
control.MaxRunningPlugins(maxRunning),
control.CacheExpiration(cache),
)
s := scheduler.New(
scheduler.CollectQSizeOption(defaultQueueSize),
Expand Down

0 comments on commit 805264f

Please sign in to comment.