Skip to content

Commit

Permalink
Make the history limit a configurable flag (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmitchell authored and brian-brazil committed Apr 13, 2018
1 parent bedf262 commit 0007554
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions history.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ type result struct {
}

type resultHistory struct {
mu sync.Mutex
nextId int64
results []*result
mu sync.Mutex
nextId int64
results []*result
maxResults uint
}

// Add a result to the history.
Expand All @@ -46,7 +47,7 @@ func (rh *resultHistory) Add(moduleName, target, debugOutput string, success boo
rh.nextId++

rh.results = append(rh.results, r)
if len(rh.results) > 100 {
if uint(len(rh.results)) > rh.maxResults {
results := make([]*result, len(rh.results)-1)
copy(results, rh.results[1:])
rh.results = results
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
listenAddress = kingpin.Flag("web.listen-address", "The address to listen on for HTTP requests.").Default(":9115").String()
timeoutOffset = kingpin.Flag("timeout-offset", "Offset to subtract from timeout in seconds.").Default("0.5").Float64()
configCheck = kingpin.Flag("config.check", "If true validate the config file and then exit.").Default().Bool()
historyLimit = kingpin.Flag("history.limit", "The maximum amount of items to keep in the history.").Default("100").Uint()

Probers = map[string]prober.ProbeFn{
"http": prober.ProbeHTTP,
Expand Down Expand Up @@ -209,7 +210,7 @@ func main() {
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger := promlog.New(allowedLevel)
rh := &resultHistory{}
rh := &resultHistory{maxResults: *historyLimit}

level.Info(logger).Log("msg", "Starting blackbox_exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", version.BuildContext())
Expand Down

0 comments on commit 0007554

Please sign in to comment.