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

feat: Allow disabling reload monitoring #730

Merged
merged 2 commits into from
Jun 21, 2023
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
3 changes: 2 additions & 1 deletion config.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Honeycomb Refinery Configuration Documentation

This is the documentation for the configuration file for Honeycomb's Refinery.
It was automatically generated on 2023-06-20 at 18:40:47 UTC.
It was automatically generated on 2023-06-21 at 17:32:11 UTC.

## The Config file

Expand Down Expand Up @@ -95,6 +95,7 @@ ConfigReloadInterval is the average interval between attempts at reloading the c
A single instance of Refinery will attempt to read its configuration and check for changes at approximately this interval.
This time is varied by a random amount to avoid all instances refreshing together.
Within a cluster, Refinery will gossip information about new configuration so that all instances can reload at close to the same time.
This feature can be disabled with a value of 0s.

- Not eligible for live reload.
- Type: `duration`
Expand Down
27 changes: 27 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,33 @@ func TestReload(t *testing.T) {

}

func TestReloadDisabled(t *testing.T) {
cm := makeYAML("General.ConfigurationVersion", 2, "General.ConfigReloadInterval", Duration(0*time.Second), "Network.ListenAddr", "0.0.0.0:8080")
rm := makeYAML("ConfigVersion", 2)
config, rules := createTempConfigs(t, cm, rm)
defer os.Remove(rules)
defer os.Remove(config)
c, err := getConfig([]string{"--no-validate", "--config", config, "--rules_config", rules})
assert.NoError(t, err)

if d, _ := c.GetListenAddr(); d != "0.0.0.0:8080" {
t.Error("received", d, "expected", "0.0.0.0:8080")
}

if file, err := os.OpenFile(config, os.O_RDWR, 0644); err == nil {
// Since we disabled reload checking this should not change anything
cm := makeYAML("General.ConfigurationVersion", 2, "General.ConfigReloadInterval", Duration(0*time.Second), "Network.ListenAddr", "0.0.0.0:9000")
file.WriteString(cm)
file.Close()
}

time.Sleep(5 * time.Second)

if d, _ := c.GetListenAddr(); d != "0.0.0.0:8080" {
t.Error("received", d, "expected", "0.0.0.0:8080")
}
}

func TestReadDefaults(t *testing.T) {
c, err := getConfig([]string{"--no-validate", "--config", "../config.yaml", "--rules_config", "../rules.yaml"})
assert.NoError(t, err)
Expand Down
14 changes: 10 additions & 4 deletions config/file_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ func NewConfig(opts *CmdEnv, errorCallback func(error)) (Config, error) {
cfg.callbacks = make([]func(), 0)
cfg.errorCallback = errorCallback

go cfg.monitor()
if cfg.mainConfig.General.ConfigReloadInterval > 0 {
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
go cfg.monitor()
}

return cfg, err
}
Expand Down Expand Up @@ -409,9 +411,13 @@ func (f *fileConfig) monitor() {

// Stop halts the monitor goroutine
func (f *fileConfig) Stop() {
f.ticker.Stop()
close(f.done)
f.done = nil
if f.ticker != nil {
f.ticker.Stop()
}
if f.done != nil {
close(f.done)
f.done = nil
}
}

func (f *fileConfig) RegisterReloadCallback(cb func()) {
Expand Down
4 changes: 2 additions & 2 deletions config/metadata/configMeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ groups:
reload: false
validations:
- type: minimum
arg: 1s
arg: 0s
summary: is the average interval between attempts at reloading the configuration file.
description: >
A single instance of Refinery will attempt to read its configuration
and check for changes at approximately this interval. This time is
varied by a random amount to avoid all instances refreshing together.
Within a cluster, Refinery will gossip information about new
configuration so that all instances can reload at close to the same
time.
time. This feature can be disabled with a value of 0s.

- name: Network
title: "Network Configuration"
Expand Down
2 changes: 1 addition & 1 deletion tools/convert/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ validateRules:
@echo
@echo "+++ validating sample rules"
@echo
go run . validate rules --input=rules_complete.yaml
go run . validate rules --input=../../rules_complete.yaml
4 changes: 2 additions & 2 deletions tools/convert/templates/configV2.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Honeycomb Refinery Configuration ##
######################################
#
# created {{ now }} from {{ .Input }} using a template generated on 2023-06-20 at 18:40:46 UTC
# created {{ now }} from {{ .Input }} using a template generated on 2023-06-21 at 17:32:10 UTC

# This file contains the configuration for the Honeycomb Refinery.
# More stuff will go here later.
Expand Down Expand Up @@ -58,7 +58,7 @@ General:
## varied by a random amount to avoid all instances refreshing together.
## Within a cluster, Refinery will gossip information about new
## configuration so that all instances can reload at close to the same
## time.
## time. This feature can be disabled with a value of 0s.
##
## Accepts a duration string with units, like "5m".
## default: 5m
Expand Down