@@ -17,12 +17,13 @@ package exporter
1717
1818import (
1919 "context"
20+ "fmt"
21+ "log/slog"
2022 "strconv"
2123 "time"
2224
2325 "github.com/pkg/errors"
2426 "github.com/prometheus/client_golang/prometheus"
25- "github.com/sirupsen/logrus"
2627 "go.mongodb.org/mongo-driver/bson"
2728 "go.mongodb.org/mongo-driver/bson/primitive"
2829 "go.mongodb.org/mongo-driver/mongo"
@@ -39,12 +40,12 @@ type currentopCollector struct {
3940var ErrInvalidOrMissingInprogEntry = errors .New ("invalid or missing inprog entry in currentop results" )
4041
4142// newCurrentopCollector creates a collector for being processed queries.
42- func newCurrentopCollector (ctx context.Context , client * mongo.Client , logger * logrus .Logger ,
43+ func newCurrentopCollector (ctx context.Context , client * mongo.Client , logger * slog .Logger ,
4344 compatible bool , topology labelsGetter , currentOpSlowTime string ,
4445) * currentopCollector {
4546 return & currentopCollector {
4647 ctx : ctx ,
47- base : newBaseCollector (client , logger .WithFields (logrus. Fields { "collector" : "currentop" } )),
48+ base : newBaseCollector (client , logger .With ( "collector" , "currentop" )),
4849 compatibleMode : compatible ,
4950 topologyInfo : topology ,
5051 currentopslowtime : currentOpSlowTime ,
@@ -66,7 +67,7 @@ func (d *currentopCollector) collect(ch chan<- prometheus.Metric) {
6667 client := d .base .client
6768 slowtime , err := time .ParseDuration (d .currentopslowtime )
6869 if err != nil {
69- logger .Errorf ("Failed to parse slowtime: %s " , err )
70+ logger .Error ("Failed to parse slowtime" , "error " , err )
7071 ch <- prometheus .NewInvalidMetric (prometheus .NewInvalidDesc (err ), err )
7172 return
7273 }
@@ -90,7 +91,7 @@ func (d *currentopCollector) collect(ch chan<- prometheus.Metric) {
9091
9192 var r primitive.M
9293 if err := res .Decode (& r ); err != nil {
93- logger .Errorf ("Failed to decode currentOp response: %s " , err )
94+ logger .Error ("Failed to decode currentOp response" , "error " , err )
9495 ch <- prometheus .NewInvalidMetric (prometheus .NewInvalidDesc (err ), err )
9596 return
9697 }
@@ -101,7 +102,7 @@ func (d *currentopCollector) collect(ch chan<- prometheus.Metric) {
101102 inprog , ok := r ["inprog" ].(primitive.A )
102103
103104 if ! ok {
104- logger .Errorf ( "Invalid type primitive.A assertion for 'inprog': %T" , r ["inprog" ])
105+ logger .Error ( fmt . Sprintf ( "Invalid type primitive.A assertion for 'inprog': %T" , r ["inprog" ]) )
105106 ch <- prometheus .NewInvalidMetric (prometheus .NewInvalidDesc (ErrInvalidOrMissingInprogEntry ),
106107 ErrInvalidOrMissingInprogEntry )
107108 }
@@ -115,33 +116,33 @@ func (d *currentopCollector) collect(ch chan<- prometheus.Metric) {
115116
116117 bsonMapElement , ok := bsonMap .(primitive.M )
117118 if ! ok {
118- logger .Errorf ( "Invalid type primitive.M assertion for bsonMap: %T" , bsonMapElement )
119+ logger .Error ( fmt . Sprintf ( "Invalid type primitive.M assertion for bsonMap: %T" , bsonMapElement ) )
119120 continue
120121 }
121122 opid , ok := bsonMapElement ["opid" ].(int32 )
122123 if ! ok {
123- logger .Errorf ( "Invalid type int32 assertion for 'opid': %T" , bsonMapElement )
124+ logger .Error ( fmt . Sprintf ( "Invalid type int32 assertion for 'opid': %T" , bsonMapElement ) )
124125 continue
125126 }
126127 namespace , ok := bsonMapElement ["ns" ].(string )
127128 if ! ok {
128- logger .Errorf ( "Invalid type string assertion for 'ns': %T" , bsonMapElement )
129+ logger .Error ( fmt . Sprintf ( "Invalid type string assertion for 'ns': %T" , bsonMapElement ) )
129130 continue
130131 }
131132 db , collection := splitNamespace (namespace )
132133 op , ok := bsonMapElement ["op" ].(string )
133134 if ! ok {
134- logger .Errorf ( "Invalid type string assertion for 'op': %T" , bsonMapElement )
135+ logger .Error ( fmt . Sprintf ( "Invalid type string assertion for 'op': %T" , bsonMapElement ) )
135136 continue
136137 }
137138 desc , ok := bsonMapElement ["desc" ].(string )
138139 if ! ok {
139- logger .Errorf ( "Invalid type string assertion for 'desc': %T" , bsonMapElement )
140+ logger .Error ( fmt . Sprintf ( "Invalid type string assertion for 'desc': %T" , bsonMapElement ) )
140141 continue
141142 }
142143 microsecs_running , ok := bsonMapElement ["microsecs_running" ].(int64 )
143144 if ! ok {
144- logger .Errorf ( "Invalid type int64 assertion for 'microsecs_running': %T" , bsonMapElement )
145+ logger .Error ( fmt . Sprintf ( "Invalid type int64 assertion for 'microsecs_running': %T" , bsonMapElement ) )
145146 continue
146147 }
147148
0 commit comments