chore(exporter): rework exporter to fix wrong histogram usage and cache metric data
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful

This commit is contained in:
Tom Neuber 2025-01-10 14:33:44 +01:00
parent 4d2a7acebc
commit 8b7f45563a
Signed by: tom
GPG key ID: F17EFE4272D89FF6
6 changed files with 180 additions and 312 deletions

View file

@ -17,6 +17,7 @@ type AppSettings struct {
ReadHeaderTimeout time.Duration
EnableExporter bool
ExporterAddress string
ExporterInterval time.Duration
}
//nolint:lll // ignore line length
@ -28,6 +29,7 @@ type CLI struct {
ReadHeaderTimeout string `name:"read-header-timeout" env:"GEOIP_READ_HEADER_TIMEOUT" help:"timeout for reading http header" default:"${default_read_header_timeout}"`
EnableExporter bool `name:"enable-exporter" env:"GEOIP_ENABLE_EXPORTER" help:"enable prometheus exporter" default:"${default_enable_exporter}"`
ExporterAddress string `name:"exporter-address" env:"GEOIP_EXPORTER_ADDRESS" help:"Address to use for the prometheus metrics server" default:"${default_exporter_address}"`
ExporterInterval string `name:"exporter-interval" env:"GEOIP_EXPORTER_INTERVAL" help:"Interval to scrape the new metrics data" default:"${default_exporter_interval}"`
}
func (c *CLI) Parse() (*AppSettings, error) {
@ -40,6 +42,7 @@ func (c *CLI) Parse() (*AppSettings, error) {
"default_read_header_timeout": "3s",
"default_enable_exporter": "false",
"default_exporter_address": ":9191",
"default_exporter_interval": "5s",
},
kong.Name("country-geo-locations"),
kong.Description("🚀 Start a simple web server for GeoIP data"),
@ -56,6 +59,11 @@ func (c *CLI) Parse() (*AppSettings, error) {
return nil, err
}
exporterInterval, err := time.ParseDuration(c.ExporterInterval)
if err != nil {
return nil, err
}
if c.DataURL == "" {
return nil, ErrInvalidDataURL
}
@ -68,5 +76,6 @@ func (c *CLI) Parse() (*AppSettings, error) {
ReadHeaderTimeout: readHeaderTimeout,
EnableExporter: c.EnableExporter,
ExporterAddress: c.ExporterAddress,
ExporterInterval: exporterInterval,
}, nil
}