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 config initialization public #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type Config struct {
}

// Validate and update exporter configuration
func (c *Config) validateAndUpdate() {
func (c *Config) ValidateAndUpdate() {
if c.AeroProm.Bind == "" {
c.AeroProm.Bind = ":9145"
}
Expand All @@ -142,7 +142,7 @@ func (c *Config) validateAndUpdate() {
}

// Initialize exporter configuration
func initConfig(configFile string, config *Config) {
func InitConfig(configFile string, config *Config) {
// to print everything out regarding reading the config in app init
log.SetLevel(log.DebugLevel)

Expand Down
2 changes: 1 addition & 1 deletion gauge_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GaugeStats struct {
}

// Initialize exporter configuration
func initGaugeStats(pGaugeStatsFile string, pGaugeStats *GaugeStats) {
func InitGaugeStats(pGaugeStatsFile string, pGaugeStats *GaugeStats) {

log.Infof("Loading Gauge Stats file %s", pGaugeStatsFile)

Expand Down
8 changes: 4 additions & 4 deletions gauge_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestGetGaugesNotEmpty(t *testing.T) {
// Initialize and validate Gauge config
gaugeList := new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeList)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeList)

nslist := gaugeList.NamespaceStats
nodelist := gaugeList.NodeStats
Expand All @@ -36,7 +36,7 @@ func TestGetGaugesCounts(t *testing.T) {
// Initialize and validate Gauge config
gaugeList := new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeList)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeList)

glist := gaugeList.NamespaceStats
assert.Equal(t, len(glist), 96)
Expand All @@ -63,7 +63,7 @@ func TestIsAGaugeTrue(t *testing.T) {
// Initialize and validate Gauge config
gaugeList := new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeList)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeList)

exists := false

Expand Down Expand Up @@ -94,7 +94,7 @@ func TestNoGaugeExists(t *testing.T) {
// Initialize and validate Gauge config
gaugeList := new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeList)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeList)

exists := gaugeList.isGauge(CTX_NAMESPACE, "non-existing-key")
assert.Equal(t, exists, false)
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ func main() {
log.Infof("Welcome to Aerospike Prometheus Exporter %s", version)

config = new(Config)
initConfig(*configFile, config)
config.validateAndUpdate()
InitConfig(*configFile, config)
config.ValidateAndUpdate()

// initialize Gauge metric definitions
gaugeStatHandler = new(GaugeStats)
initGaugeStats(*gaugeStatsFile, gaugeStatHandler)
InitGaugeStats(*gaugeStatsFile, gaugeStatHandler)

fullHost = net.JoinHostPort(config.Aerospike.Host, strconv.Itoa(int(config.Aerospike.Port)))

host := aero.NewHost(config.Aerospike.Host, int(config.Aerospike.Port))
host.TLSName = config.Aerospike.NodeTLSName

observer, err := newObserver(host, config.Aerospike.User, config.Aerospike.Password)
observer, err := NewObserver(host, config.Aerospike.User, config.Aerospike.Password)
if err != nil {
log.Fatalln(err)
}
Expand Down
2 changes: 1 addition & 1 deletion observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func initAerospikeTLS() *tls.Config {
return tlsConfig
}

func newObserver(server *aero.Host, user, pass string) (o *Observer, err error) {
func NewObserver(server *aero.Host, user, pass string) (o *Observer, err error) {
// initialize aerospike_node_up metric descriptor
nodeActiveDesc = prometheus.NewDesc(
"aerospike_node_up",
Expand Down
16 changes: 8 additions & 8 deletions watcher_latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestLatencies_PassTwoKeys(t *testing.T) {
fmt.Println("initializing config ... TestLatencies_PassTwoKeys")
// Initialize and validate config
config = new(Config)
initConfig(DEFAULT_APE_TOML, config)
config.validateAndUpdate()
InitConfig(DEFAULT_APE_TOML, config)
config.ValidateAndUpdate()

watcher := new(LatencyWatcher)

Expand All @@ -50,8 +50,8 @@ func TestLatencies_RefreshDefault(t *testing.T) {
fmt.Println("initializing config ... TestLatencies_RefreshDefault")
// Initialize and validate config
config = new(Config)
initConfig(DEFAULT_APE_TOML, config)
config.validateAndUpdate()
InitConfig(DEFAULT_APE_TOML, config)
config.ValidateAndUpdate()

// run the test-case logic
latencies_runTestCase(t)
Expand All @@ -65,14 +65,14 @@ func TestLatencies_RefreshWithLabelsConfig(t *testing.T) {
fmt.Println("initializing config ... TestLatencies_RefreshWithLabelsConfig")
// Initialize and validate config
config = new(Config)
initConfig(LABELS_APE_TOML, config)
config.validateAndUpdate()
InitConfig(LABELS_APE_TOML, config)
config.ValidateAndUpdate()

watcher := new(LatencyWatcher)

gaugeStatHandler = new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
rawMetrics := getRawMetrics()

lObserver := &Observer{}
Expand Down Expand Up @@ -127,7 +127,7 @@ func latencies_runTestCase(t *testing.T) {

gaugeStatHandler = new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
rawMetrics := getRawMetrics()

lObserver := &Observer{}
Expand Down
18 changes: 9 additions & 9 deletions watcher_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func TestNamespaceRefreshDefault(t *testing.T) {
fmt.Println("initializing config ... TestNamespaceRefreshDefault")
// Initialize and validate config
config = new(Config)
initConfig(DEFAULT_APE_TOML, config)
InitConfig(DEFAULT_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

runTestcase(t)
os.Setenv(TESTCASE_MODE, TESTCASE_MODE_FALSE)
Expand All @@ -64,9 +64,9 @@ func TestNamespaceRefreshLabels(t *testing.T) {
fmt.Println("initializing config ... TestNamespaceRefreshLabels")
// Initialize and validate config
config = new(Config)
initConfig(LABELS_APE_TOML, config)
InitConfig(LABELS_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

runTestcase(t)
os.Setenv(TESTCASE_MODE, TESTCASE_MODE_FALSE)
Expand All @@ -80,9 +80,9 @@ func TestNamespaceRefreshAllowlist(t *testing.T) {
fmt.Println("initializing config ... TestNamespaceRefreshAllowlist")
// Initialize and validate config
config = new(Config)
initConfig(NS_ALLOWLIST_APE_TOML, config)
InitConfig(NS_ALLOWLIST_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

runTestcase(t)

Expand All @@ -96,9 +96,9 @@ func TestNamespaceRefreshBlocklist(t *testing.T) {
fmt.Println("initializing config ... TestNamespaceRefreshBlocklist")
// Initialize and validate config
config = new(Config)
initConfig(NS_BLOCKLIST_APE_TOML, config)
InitConfig(NS_BLOCKLIST_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

runTestcase(t)

Expand All @@ -111,7 +111,7 @@ func runTestcase(t *testing.T) {

gaugeStatHandler = new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)

// read raw-metrics from mock data gen, create observer and channel prometeus metric ingestion and processing
rawMetrics := getRawMetrics()
Expand Down
14 changes: 7 additions & 7 deletions watcher_node_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func TestNodeStats_RefreshDefault(t *testing.T) {
fmt.Println("initializing config ... TestNodeStats_RefreshDefault")
// Initialize and validate config
config = new(Config)
initConfig(DEFAULT_APE_TOML, config)
InitConfig(DEFAULT_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

// run the test-case logic
nodeStats_runTestCase(t)
Expand All @@ -54,9 +54,9 @@ func TestNodeStats_Allowlist(t *testing.T) {
fmt.Println("initializing config ... TestNodeStats_Allowlist")
// Initialize and validate config
config = new(Config)
initConfig(NS_ALLOWLIST_APE_TOML, config)
InitConfig(NS_ALLOWLIST_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

// run the test-case logic
nodeStats_runTestCase(t)
Expand All @@ -70,9 +70,9 @@ func TestNodeStats_Blocklist(t *testing.T) {
fmt.Println("initializing config ... TestNodeStats_Blocklist")
// Initialize and validate config
config = new(Config)
initConfig(NS_BLOCKLIST_APE_TOML, config)
InitConfig(NS_BLOCKLIST_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

// run the test-case logic
nodeStats_runTestCase(t)
Expand All @@ -88,7 +88,7 @@ func nodeStats_runTestCase(t *testing.T) {

gaugeStatHandler = new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
rawMetrics := getRawMetrics()

lObserver := &Observer{}
Expand Down
16 changes: 8 additions & 8 deletions watcher_sets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func TestSets_RefreshDefault(t *testing.T) {
fmt.Println("initializing config ... TestSets_RefreshDefault")
// Initialize and validate config
config = new(Config)
initConfig(DEFAULT_APE_TOML, config)
InitConfig(DEFAULT_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

// run the test-case logic
sets_runTestCase(t)
Expand All @@ -54,9 +54,9 @@ func TestSets_Allowlist(t *testing.T) {
fmt.Println("initializing config ... TestSets_Allowlist")
// Initialize and validate config
config = new(Config)
initConfig(NS_ALLOWLIST_APE_TOML, config)
InitConfig(NS_ALLOWLIST_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

// run the test-case logic
sets_runTestCase(t)
Expand All @@ -70,14 +70,14 @@ func TestSets_RefreshWithLabelsConfig(t *testing.T) {
fmt.Println("initializing config ... TestSets_RefreshWithLabelsConfig")
// Initialize and validate config
config = new(Config)
initConfig(LABELS_APE_TOML, config)
config.validateAndUpdate()
InitConfig(LABELS_APE_TOML, config)
config.ValidateAndUpdate()

watcher := new(SetWatcher)

gaugeStatHandler = new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
rawMetrics := getRawMetrics()

lObserver := &Observer{}
Expand Down Expand Up @@ -132,7 +132,7 @@ func sets_runTestCase(t *testing.T) {

gaugeStatHandler = new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
rawMetrics := getRawMetrics()

lObserver := &Observer{}
Expand Down
20 changes: 10 additions & 10 deletions watcher_sindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func TestSindex_PassOneKeys(t *testing.T) {
watcher := new(SindexWatcher)

config = new(Config)
initConfig(LABELS_APE_TOML, config)
config.validateAndUpdate()
InitConfig(LABELS_APE_TOML, config)
config.ValidateAndUpdate()

// Check passoneKeys
passOneKeysOutputs := watcher.passOneKeys()
Expand Down Expand Up @@ -48,9 +48,9 @@ func TestSindex_RefreshDefault(t *testing.T) {
fmt.Println("initializing config ... TestSindex_RefreshDefault")
// Initialize and validate config
config = new(Config)
initConfig(DEFAULT_APE_TOML, config)
InitConfig(DEFAULT_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

// run the test-case logic
sindex_runTestCase(t)
Expand All @@ -64,9 +64,9 @@ func TestSindex_Allowlist(t *testing.T) {
fmt.Println("initializing config ... TestSets_Allowlist")
// Initialize and validate config
config = new(Config)
initConfig(NS_ALLOWLIST_APE_TOML, config)
InitConfig(NS_ALLOWLIST_APE_TOML, config)

config.validateAndUpdate()
config.ValidateAndUpdate()

// run the test-case logic
sindex_runTestCase(t)
Expand All @@ -80,14 +80,14 @@ func TestSindex_RefreshWithLabelsConfig(t *testing.T) {
fmt.Println("initializing config ... TestSindex_RefreshWithLabelsConfig")
// Initialize and validate config
config = new(Config)
initConfig(LABELS_APE_TOML, config)
config.validateAndUpdate()
InitConfig(LABELS_APE_TOML, config)
config.ValidateAndUpdate()

watcher := new(SindexWatcher)

gaugeStatHandler = new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
rawMetrics := getRawMetrics()

lObserver := &Observer{}
Expand Down Expand Up @@ -143,7 +143,7 @@ func sindex_runTestCase(t *testing.T) {

gaugeStatHandler = new(GaugeStats)

initGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
InitGaugeStats(METRICS_CONFIG_FILE, gaugeStatHandler)
rawMetrics := getRawMetrics()

lObserver := &Observer{}
Expand Down
Loading