Skip to content

Commit

Permalink
finish up migration to new events
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Siwiec <[email protected]>
  • Loading branch information
rizzza committed Nov 2, 2023
1 parent 973420a commit 4080920
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ generate: background-run .generate kill-running ## Generates code
go-run: ## Runs the app
@echo --- Running binary...
@date --rfc-3339=seconds
@go run main.go serve --dev
@go run main.go serve --dev --oidc=false

background-run: ## Runs in the app in the background
@date --rfc-3339=seconds
Expand Down
24 changes: 18 additions & 6 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"strconv"
"syscall"
"time"

"entgo.io/ent/dialect"
entsql "entgo.io/ent/dialect/sql"
Expand All @@ -27,7 +28,10 @@ import (
"go.infratographer.com/location-api/internal/graphapi"
)

var defaultListenAddr = ":7909"
const (
defaultListenAddr = ":7909"
shutdownTimeout = 10 * time.Second
)

var (
enablePlayground bool
Expand Down Expand Up @@ -57,7 +61,7 @@ func init() {

echox.MustViperFlags(viper.GetViper(), serveCmd.Flags(), defaultListenAddr)
echojwtx.MustViperFlags(viper.GetViper(), serveCmd.Flags())
events.MustViperFlagsForPublisher(viper.GetViper(), serveCmd.Flags(), appName)
events.MustViperFlags(viper.GetViper(), serveCmd.Flags(), appName)
permissions.MustViperFlags(viper.GetViper(), serveCmd.Flags())

// only available as a CLI arg because it shouldn't be something that could accidentially end up in a config file or env var
Expand All @@ -78,9 +82,9 @@ func serve(ctx context.Context) error {
viper.Set("oidc.enabled", false)
}

publisher, err := events.NewPublisher(config.AppConfig.Events.Publisher)
events, err := events.NewConnection(config.AppConfig.Events, events.WithLogger(logger))
if err != nil {
logger.Fatal("unable to initialize event publisher", zap.Error(err))
logger.Fatalw("failed to initialize events", "error", err)
}

err = otelx.InitTracer(config.AppConfig.Tracing, appName, logger)
Expand All @@ -97,7 +101,7 @@ func serve(ctx context.Context) error {

entDB := entsql.OpenDB(dialect.Postgres, db)

cOpts := []ent.Option{ent.Driver(entDB), ent.EventsPublisher(publisher)}
cOpts := []ent.Option{ent.Driver(entDB), ent.EventsPublisher(events)}

if config.AppConfig.Logging.Debug {
cOpts = append(cOpts,
Expand All @@ -121,14 +125,15 @@ func serve(ctx context.Context) error {
middleware = append(middleware, auth.Middleware())
}

srv, err := echox.NewServer(logger.Desugar(), config.AppConfig.Server, versionx.BuildDetails())
srv, err := echox.NewServer(logger.Desugar(), config.AppConfig.Server, versionx.BuildDetails(), echox.WithLoggingSkipper(echox.SkipDefaultEndpoints))
if err != nil {
logger.Fatal("failed to initialize new server", zap.Error(err))
}

perms, err := permissions.New(config.AppConfig.Permissions,
permissions.WithLogger(logger),
permissions.WithDefaultChecker(permissions.DefaultAllowChecker),
permissions.WithEventsPublisher(events),
)
if err != nil {
logger.Fatal("failed to initialize permissions", zap.Error(err))
Expand All @@ -144,6 +149,13 @@ func serve(ctx context.Context) error {
// TODO: we should have a database check
// srv.AddReadinessCheck("database", r.DatabaseCheck)

defer func() {
ctx, cancel := context.WithTimeout(ctx, shutdownTimeout)
defer cancel()

_ = events.Shutdown(ctx)
}()

if err = srv.RunWithContext(ctx); err != nil {
logger.Fatal("failed to run server", zap.Error(err))
}
Expand Down
28 changes: 11 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ require (
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go/modules/postgres v0.26.0
github.com/vektah/gqlparser/v2 v2.5.10
github.com/wundergraph/graphql-go-tools v1.63.0
go.infratographer.com/permissions-api v0.1.14
go.infratographer.com/x v0.3.4
github.com/wundergraph/graphql-go-tools v1.67.0
go.infratographer.com/permissions-api v0.2.6
go.infratographer.com/x v0.3.9
go.uber.org/zap v1.26.0
)

Expand All @@ -29,11 +29,9 @@ require (
dario.cat/mergo v1.0.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/MicahParks/keyfunc/v2 v2.0.3 // indirect
github.com/MicahParks/keyfunc/v2 v2.1.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.1 // indirect
github.com/ThreeDotsLabs/watermill v1.2.0 // indirect
github.com/ThreeDotsLabs/watermill-nats/v2 v2.0.0 // indirect
github.com/XSAM/otelsql v0.23.0 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
Expand All @@ -52,7 +50,6 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/garsue/watermillzap v1.2.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
Expand All @@ -65,12 +62,11 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.0 // indirect
Expand All @@ -87,7 +83,6 @@ require (
github.com/labstack/echo-contrib v0.15.0 // indirect
github.com/labstack/echo-jwt/v4 v4.2.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -102,20 +97,19 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/nats-io/jwt/v2 v2.5.0 // indirect
github.com/nats-io/nats-server/v2 v2.9.21 // indirect
github.com/nats-io/jwt/v2 v2.5.2 // indirect
github.com/nats-io/nats-server/v2 v2.10.1 // indirect
github.com/nats-io/nats.go v1.30.2 // indirect
github.com/nats-io/nkeys v0.4.5 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v1.1.7 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/pressly/goose/v3 v3.13.4 // indirect
github.com/pressly/goose/v3 v3.15.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.40.0 // indirect
Expand All @@ -129,6 +123,7 @@ require (
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/testcontainers/testcontainers-go v0.26.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
Expand All @@ -152,9 +147,8 @@ require (
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.step.sm/crypto v0.31.2 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.step.sm/crypto v0.35.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
Expand Down
Loading

0 comments on commit 4080920

Please sign in to comment.