Skip to content

Commit 7d73c1d

Browse files
ryanwuermachine424
andauthored
refactor[discovery, tsdb]: simplify error handling and remove redundant checks (prometheus#16328)
* refactor: simplify error handling and remove redundant checks Signed-off-by: Ryan Wu <rongjun0821@gmail.com> * Add the comment for return of reloading blocks failure Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com> Signed-off-by: Ryan Wu <rongjun0821@gmail.com> * Add the comment for return of reloading blocks failure Signed-off-by: Ryan Wu <rongjun0821@gmail.com> --------- Signed-off-by: Ryan Wu <rongjun0821@gmail.com> Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com>
1 parent 4e91f13 commit 7d73c1d

File tree

4 files changed

+5
-15
lines changed

4 files changed

+5
-15
lines changed

discovery/openstack/loadbalancer.go

-4
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,5 @@ func (i *LoadBalancerDiscovery) refresh(ctx context.Context) ([]*targetgroup.Gro
189189
tg.Targets = append(tg.Targets, labels)
190190
}
191191

192-
if err != nil {
193-
return nil, err
194-
}
195-
196192
return []*targetgroup.Group{tg}, nil
197193
}

discovery/vultr/vultr.go

-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package vultr
1616
import (
1717
"context"
1818
"errors"
19-
"fmt"
2019
"log/slog"
2120
"net"
2221
"net/http"
@@ -137,10 +136,6 @@ func NewDiscovery(conf *SDConfig, logger *slog.Logger, metrics discovery.Discove
137136

138137
d.client.SetUserAgent(version.PrometheusUserAgent())
139138

140-
if err != nil {
141-
return nil, fmt.Errorf("error setting up vultr agent: %w", err)
142-
}
143-
144139
d.Discovery = refresh.NewDiscovery(
145140
refresh.Options{
146141
Logger: logger,

tsdb/db.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2280,10 +2280,9 @@ func (db *DB) CleanTombstones() (err error) {
22802280
db.logger.Error("failed to delete block after failed `CleanTombstones`", "dir", dir, "err", err)
22812281
}
22822282
}
2283-
if err != nil {
2284-
return fmt.Errorf("reload blocks: %w", err)
2285-
}
2286-
return nil
2283+
2284+
// This should only be reached if an error occurred.
2285+
return fmt.Errorf("reload blocks: %w", err)
22872286
}
22882287
}
22892288
return nil

tsdb/db_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9104,7 +9104,7 @@ func compareSeries(t require.TestingT, expected, actual map[string][]chunks.Samp
91049104
require.Equal(t, eS.F(), aS.F(), "sample %d in series %q differs", i, key)
91059105
case chunkenc.ValHistogram:
91069106
eH, aH := eS.H(), aS.H()
9107-
if aH.CounterResetHint == histogram.UnknownCounterReset && aH.CounterResetHint != histogram.GaugeType {
9107+
if aH.CounterResetHint == histogram.UnknownCounterReset {
91089108
eH = eH.Copy()
91099109
// It is always safe to set the counter reset hint to UnknownCounterReset
91109110
eH.CounterResetHint = histogram.UnknownCounterReset
@@ -9114,7 +9114,7 @@ func compareSeries(t require.TestingT, expected, actual map[string][]chunks.Samp
91149114

91159115
case chunkenc.ValFloatHistogram:
91169116
eFH, aFH := eS.FH(), aS.FH()
9117-
if aFH.CounterResetHint == histogram.UnknownCounterReset && aFH.CounterResetHint != histogram.GaugeType {
9117+
if aFH.CounterResetHint == histogram.UnknownCounterReset {
91189118
eFH = eFH.Copy()
91199119
// It is always safe to set the counter reset hint to UnknownCounterReset
91209120
eFH.CounterResetHint = histogram.UnknownCounterReset

0 commit comments

Comments
 (0)