Skip to content

Commit f0725fe

Browse files
committed
Remove deprecated errors package
Remove use of deprecated errors package and replace with `fmt` use. Signed-off-by: SuperQ <[email protected]>
1 parent 62e266f commit f0725fe

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

Diff for: go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/alecthomas/kingpin/v2 v2.4.0
77
github.com/coreos/go-systemd/v22 v22.5.0
88
github.com/godbus/dbus/v5 v5.1.0
9-
github.com/pkg/errors v0.9.1
109
github.com/prometheus/client_golang v1.21.1
1110
github.com/prometheus/common v0.62.0
1211
github.com/prometheus/exporter-toolkit v0.13.2

Diff for: go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
3434
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
3535
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
3636
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
37-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
38-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3937
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4038
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4139
github.com/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGCQ8YOmu+Ibk=

Diff for: systemd/systemd.go

+24-25
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929

3030
kingpin "github.com/alecthomas/kingpin/v2"
3131
"github.com/coreos/go-systemd/v22/dbus"
32-
"github.com/pkg/errors"
3332
"github.com/prometheus/client_golang/prometheus"
3433
)
3534

@@ -48,7 +47,7 @@ var (
4847
var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"}
4948

5049
var (
51-
errGetPropertyMsg = "couldn't get unit's %s property"
50+
errGetPropertyMsg = "couldn't get unit's %s property: %w"
5251
errConvertUint64PropertyMsg = "couldn't convert unit's %s property %v to uint64"
5352
errConvertUint32PropertyMsg = "couldn't convert unit's %s property %v to uint32"
5453
errConvertStringPropertyMsg = "couldn't convert unit's %s property %v to string"
@@ -301,7 +300,7 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
301300
begin := time.Now()
302301
conn, err := c.newDbus()
303302
if err != nil {
304-
return errors.Wrapf(err, "couldn't get dbus connection")
303+
return fmt.Errorf("couldn't get dbus connection: %w", err)
305304
}
306305
defer conn.Close()
307306

@@ -317,7 +316,7 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
317316

318317
allUnits, err := conn.ListUnitsContext(c.ctx)
319318
if err != nil {
320-
return errors.Wrap(err, "could not get list of systemd units from dbus")
319+
return fmt.Errorf("could not get list of systemd units from dbus: %w", err)
321320
}
322321

323322
c.logger.Debug("systemd ListUnits took", "seconds", time.Since(begin).Seconds())
@@ -493,11 +492,11 @@ func (c *Collector) collectUnitTimeMetrics(conn *dbus.Conn, ch chan<- prometheus
493492
func (c *Collector) collectUnitTimeMetric(conn *dbus.Conn, ch chan<- prometheus.Metric, unit dbus.UnitStatus, desc *prometheus.Desc, propertyName string) error {
494493
timestampValue, err := conn.GetUnitPropertyContext(c.ctx, unit.Name, propertyName)
495494
if err != nil {
496-
return errors.Wrapf(err, errGetPropertyMsg, propertyName)
495+
return fmt.Errorf(errGetPropertyMsg, propertyName, err)
497496
}
498497
startTimeUsec, ok := timestampValue.Value.Value().(uint64)
499498
if !ok {
500-
return errors.Errorf(errConvertUint64PropertyMsg, propertyName, timestampValue.Value.Value())
499+
return fmt.Errorf(errConvertUint64PropertyMsg, propertyName, timestampValue.Value.Value())
501500
}
502501

503502
ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, float64(startTimeUsec)/1e6, unit.Name, parseUnitType(unit))
@@ -510,12 +509,12 @@ func (c *Collector) collectMountMetainfo(conn *dbus.Conn, ch chan<- prometheus.M
510509
// TODO: wrap GetUnitTypePropertyString(
511510
serviceTypeProperty, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Mount", "Type")
512511
if err != nil {
513-
return errors.Wrapf(err, errGetPropertyMsg, "Type")
512+
return fmt.Errorf(errGetPropertyMsg, "Type", err)
514513
}
515514

516515
serviceType, ok := serviceTypeProperty.Value.Value().(string)
517516
if !ok {
518-
return errors.Errorf(errConvertStringPropertyMsg, "Type", serviceTypeProperty.Value.Value())
517+
return fmt.Errorf(errConvertStringPropertyMsg, "Type", serviceTypeProperty.Value.Value())
519518
}
520519

521520
ch <- prometheus.MustNewConstMetric(
@@ -529,11 +528,11 @@ func (c *Collector) collectMountMetainfo(conn *dbus.Conn, ch chan<- prometheus.M
529528
func (c *Collector) collectServiceMetainfo(conn *dbus.Conn, ch chan<- prometheus.Metric, unit dbus.UnitStatus) error {
530529
serviceTypeProperty, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Service", "Type")
531530
if err != nil {
532-
return errors.Wrapf(err, errGetPropertyMsg, "Type")
531+
return fmt.Errorf(errGetPropertyMsg, "Type", err)
533532
}
534533
serviceType, ok := serviceTypeProperty.Value.Value().(string)
535534
if !ok {
536-
return errors.Errorf(errConvertStringPropertyMsg, "Type", serviceTypeProperty.Value.Value())
535+
return fmt.Errorf(errConvertStringPropertyMsg, "Type", serviceTypeProperty.Value.Value())
537536
}
538537

539538
ch <- prometheus.MustNewConstMetric(
@@ -545,11 +544,11 @@ func (c *Collector) collectServiceMetainfo(conn *dbus.Conn, ch chan<- prometheus
545544
func (c *Collector) collectServiceRestartCount(conn *dbus.Conn, ch chan<- prometheus.Metric, unit dbus.UnitStatus) error {
546545
restartsCount, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Service", "NRestarts")
547546
if err != nil {
548-
return errors.Wrapf(err, errGetPropertyMsg, "NRestarts")
547+
return fmt.Errorf(errGetPropertyMsg, "NRestarts", err)
549548
}
550549
val, ok := restartsCount.Value.Value().(uint32)
551550
if !ok {
552-
return errors.Errorf(errConvertUint32PropertyMsg, "NRestarts", restartsCount.Value.Value())
551+
return fmt.Errorf(errConvertUint32PropertyMsg, "NRestarts", restartsCount.Value.Value())
553552
}
554553
ch <- prometheus.MustNewConstMetric(
555554
c.nRestartsDesc, prometheus.CounterValue,
@@ -565,11 +564,11 @@ func (c *Collector) collectServiceStartTimeMetrics(conn *dbus.Conn, ch chan<- pr
565564
case "active":
566565
timestampValue, err := conn.GetUnitPropertyContext(c.ctx, unit.Name, "ActiveEnterTimestamp")
567566
if err != nil {
568-
return errors.Wrapf(err, errGetPropertyMsg, "ActiveEnterTimestamp")
567+
return fmt.Errorf(errGetPropertyMsg, "ActiveEnterTimestamp", err)
569568
}
570569
startTime, ok := timestampValue.Value.Value().(uint64)
571570
if !ok {
572-
return errors.Errorf(errConvertUint64PropertyMsg, "ActiveEnterTimestamp", timestampValue.Value.Value())
571+
return fmt.Errorf(errConvertUint64PropertyMsg, "ActiveEnterTimestamp", timestampValue.Value.Value())
573572
}
574573
startTimeUsec = startTime
575574

@@ -587,7 +586,7 @@ func (c *Collector) collectServiceStartTimeMetrics(conn *dbus.Conn, ch chan<- pr
587586
func (c *Collector) collectSocketConnMetrics(conn *dbus.Conn, ch chan<- prometheus.Metric, unit dbus.UnitStatus) error {
588587
acceptedConnectionCount, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Socket", "NAccepted")
589588
if err != nil {
590-
return errors.Wrapf(err, errGetPropertyMsg, "NAccepted")
589+
return fmt.Errorf(errGetPropertyMsg, "NAccepted", err)
591590
}
592591

593592
ch <- prometheus.MustNewConstMetric(
@@ -596,7 +595,7 @@ func (c *Collector) collectSocketConnMetrics(conn *dbus.Conn, ch chan<- promethe
596595

597596
currentConnectionCount, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Socket", "NConnections")
598597
if err != nil {
599-
return errors.Wrapf(err, errGetPropertyMsg, "NConnections")
598+
return fmt.Errorf(errGetPropertyMsg, "NConnections", err)
600599
}
601600
ch <- prometheus.MustNewConstMetric(
602601
c.socketCurrentConnectionsDesc, prometheus.GaugeValue,
@@ -605,7 +604,7 @@ func (c *Collector) collectSocketConnMetrics(conn *dbus.Conn, ch chan<- promethe
605604
// NRefused wasn't added until systemd 239.
606605
refusedConnectionCount, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Socket", "NRefused")
607606
if err != nil {
608-
return errors.Wrapf(err, errGetPropertyMsg, "NRefused")
607+
return fmt.Errorf(errGetPropertyMsg, "NRefused", err)
609608
}
610609
ch <- prometheus.MustNewConstMetric(
611610
c.socketRefusedConnectionsDesc, prometheus.GaugeValue,
@@ -625,12 +624,12 @@ func (c *Collector) collectIPAccountingMetrics(conn *dbus.Conn, ch chan<- promet
625624
for propertyName, desc := range unitPropertyToPromDesc {
626625
property, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Service", propertyName)
627626
if err != nil {
628-
return errors.Wrapf(err, errGetPropertyMsg, propertyName)
627+
return fmt.Errorf(errGetPropertyMsg, propertyName, err)
629628
}
630629

631630
counter, ok := property.Value.Value().(uint64)
632631
if !ok {
633-
return errors.Errorf(errConvertUint64PropertyMsg, propertyName, property.Value.Value())
632+
return fmt.Errorf(errConvertUint64PropertyMsg, propertyName, property.Value.Value())
634633
}
635634

636635
ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue,
@@ -645,12 +644,12 @@ func (c *Collector) collectIPAccountingMetrics(conn *dbus.Conn, ch chan<- promet
645644
func (c *Collector) collectServiceTasksMetrics(conn *dbus.Conn, ch chan<- prometheus.Metric, unit dbus.UnitStatus) error {
646645
tasksCurrentCount, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Service", "TasksCurrent")
647646
if err != nil {
648-
return errors.Wrapf(err, errGetPropertyMsg, "TasksCurrent")
647+
return fmt.Errorf(errGetPropertyMsg, "TasksCurrent", err)
649648
}
650649

651650
currentCount, ok := tasksCurrentCount.Value.Value().(uint64)
652651
if !ok {
653-
return errors.Errorf(errConvertUint64PropertyMsg, "TasksCurrent", tasksCurrentCount.Value.Value())
652+
return fmt.Errorf(errConvertUint64PropertyMsg, "TasksCurrent", tasksCurrentCount.Value.Value())
654653
}
655654

656655
// Don't set if tasksCurrent if dbus reports MaxUint64.
@@ -662,12 +661,12 @@ func (c *Collector) collectServiceTasksMetrics(conn *dbus.Conn, ch chan<- promet
662661

663662
tasksMaxCount, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Service", "TasksMax")
664663
if err != nil {
665-
return errors.Wrapf(err, errGetPropertyMsg, "TasksMax")
664+
return fmt.Errorf(errGetPropertyMsg, "TasksMax", err)
666665
}
667666

668667
maxCount, ok := tasksMaxCount.Value.Value().(uint64)
669668
if !ok {
670-
return errors.Errorf(errConvertUint64PropertyMsg, "TasksMax", tasksMaxCount.Value.Value())
669+
return fmt.Errorf(errConvertUint64PropertyMsg, "TasksMax", tasksMaxCount.Value.Value())
671670
}
672671
// Don't set if tasksMax if dbus reports MaxUint64.
673672
if maxCount != math.MaxUint64 {
@@ -682,11 +681,11 @@ func (c *Collector) collectServiceTasksMetrics(conn *dbus.Conn, ch chan<- promet
682681
func (c *Collector) collectTimerTriggerTime(conn *dbus.Conn, ch chan<- prometheus.Metric, unit dbus.UnitStatus) error {
683682
lastTriggerValue, err := conn.GetUnitTypePropertyContext(c.ctx, unit.Name, "Timer", "LastTriggerUSec")
684683
if err != nil {
685-
return errors.Wrapf(err, errGetPropertyMsg, "LastTriggerUSec")
684+
return fmt.Errorf(errGetPropertyMsg, "LastTriggerUSec", err)
686685
}
687686
val, ok := lastTriggerValue.Value.Value().(uint64)
688687
if !ok {
689-
return errors.Errorf(errConvertUint64PropertyMsg, "LastTriggerUSec", lastTriggerValue.Value.Value())
688+
return fmt.Errorf(errConvertUint64PropertyMsg, "LastTriggerUSec", lastTriggerValue.Value.Value())
690689
}
691690
ch <- prometheus.MustNewConstMetric(
692691
c.timerLastTriggerDesc, prometheus.GaugeValue,

0 commit comments

Comments
 (0)