-
-
Notifications
You must be signed in to change notification settings - Fork 96
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When the global key in the main config file is missing, the application crashes with a panic:
ts=2023-01-19T12:19:18.220Z caller=klog.go:108 level=warn func=Warningf msg="Starting SQL exporter (version=0.9.2, branch=HEAD, revision=e1a5775cca58bf1110516baebc6fe7854d18279b) (go=go1.19.4, platform=linux/amd64, user=root@46fa4bc8dec6, date=20221222-15:10:06)"
ts=2023-01-19T12:19:18.220Z caller=klog.go:84 level=debug func=Infof msg="Loading configuration from sql-exporter.yaml"
ts=2023-01-19T12:19:18.221Z caller=klog.go:84 level=debug func=Infof msg="Loaded collector 'tables' from collectors/tables.yaml"
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8ced68]
goroutine 1 [running]:
gopkg.in/yaml%2ev3.handleErr(0xc0005abbd0)
/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/yaml.go:294 +0x6d
panic({0x10e49a0, 0x1c74650})
/usr/local/go/src/runtime/panic.go:884 +0x212
github.com/burningalchemist/sql_exporter/config.(*Config).UnmarshalYAML(0xc0001d2000, 0x112ed60?)
/app/config/config.go:76 +0x168
gopkg.in/yaml%2ev3.(*decoder).callObsoleteUnmarshaler(0xc0001d2070, 0xc0004bc1e0, {0x7fc5cd458ab0, 0xc0001d2000})
/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/decode.go:379 +0xa7
gopkg.in/yaml%2ev3.(*decoder).prepare(0x0?, 0x0?, {0x11d7f40?, 0xc0001d2000?, 0x0?})
/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/decode.go:427 +0x245
gopkg.in/yaml%2ev3.(*decoder).unmarshal(0xc0001d2070, 0xc0004bc1e0, {0x11d7f40?, 0xc0001d2000?, 0x0?})
/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/decode.go:502 +0x2a5
gopkg.in/yaml%2ev3.(*decoder).document(0x0?, 0x0?, {0x11d7f40?, 0xc0001d2000?, 0xc0002c1800?})
/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/decode.go:527 +0x5b
gopkg.in/yaml%2ev3.(*decoder).unmarshal(0xc0001d2070, 0xc0004bc140, {0x11d7f40?, 0xc0001d2000?, 0x7fc5f4954a68?})
/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/decode.go:498 +0x42d
gopkg.in/yaml%2ev3.unmarshal({0xc0004c0000, 0xf1, 0x200}, {0x112ed60?, 0xc0001d2000}, 0x50?)
/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/yaml.go:167 +0x426
gopkg.in/yaml%2ev3.Unmarshal(...)
/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/yaml.go:89
github.com/burningalchemist/sql_exporter/config.Load({0x7fff28047e35, 0x12})
/app/config/config.go:29 +0x115
github.com/burningalchemist/sql_exporter.NewExporter({0x7fff28047e35?, 0x1b?})
/app/exporter.go:41 +0x33
main.main()
/app/cmd/sql_exporter/main.go:80 +0x529
EDIT: I pasted the wrong panic before, now it is correct.
To Reproduce
Steps to reproduce the behavior:
- Try to start the exporter using the config shown in Configuration. Make sure at least one collector file is present.
- See panic
Expected behavior
In the example file below, it is expected that all the configuration options under global are set to their defaults.
Configuration
target:
data_source_name: 'driver://user:pass@dbhost:5433/dbname'
collectors: [example]
collector_files: ['collectors/*.yaml']Additional context
The panic can be avoided (and defaults for globals applied) by defining an empty-object global: {} key in the config:
global: {}
target:
data_source_name: 'driver://user:pass@dbhost:5433/dbname'
collectors: [example]
collector_files: ['collectors/*.yaml']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working