44package collector
55
66import (
7+ "log/slog"
78 "slices"
89 "strconv"
910 "strings"
@@ -13,7 +14,7 @@ import (
1314// isScrapeMetric returns true if a metric should be scraped. Metrics may not be scraped if they have a custom scrape interval,
1415// and the time since the last scrape is less than the custom scrape interval.
1516// If there is no tick time or last known tick, the metric is always scraped.
16- func ( e * Exporter ) isScrapeMetric ( tick * time.Time , metric * Metric , d * Database ) bool {
17+ func isScrapeMetric ( logger * slog. Logger , tick * time.Time , metric * Metric , d * Database ) bool {
1718 // If the metric isn't enabled for the database, don't scrape it.
1819 if ! metric .IsEnabledForDatabase (d ) {
1920 return false
@@ -24,7 +25,7 @@ func (e *Exporter) isScrapeMetric(tick *time.Time, metric *Metric, d *Database)
2425 return true
2526 }
2627 // If the metric doesn't have a custom scrape interval, scrape it.
27- interval , ok := e . getScrapeInterval (metric .Context , metric .ScrapeInterval )
28+ interval , ok := getScrapeInterval (logger , metric .Context , metric .ScrapeInterval )
2829 if ! ok {
2930 return true
3031 }
@@ -39,39 +40,39 @@ func (e *Exporter) isScrapeMetric(tick *time.Time, metric *Metric, d *Database)
3940 return shouldScrape
4041}
4142
42- func ( e * Exporter ) getScrapeInterval ( context , scrapeInterval string ) (time.Duration , bool ) {
43+ func getScrapeInterval ( logger * slog. Logger , context , scrapeInterval string ) (time.Duration , bool ) {
4344 if len (scrapeInterval ) > 0 {
4445 si , err := time .ParseDuration (scrapeInterval )
4546 if err != nil {
46- e . logger .Error ("Unable to convert scrapeinterval to duration (metric=" + context + ")" )
47+ logger .Error ("Unable to convert scrapeinterval to duration (metric=" + context + ")" )
4748 return 0 , false
4849 }
4950 return si , true
5051 }
5152 return 0 , false
5253}
5354
54- func ( e * Exporter ) getQueryTimeout ( metric * Metric , d * Database ) time.Duration {
55+ func getQueryTimeout ( logger * slog. Logger , metric * Metric , d * Database ) time.Duration {
5556 if len (metric .QueryTimeout ) > 0 {
5657 qt , err := time .ParseDuration (metric .QueryTimeout )
5758 if err != nil {
58- e . logger .Error ("Unable to convert querytimeout to duration (metric=" + metric .Context + ")" )
59+ logger .Error ("Unable to convert querytimeout to duration (metric=" + metric .Context + ")" )
5960 return time .Duration (d .Config .GetQueryTimeout ()) * time .Second
6061 }
6162 return qt
6263 }
6364 return time .Duration (d .Config .GetQueryTimeout ()) * time .Second
6465}
6566
66- func ( e * Exporter ) parseFloat ( metric , metricHelp string , row map [string ]string ) (float64 , bool ) {
67+ func parseFloat ( logger * slog. Logger , metric , metricHelp string , row map [string ]string ) (float64 , bool ) {
6768 value , ok := row [metric ]
6869 if ! ok || value == "<nil>" {
6970 // treat nil value as 0
7071 return 0.0 , ok
7172 }
7273 valueFloat , err := strconv .ParseFloat (strings .TrimSpace (value ), 64 )
7374 if err != nil {
74- e . logger .Error ("Unable to convert current value to float (metric=" + metric +
75+ logger .Error ("Unable to convert current value to float (metric=" + metric +
7576 ",metricHelp=" + metricHelp + ",value=<" + row [metric ] + ">)" )
7677 return - 1 , false
7778 }
0 commit comments