Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update various dependencies #366

Merged
merged 31 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
70efd96
gitignore: Un-ignore content of vendor directory
monstermunchkin Apr 2, 2024
327cdb5
gomod: Switch to github.com/google/uuid
monstermunchkin Apr 2, 2024
37c922c
Switch to github.com/google/uuid
monstermunchkin Apr 2, 2024
e5c68e4
gomod: Update github.com/PuerkitoBio/rehttp to v1.4.0
monstermunchkin Apr 2, 2024
7ff9751
gomod: Update github.com/caarlos0/env to v10
monstermunchkin Apr 2, 2024
e8f5e66
Update to github.com/caarlos0/env v10
monstermunchkin Apr 2, 2024
8d94f06
gomod: Update github.com/certifi/gocertifi
monstermunchkin Apr 2, 2024
cc801a9
gomod: Update github.com/dave/jennifer
monstermunchkin Apr 2, 2024
7039660
gomod: Update github.com/golang-jwt/jwt to v5
monstermunchkin Apr 2, 2024
dc9d18a
Update to github.com/golang-jwt/jwt/v5
monstermunchkin Apr 2, 2024
eca90c7
gomod: Update github.com/gorilla/mux to v1.8.1
monstermunchkin Apr 2, 2024
5756a8b
gomod: Update github.com/grpc-ecosystem/go-grpc-middleware
monstermunchkin Apr 2, 2024
15e7cc8
gomod: Add github.com/grpc-ecosystem/go-grpc-middleware/providers/pro…
monstermunchkin Apr 2, 2024
bd51332
Use github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus
monstermunchkin Apr 2, 2024
4155797
gomod: Update github.com/mattn/go-isatty
monstermunchkin Apr 2, 2024
196d80d
gomod: Update github.com/mattn/goveralls
monstermunchkin Apr 2, 2024
9eeb6be
gomod: Update github.com/prometheus/client_golang
monstermunchkin Apr 2, 2024
3c0144e
gomod: Update github.com/rs/xid
monstermunchkin Apr 2, 2024
acf9514
gomod: Update github.com/rs/zerolog
monstermunchkin Apr 2, 2024
e57c7b4
gomod: Update github.com/shopspring/decimal
monstermunchkin Apr 2, 2024
f645644
gomod: Update github.com/sony/gobreaker
monstermunchkin Apr 2, 2024
5054352
gomod: Update github.com/spf13/cobra
monstermunchkin Apr 2, 2024
7695e46
gomod: Update github.com/stretchr/testify
monstermunchkin Apr 2, 2024
3562d4f
gomod: Update github.com/zenazn/goji
monstermunchkin Apr 2, 2024
d2cdf6b
gomod: Remove golang.org/x/tools/cmd/cover (deprecated)
monstermunchkin Apr 2, 2024
e5b12c9
tools.go: Remove golang.org/x/tools/cmd/cover (deprecated)
monstermunchkin Apr 2, 2024
c9297d7
gomod: Update golang.org/x/vuln
monstermunchkin Apr 2, 2024
e15a8d9
gomod: Update google.golang.org/grpc
monstermunchkin Apr 2, 2024
2cadba0
gomod: Update google.golang.org/grpc/cmd/protoc-gen-go-grpc
monstermunchkin Apr 2, 2024
e34acf7
gomod: Update go-pg to v10
monstermunchkin Apr 9, 2024
45ded84
Update to go-pg/v10
monstermunchkin Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ tmp/*

# ignore goland project files
.idea/

# Un-ignore anything in the vendor directory
!vendor/**
2 changes: 1 addition & 1 deletion backend/couchdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package couchdb
import (
"context"

"github.com/caarlos0/env"
"github.com/caarlos0/env/v10"
"github.com/go-kivik/couchdb/v3"
kivik "github.com/go-kivik/kivik/v3"

Expand Down
2 changes: 1 addition & 1 deletion backend/k8sapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"os"
"strings"

"github.com/caarlos0/env"
"github.com/caarlos0/env/v10"
"github.com/pace/bricks/http/transport"
"github.com/pace/bricks/maintenance/log"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/objstore/objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/caarlos0/env"
"github.com/caarlos0/env/v10"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"

Expand Down
2 changes: 1 addition & 1 deletion backend/postgres/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io"
"net"

"github.com/go-pg/pg"
"github.com/go-pg/pg/v10"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion backend/postgres/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"testing"

"github.com/go-pg/pg"
"github.com/go-pg/pg/v10"
"github.com/stretchr/testify/require"

pbpostgres "github.com/pace/bricks/backend/postgres"
Expand Down
2 changes: 1 addition & 1 deletion backend/postgres/health_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"time"

"github.com/go-pg/pg/orm"
"github.com/go-pg/pg/v10/orm"
"github.com/pace/bricks/maintenance/health/servicehealthcheck"
)

Expand Down
2 changes: 1 addition & 1 deletion backend/postgres/health_postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
"time"

"github.com/go-pg/pg/orm"
"github.com/go-pg/pg/v10/orm"
http2 "github.com/pace/bricks/http"
"github.com/pace/bricks/maintenance/errors"
"github.com/pace/bricks/maintenance/health/servicehealthcheck"
Expand Down
136 changes: 136 additions & 0 deletions backend/postgres/hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package postgres

import (
"context"
"math"
"time"

"github.com/go-pg/pg/v10"
"github.com/opentracing/opentracing-go"
olog "github.com/opentracing/opentracing-go/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"

"github.com/pace/bricks/maintenance/log"
)

type QueryLogger struct{}

func (QueryLogger) BeforeQuery(_ context.Context, _ *pg.QueryEvent) (context.Context, error) {
return nil, nil
}

func (QueryLogger) AfterQuery(ctx context.Context, event *pg.QueryEvent) error {
q, qe := event.UnformattedQuery()
if qe == nil {
if !(cfg.LogRead || cfg.LogWrite) {
return nil
}
// we can only and should only perfom the following check if we have the information availaible
mode := determineQueryMode(string(q))
if mode == readMode && !cfg.LogRead {
return nil
}
if mode == writeMode && !cfg.LogWrite {
return nil
}

}

dur := float64(time.Since(event.StartTime)) / float64(time.Millisecond)

// check if log context is given
var logger *zerolog.Logger
if ctx != nil {
logger = log.Ctx(ctx)
} else {
logger = log.Logger()
}

// add general info
le := logger.Debug().
Float64("duration", dur).
Str("sentry:category", "postgres")

// add error or result set info
if event.Err != nil {
le = le.Err(event.Err)
} else {
le = le.Int("affected", event.Result.RowsAffected()).
Int("rows", event.Result.RowsReturned())
}

if qe != nil {
// this is only a display issue not a "real" issue
le.Msgf("%v", qe)
}
le.Msg(string(q))

return nil
}

type OpenTracingAdapter struct{}

func (OpenTracingAdapter) BeforeQuery(_ context.Context, _ *pg.QueryEvent) (context.Context, error) {
return nil, nil
}

func (OpenTracingAdapter) AfterQuery(ctx context.Context, event *pg.QueryEvent) error {
// start span with general info
q, qe := event.UnformattedQuery()
if qe != nil {
// this is only a display issue not a "real" issue
q = []byte(qe.Error())
}

span, _ := opentracing.StartSpanFromContext(event.DB.Context(), "sql: "+getQueryType(string(q)),
opentracing.StartTime(event.StartTime))

span.SetTag("db.system", "postgres")

fields := []olog.Field{
olog.String("query", string(q)),
}

// add error or result set info
if event.Err != nil {
fields = append(fields, olog.Error(event.Err))
} else {
fields = append(fields,
olog.Int("affected", event.Result.RowsAffected()),
olog.Int("rows", event.Result.RowsReturned()))
}

span.LogFields(fields...)
span.Finish()

return nil
}

type MetricsAdapter struct {
opts *pg.Options
}

func (MetricsAdapter) BeforeQuery(_ context.Context, _ *pg.QueryEvent) (context.Context, error) {
return nil, nil
}

func (m MetricsAdapter) AfterQuery(ctx context.Context, event *pg.QueryEvent) error {
dur := float64(time.Since(event.StartTime)) / float64(time.Millisecond)
labels := prometheus.Labels{
"database": m.opts.Addr + "/" + m.opts.Database,
}

metricQueryTotal.With(labels).Inc()

if event.Err != nil {
metricQueryFailed.With(labels).Inc()
} else {
r := event.Result
metricQueryRowsTotal.With(labels).Add(float64(r.RowsReturned()))
metricQueryAffectedTotal.With(labels).Add(math.Max(0, float64(r.RowsAffected())))
}
metricQueryDurationSeconds.With(labels).Observe(dur)

return nil
}
2 changes: 1 addition & 1 deletion backend/postgres/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync"
"time"

"github.com/go-pg/pg"
"github.com/go-pg/pg/v10"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down
124 changes: 9 additions & 115 deletions backend/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ package postgres
import (
"context"
"fmt"
"math"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
"time"

"github.com/caarlos0/env"
"github.com/go-pg/pg"
"github.com/opentracing/opentracing-go"
olog "github.com/opentracing/opentracing-go/log"
"github.com/caarlos0/env/v10"
"github.com/go-pg/pg/v10"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"

"github.com/pace/bricks/maintenance/health/servicehealthcheck"
"github.com/pace/bricks/maintenance/log"
Expand Down Expand Up @@ -224,7 +220,8 @@ func ConnectionPool(opts ...ConfigOption) *pg.DB {
//
// Fot a health check for this connection a PgHealthCheck needs to
// be registered:
// servicehealthcheck.RegisterHealthCheck(...)
//
// servicehealthcheck.RegisterHealthCheck(...)
func CustomConnectionPool(opts *pg.Options) *pg.DB {
log.Logger().Info().Str("addr", opts.Addr).
Str("user", opts.User).
Expand All @@ -233,14 +230,14 @@ func CustomConnectionPool(opts *pg.Options) *pg.DB {
Msg("PostgreSQL connection pool created")
db := pg.Connect(opts)
if cfg.LogWrite || cfg.LogRead {
db.OnQueryProcessed(queryLogger)
db.AddQueryHook(QueryLogger{})
} else {
log.Logger().Warn().Msg("Connection pool has logging queries disabled completely")
}
db.OnQueryProcessed(openTracingAdapter)
db.OnQueryProcessed(func(event *pg.QueryProcessedEvent) {
metricsAdapter(event, opts)
})

db.AddQueryHook(OpenTracingAdapter{})
db.AddQueryHook(MetricsAdapter{opts})

return db
}

Expand All @@ -260,57 +257,6 @@ func determineQueryMode(qry string) queryMode {
return writeMode
}

func queryLogger(event *pg.QueryProcessedEvent) {
q, qe := event.UnformattedQuery()
if qe == nil {
if !(cfg.LogRead || cfg.LogWrite) {
return
}
// we can only and should only perfom the following check if we have the information availaible
mode := determineQueryMode(q)
if mode == readMode && !cfg.LogRead {
return
}
if mode == writeMode && !cfg.LogWrite {
return
}

}
ctx := event.DB.Context()
dur := float64(time.Since(event.StartTime)) / float64(time.Millisecond)

// check if log context is given
var logger *zerolog.Logger
if ctx != nil {
logger = log.Ctx(ctx)
} else {
logger = log.Logger()
}

// add general info
le := logger.Debug().
Str("file", event.File).
Int("line", event.Line).
Str("func", event.Func).
Int("attempt", event.Attempt).
Float64("duration", dur).
Str("sentry:category", "postgres")

// add error or result set info
if event.Error != nil {
le = le.Err(event.Error)
} else {
le = le.Int("affected", event.Result.RowsAffected()).
Int("rows", event.Result.RowsReturned())
}

if qe != nil {
// this is only a display issue not a "real" issue
le.Msgf("%v", qe)
}
le.Msg(q)
}

var reQueryType = regexp.MustCompile(`(\s)`)
var reQueryTypeCleanup = regexp.MustCompile(`(?m)(\s+|\n)`)

Expand All @@ -324,55 +270,3 @@ func getQueryType(s string) string {
}
return strings.ToUpper(s)
}

func openTracingAdapter(event *pg.QueryProcessedEvent) {
// start span with general info
q, qe := event.UnformattedQuery()
if qe != nil {
// this is only a display issue not a "real" issue
q = qe.Error()
}

span, _ := opentracing.StartSpanFromContext(event.DB.Context(), "sql: "+getQueryType(q),
opentracing.StartTime(event.StartTime))

span.SetTag("db.system", "postgres")

fields := []olog.Field{
olog.String("file", event.File),
olog.Int("line", event.Line),
olog.String("func", event.Func),
olog.Int("attempt", event.Attempt),
olog.String("query", q),
}

// add error or result set info
if event.Error != nil {
fields = append(fields, olog.Error(event.Error))
} else {
fields = append(fields,
olog.Int("affected", event.Result.RowsAffected()),
olog.Int("rows", event.Result.RowsReturned()))
}

span.LogFields(fields...)
span.Finish()
}

func metricsAdapter(event *pg.QueryProcessedEvent, opts *pg.Options) {
dur := float64(time.Since(event.StartTime)) / float64(time.Millisecond)
labels := prometheus.Labels{
"database": opts.Addr + "/" + opts.Database,
}

metricQueryTotal.With(labels).Inc()

if event.Error != nil {
metricQueryFailed.With(labels).Inc()
} else {
r := event.Result
metricQueryRowsTotal.With(labels).Add(float64(r.RowsReturned()))
metricQueryAffectedTotal.With(labels).Add(math.Max(0, float64(r.RowsAffected())))
}
metricQueryDurationSeconds.With(labels).Observe(dur)
}
4 changes: 2 additions & 2 deletions backend/postgres/query_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package postgres
import (
"context"

"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
)

type pgPoolAdapter struct {
Expand Down
Loading
Loading