bryanklewis / prometheus-eventhubs-adapter

Use Azure Event Hubs as a remote storage for Prometheus
Apache License 2.0
10 stars 12 forks source link

Commandline flags not assigned to adapterConfig.writeHub #15

Closed AlvinRamoutar closed 3 years ago

AlvinRamoutar commented 3 years ago

Hey @bryanklewis ,

Noticing that passing commandline flags pertaining to hub.EventHubConfig are not being stored in adapterConfig.writeHub. This results in the following error below:

C:\Users\ramoua\source\repos\prometheus-eventhubs-adapter [test-fix]> go build . ; .\prometheus-eventhubs-adapter.exe --write_connstring "EndPoignant" --log_level debug
{"level":"info","version":"dev","commit":"local","build":"local","timestamp":"2020-12-15T00:25:30Z","message":"prometheus-eventhubs-adapter starting"}
{"level":"debug","listen_address":":9201","log_level":"debug","read_timeout":5000,"telemetry_path":"/metrics","write_adxmapping":"promMap","write_batch":true,"write_path":"/write","write_serializer":"json","write_timeout":10000,"timestamp":"2020-12-15T00:25:30Z","message":"show config"}
{"level":"fatal","error":"unable to determine event hub creation; missing configuration parameter","timestamp":"2020-12-15T00:25:30Z","message":"Failed to create event hub connection"}

There is a connection between viper.RegisterAlias - possibly mutating the config in memory (would need to read into Viper more). Commenting out https://github.com/bryanklewis/prometheus-eventhubs-adapter/blob/130b0eb599726f8691d4f1c6d79d23223b0c4ce9/config.go#L84 fixes the issue:

C:\Users\ramoua\source\repos\prometheus-eventhubs-adapter [test-fix]> go build . ; .\prometheus-eventhubs-adapter.exe --write_connstring "EndPoignant" --log_level debug
{"level":"info","version":"dev","commit":"local","build":"local","timestamp":"2020-12-15T00:25:39Z","message":"prometheus-eventhubs-adapter starting"}
{"level":"debug","listen_address":":9201","log_level":"debug","read_timeout":5000,"telemetry_path":"/metrics","write_adxmapping":"promMap","write_batch":true,"write_connstring":"EndPoignant","write_path":"/write","write_serializer":"json","write_timeout":10000,"timestamp":"2020-12-15T00:25:39Z","message":"show config"}
{"level":"fatal","error":"failed parsing connection string due to unmatched key value separated by '='","timestamp":"2020-12-15T00:25:39Z","message":"Failed to create event hub connection"}

This was discovered by observing pflags via inserting pflag.Lookup("write_connstring").Value.String() in main() after hub.NewClient() call. Lookup was successful, while viper.GetString() was empty.

bryanklewis commented 3 years ago

ive had other problems with Viper, i plan on dropping it in a future release. Using kingpin like some of the official Prometheus exporters do or even just native go commands. Thank-you so much for finding that and offering a fix. working on the merge now.

AlvinRamoutar commented 3 years ago

Thanks for merging, will work with this some more tomorrow and close the ticket then. Viper's not a bad choice - lots of activity over there in comparison to kingpin. By the way @bryanklewis , do you have an estimate release date for v0.4.2? Would like to deploy via docker :)

bryanklewis commented 3 years ago

@AlvinRamoutar, today actually. Should see it there now.