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

Make the history limit a configurable flag #308

Merged
merged 1 commit into from
Apr 13, 2018
Merged
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
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