Skip to content

Commit a5e92d1

Browse files
wip: replace deprecated promlog with promslog
Remaining TODOs: - Review log messages to ensure they make sense
1 parent e870484 commit a5e92d1

30 files changed

+261
-2528
lines changed

bigquerydb/client.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ import (
1818
"encoding/json"
1919
"fmt"
2020
"io"
21+
"log/slog"
2122
"math"
2223
"os"
2324
"sort"
2425
"strings"
2526
"time"
2627

2728
"cloud.google.com/go/bigquery"
28-
"github.com/go-kit/log"
29-
"github.com/go-kit/log/level"
3029
"github.com/pkg/errors"
3130
"github.com/prometheus/client_golang/prometheus"
3231
"github.com/prometheus/common/model"
@@ -37,7 +36,7 @@ import (
3736

3837
// BigqueryClient allows sending batches of Prometheus samples to Bigquery.
3938
type BigqueryClient struct {
40-
logger log.Logger
39+
logger slog.Logger
4140
client bigquery.Client
4241
datasetID string
4342
tableID string
@@ -50,13 +49,13 @@ type BigqueryClient struct {
5049
}
5150

5251
// NewClient creates a new Client.
53-
func NewClient(logger log.Logger, googleAPIjsonkeypath, googleProjectID, googleAPIdatasetID, googleAPItableID string, remoteTimeout time.Duration) *BigqueryClient {
52+
func NewClient(logger slog.Logger, googleAPIjsonkeypath, googleProjectID, googleAPIdatasetID, googleAPItableID string, remoteTimeout time.Duration) *BigqueryClient {
5453
ctx := context.Background()
5554
bigQueryClientOptions := []option.ClientOption{}
5655
if googleAPIjsonkeypath != "" {
5756
jsonFile, err := os.Open(googleAPIjsonkeypath)
5857
if err != nil {
59-
level.Error(logger).Log("err", err) //nolint:errcheck
58+
logger.Error("failed to open google API json key", slog.Any("err", err))
6059
os.Exit(1)
6160
}
6261

@@ -65,7 +64,7 @@ func NewClient(logger log.Logger, googleAPIjsonkeypath, googleProjectID, googleA
6564
var result map[string]interface{}
6665
err = json.Unmarshal([]byte(byteValue), &result)
6766
if err != nil {
68-
level.Error(logger).Log("err", err) //nolint:errcheck
67+
logger.Error("failed to unmarshal google API json key", slog.Any("err", err))
6968
os.Exit(1)
7069
}
7170

@@ -80,13 +79,14 @@ func NewClient(logger log.Logger, googleAPIjsonkeypath, googleProjectID, googleA
8079
c, err := bigquery.NewClient(ctx, googleProjectID, bigQueryClientOptions...)
8180

8281
if err != nil {
83-
level.Error(logger).Log("err", err) //nolint:errcheck
82+
logger.Error("failed to create new bigquery client", slog.Any("err", err))
8483
os.Exit(1)
8584
}
8685

87-
if logger == nil {
88-
logger = log.NewNopLogger()
89-
}
86+
// TODO: Fix this
87+
// if logger == nil {
88+
// logger = log.NewNopLogger()
89+
// }
9090

9191
return &BigqueryClient{
9292
logger: logger,
@@ -180,7 +180,7 @@ func (c *BigqueryClient) Write(timeseries []*prompb.TimeSeries) error {
180180
for _, s := range samples {
181181
v := float64(s.Value)
182182
if math.IsNaN(v) || math.IsInf(v, 0) {
183-
//level.Debug(c.logger).Log("msg", "cannot send to BigQuery, skipping sample", "value", v, "sample", s)
183+
//logger.Debug("cannot send to BigQuery, skipping sample", slog.Any("value", v), slog.Any("sample", s))
184184
c.ignoredSamples.Inc()
185185
continue
186186
}
@@ -259,7 +259,7 @@ func (c *BigqueryClient) Read(req *prompb.ReadRequest) (*prompb.ReadResponse, er
259259
}
260260
duration := time.Since(begin).Seconds()
261261
c.sqlQueryDuration.Observe(duration)
262-
level.Debug(c.logger).Log("msg", "BigQuery SQL query", "rows", iter.TotalRows, "duration", duration) //nolint:errcheck
262+
c.logger.Debug("BigQuery SQL query", slog.Any("rows", iter.TotalRows), slog.Any("duration", duration))
263263
}
264264

265265
resp := prompb.ReadResponse{
@@ -312,7 +312,7 @@ func (c *BigqueryClient) buildCommand(q *prompb.Query) (string, error) {
312312
matchers = append(matchers, fmt.Sprintf("timestamp <= TIMESTAMP_MILLIS(%v)", q.EndTimestampMs))
313313

314314
query := fmt.Sprintf("SELECT metricname, tags, UNIX_MILLIS(timestamp) as timestamp, value FROM %s.%s WHERE %v ORDER BY timestamp", c.datasetID, c.tableID, strings.Join(matchers, " AND "))
315-
level.Debug(c.logger).Log("msg", "BigQuery read", "sql query", query) //nolint:errcheck
315+
c.logger.Debug("BigQuery read", slog.Any("sql query", query))
316316

317317
return query, nil
318318
}

bigquerydb/client_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ limitations under the License.
1616
package bigquerydb
1717

1818
import (
19+
"log/slog"
1920
"math"
2021
"os"
2122
"testing"
2223
"time"
2324

24-
"github.com/go-kit/log"
2525
"github.com/prometheus/prometheus/prompb"
2626
"github.com/stretchr/testify/assert"
2727
)
2828

2929
var bigQueryClientTimeout = time.Second * 60
30-
var logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
30+
var logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
3131

3232
var googleAPIdatasetID = os.Getenv("BQ_DATASET_NAME")
3333
var googleAPItableID = os.Getenv("BQ_TABLE_NAME")
@@ -95,7 +95,7 @@ func TestLabelMatchers(t *testing.T) {
9595
"emptyResult": {},
9696
}
9797

98-
bqclient := NewClient(logger, "", googleProjectID, googleAPIdatasetID, googleAPItableID, bigQueryClientTimeout)
98+
bqclient := NewClient(*logger, "", googleProjectID, googleAPIdatasetID, googleAPItableID, bigQueryClientTimeout)
9999

100100
for _, timeseries := range timeseriesData {
101101
err := bqclient.Write(timeseries)

go.mod

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.23
44

55
require (
66
cloud.google.com/go/bigquery v1.65.0
7-
github.com/go-kit/log v0.2.1
87
github.com/gogo/protobuf v1.3.2
98
github.com/golang/snappy v0.0.4
109
github.com/pkg/errors v0.9.1
@@ -29,7 +28,6 @@ require (
2928
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3029
github.com/davecgh/go-spew v1.1.1 // indirect
3130
github.com/felixge/httpsnoop v1.0.4 // indirect
32-
github.com/go-logfmt/logfmt v0.5.1 // indirect
3331
github.com/go-logr/logr v1.4.2 // indirect
3432
github.com/go-logr/stdr v1.2.2 // indirect
3533
github.com/goccy/go-json v0.10.2 // indirect

go.sum

-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
4343
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
4444
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
4545
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
46-
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
47-
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
48-
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
49-
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
5046
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
5147
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
5248
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=

0 commit comments

Comments
 (0)