@@ -2,6 +2,7 @@ package exporter
22
33import  (
44	"fmt" 
5+ 	"log/slog" 
56	"net/http" 
67	"net/url" 
78	"runtime" 
@@ -16,7 +17,6 @@ import (
1617	"github.com/gomodule/redigo/redis" 
1718	"github.com/prometheus/client_golang/prometheus" 
1819	"github.com/prometheus/client_golang/prometheus/promhttp" 
19- 	log "github.com/sirupsen/logrus" 
2020)
2121
2222type  BuildInfo  struct  {
@@ -93,7 +93,7 @@ type Options struct {
9393
9494// NewRedisExporter returns a new exporter of Redis metrics. 
9595func  NewRedisExporter (uri  string , opts  Options ) (* Exporter , error ) {
96- 	log . Debugf ("NewRedisExporter options: %#v " , opts )
96+ 	slog . Debug ("NewRedisExporter options"  ,  "options "opts )
9797
9898	switch  {
9999	case  strings .HasPrefix (uri , "valkey://" ):
@@ -102,7 +102,7 @@ func NewRedisExporter(uri string, opts Options) (*Exporter, error) {
102102		uri  =  strings .Replace (uri , "valkeys://" , "rediss://" , 1 )
103103	}
104104
105- 	log . Debugf ( "NewRedisExporter = using  redis uri: %s "uri )
105+ 	slog . Debug ( "Using  redis URI" ,  "uri "uri )
106106
107107	e  :=  & Exporter {
108108		redisAddr : uri ,
@@ -403,31 +403,31 @@ func NewRedisExporter(uri string, opts Options) (*Exporter, error) {
403403	if  keys , err  :=  parseKeyArg (opts .CheckKeys ); err  !=  nil  {
404404		return  nil , fmt .Errorf ("couldn't parse check-keys: %s" , err )
405405	} else  {
406- 		log . Debugf ("keys: %#v " , keys )
406+ 		slog . Debug ("keys"  ,  "keys "keys )
407407	}
408408
409409	if  singleKeys , err  :=  parseKeyArg (opts .CheckSingleKeys ); err  !=  nil  {
410410		return  nil , fmt .Errorf ("couldn't parse check-single-keys: %s" , err )
411411	} else  {
412- 		log . Debugf ("singleKeys: %#v " , singleKeys )
412+ 		slog . Debug ("singleKeys"  ,  "singleKeys "singleKeys )
413413	}
414414
415415	if  streams , err  :=  parseKeyArg (opts .CheckStreams ); err  !=  nil  {
416416		return  nil , fmt .Errorf ("couldn't parse check-streams: %s" , err )
417417	} else  {
418- 		log . Debugf ("streams: %#v " , streams )
418+ 		slog . Debug ("streams"  ,  "streams "streams )
419419	}
420420
421421	if  singleStreams , err  :=  parseKeyArg (opts .CheckSingleStreams ); err  !=  nil  {
422422		return  nil , fmt .Errorf ("couldn't parse check-single-streams: %s" , err )
423423	} else  {
424- 		log . Debugf ("singleStreams: %#v " , singleStreams )
424+ 		slog . Debug ("singleStreams"  ,  "singleStreams "singleStreams )
425425	}
426426
427427	if  countKeys , err  :=  parseKeyArg (opts .CountKeys ); err  !=  nil  {
428428		return  nil , fmt .Errorf ("couldn't parse count-keys: %s" , err )
429429	} else  {
430- 		log . Debugf ("countKeys: %#v " , countKeys )
430+ 		slog . Debug ("countKeys"  ,  "countKeys "countKeys )
431431	}
432432
433433	if  opts .InclSystemMetrics  {
@@ -603,13 +603,13 @@ func (e *Exporter) extractConfigMetrics(ch chan<- prometheus.Metric, config []in
603603	for  pos  :=  0 ; pos  <  len (config )/ 2 ; pos ++  {
604604		strKey , err  :=  redis .String (config [pos * 2 ], nil )
605605		if  err  !=  nil  {
606- 			log . Errorf ("invalid config key name, err: %s, skipped " , err )
606+ 			slog . Error ("invalid config key name, skipped"  ,  "error "err )
607607			continue 
608608		}
609609
610610		strVal , err  :=  redis .String (config [pos * 2 + 1 ], nil )
611611		if  err  !=  nil  {
612- 			log . Debugf ("invalid config value for key name %s, err: %s, skipped"  , strKey , err )
612+ 			slog . Debug ("invalid config value for key name, skipped"  ,  "key" , strKey ,  "error" , err )
613613			continue 
614614		}
615615
@@ -665,7 +665,7 @@ func (e *Exporter) extractConfigMetrics(ch chan<- prometheus.Metric, config []in
665665}
666666
667667func  (e  * Exporter ) scrapeRedisHost (ch  chan <-  prometheus.Metric ) error  {
668- 	defer  log . Debugf ( "scrapeRedisHost() done "
668+ 	defer  slog . Debug ( "Finished scraping Redis host "
669669
670670	startTime  :=  time .Now ()
671671	c , err  :=  e .connectToRedis ()
@@ -675,63 +675,63 @@ func (e *Exporter) scrapeRedisHost(ch chan<- prometheus.Metric) error {
675675	if  err  !=  nil  {
676676		var  redactedAddr  string 
677677		if  redisURL , err2  :=  url .Parse (e .redisAddr ); err2  !=  nil  {
678- 			log . Debugf ( "url.Parse( %s ) err: %s" , e .redisAddr , err2 )
678+ 			slog . Debug ( "Failed to parse URL" ,  "address" , e .redisAddr ,  "error" , err2 )
679679			redactedAddr  =  "<redacted>" 
680680		} else  {
681681			redactedAddr  =  redisURL .Redacted ()
682682		}
683- 		log . Errorf ("Couldn't connect to redis instance (%s) " , redactedAddr )
684- 		log . Debugf ( "connectToRedis( %s ) err: %s" , e .redisAddr , err )
683+ 		slog . Error ("Couldn't connect to redis instance"  ,  "address "redactedAddr )
684+ 		slog . Debug ( "Connect to redis failed" ,  "address" , e .redisAddr ,  "error" , err )
685685		return  err 
686686	}
687687	defer  c .Close ()
688688
689- 	log . Debugf ( "connected  to: %s "e .redisAddr )
690- 	log . Debugf ("connecting took %f  seconds" , connectTookSeconds )
689+ 	slog . Debug ( "Connected  to redis" ,  "address "e .redisAddr )
690+ 	slog . Debug ("connecting took seconds"  ,  " seconds"connectTookSeconds )
691691
692692	if  e .options .PingOnConnect  {
693693		startTime  :=  time .Now ()
694694
695695		if  _ , err  :=  doRedisCmd (c , "PING" ); err  !=  nil  {
696- 			log . Errorf ("Couldn't PING server, err: %s " , err )
696+ 			slog . Error ("Couldn't PING server"  ,  "error "err )
697697		} else  {
698698			pingTookSeconds  :=  time .Since (startTime ).Seconds ()
699699			e .registerConstMetricGauge (ch , "exporter_last_scrape_ping_time_seconds" , pingTookSeconds )
700- 			log . Debugf ("PING took %f  seconds" , pingTookSeconds )
700+ 			slog . Debug ("PING took seconds"  ,  " seconds"pingTookSeconds )
701701		}
702702	}
703703
704704	if  e .options .SetClientName  {
705705		if  _ , err  :=  doRedisCmd (c , "CLIENT" , "SETNAME" , "redis_exporter" ); err  !=  nil  {
706- 			log . Errorf ("Couldn't set client name, err: %s " , err )
706+ 			slog . Error ("Couldn't set client name"  ,  "error "err )
707707		}
708708	}
709709
710710	dbCount  :=  0 
711711	if  e .options .ConfigCommandName  ==  "-"  {
712- 		log . Debugf ("Skipping extractConfigMetrics() " )
712+ 		slog . Debug ("Skipping config metrics extraction " )
713713	} else  {
714714		if  config , err  :=  redis .Values (doRedisCmd (c , e .options .ConfigCommandName , "GET" , "*" )); err  ==  nil  {
715715			dbCount , err  =  e .extractConfigMetrics (ch , config )
716716			if  err  !=  nil  {
717- 				log . Errorf ( "Redis extractConfigMetrics() err: %s "err )
717+ 				slog . Error ( "Failed to extract config metrics" ,  "error "err )
718718				return  err 
719719			}
720720		} else  {
721- 			log . Debugf ("Redis CONFIG err: %s " , err )
721+ 			slog . Debug ("Redis CONFIG err"  ,  "error "err )
722722		}
723723	}
724724
725725	infoAll , err  :=  redis .String (doRedisCmd (c , "INFO" , "ALL" ))
726726	if  err  !=  nil  ||  infoAll  ==  ""  {
727- 		log . Debugf ("Redis INFO ALL err: %s " , err )
727+ 		slog . Debug ("Redis INFO ALL err"  ,  "error "err )
728728		infoAll , err  =  redis .String (doRedisCmd (c , "INFO" ))
729729		if  err  !=  nil  {
730- 			log . Errorf ("Redis INFO err: %s " , err )
730+ 			slog . Error ("Redis INFO err"  ,  "error "err )
731731			return  err 
732732		}
733733	}
734- 	log . Debugf ("Redis INFO ALL result: [%#v] " , infoAll )
734+ 	slog . Debug ("Redis INFO ALL result"  ,  "result "infoAll )
735735
736736	if  strings .Contains (infoAll , "cluster_enabled:1" ) {
737737		if  clusterInfo , err  :=  redis .String (doRedisCmd (c , "CLUSTER" , "INFO" )); err  ==  nil  {
@@ -740,7 +740,7 @@ func (e *Exporter) scrapeRedisHost(ch chan<- prometheus.Metric) error {
740740			// in cluster mode Redis only supports one database, so no extra DB number padding needed 
741741			dbCount  =  1 
742742		} else  {
743- 			log . Errorf ("Redis CLUSTER INFO err: %s " , err )
743+ 			slog . Error ("Redis CLUSTER INFO err"  ,  "error "err )
744744		}
745745	} else  if  dbCount  ==  0  {
746746		// in non-cluster mode, if dbCount is zero, then "CONFIG" failed to retrieve a valid 
@@ -749,7 +749,7 @@ func (e *Exporter) scrapeRedisHost(ch chan<- prometheus.Metric) error {
749749		dbCount  =  16 
750750	}
751751
752- 	log . Debugf ("dbCount: %d " , dbCount )
752+ 	slog . Debug ("dbCount"  ,  "count "dbCount )
753753
754754	role  :=  e .extractInfoMetrics (ch , infoAll , dbCount )
755755
@@ -759,17 +759,17 @@ func (e *Exporter) scrapeRedisHost(ch chan<- prometheus.Metric) error {
759759
760760	// skip these metrics for master if SkipCheckKeysForRoleMaster is set 
761761	// (can help with reducing workload on the master node) 
762- 	log . Debugf ("checkKeys metric collection for role: %s  SkipCheckKeysForRoleMaster flag: %#v"  , role , e .options .SkipCheckKeysForRoleMaster )
762+ 	slog . Debug ("checkKeys metric collection for role"  ,  "role" , role ,  "SkipCheckKeysForRoleMaster" , e .options .SkipCheckKeysForRoleMaster )
763763	if  role  ==  InstanceRoleSlave  ||  ! e .options .SkipCheckKeysForRoleMaster  {
764764		if  err  :=  e .extractCheckKeyMetrics (ch , c ); err  !=  nil  {
765- 			log . Errorf ( "extractCheckKeyMetrics() err: %s "err )
765+ 			slog . Error ( "Failed to extract check key metrics" ,  "error "err )
766766		}
767767
768768		e .extractCountKeysMetrics (ch , c )
769769
770770		e .extractStreamMetrics (ch , c )
771771	} else  {
772- 		log . Infof ("skipping checkKeys metrics,  role: %s  flag: %#v " , role , e .options .SkipCheckKeysForRoleMaster )
772+ 		slog . Info ("skipping checkKeys metrics"  ,  " role"role ,  "flag" , e .options .SkipCheckKeysForRoleMaster )
773773	}
774774
775775	e .extractSlowLogMetrics (ch , c )
0 commit comments