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

added structured-logging and tracing #5

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ HOST=localhost
METADATA_PORT=8081
RATING_PORT=8082
MOVIE_PORT=8083
CONSUL_URL=localhost:8500
CONSUL_URL=localhost:8500
JAEGER_URL=localhost:4317
ENVIRONMENT=dev
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ delete-postgres:
podman rm -f postgres
podman volume prune

create-jaeger:
podman run --name jaeger -e COLLECTOR_OTLP_ENABLED=true -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 14250:14250 -p 14268:14268 -p 14269:14269 -p 9411:9411 -d jaegertracing/all-in-one:1.52

delete-jaeger:
podman rm -f jaeger
podman volume prune

create-migration:
migrate create -ext sql -dir database/migration -seq $(name)

Expand Down Expand Up @@ -54,4 +61,4 @@ generate-mock:
run-test:
go test ./...

.PHONY: create-consul delete-consul proto-generate create-pulsar delete-pulsar create-postgres delete-postgres create-migration migrate-up migrate-down generate-dbdocs generate-schema generate-sqlc generate-image generate-mock run-test
.PHONY: create-consul delete-consul proto-generate create-pulsar delete-pulsar create-postgres delete-postgres create-jaeger delete-jaeger create-migration migrate-up migrate-down generate-dbdocs generate-schema generate-sqlc generate-image generate-mock run-test
4 changes: 2 additions & 2 deletions cmd/rating/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"log"
"main/rating/model"
"main/utils"
"main/util"
"os"

"github.com/apache/pulsar-client-go/pulsar"
Expand All @@ -19,7 +19,7 @@ func main() {
flag.StringVar(&config, "config", ".env", "Configuration path")
flag.StringVar(&data, "data", "data.json", "Load Rating data")
flag.Parse()
cfg := utils.LoadConfig(config)
cfg := util.LoadConfig(config)

client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: cfg.PulsarURL,
Expand Down
4 changes: 2 additions & 2 deletions database/db/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package db
import (
"context"
"log"
"main/utils"
"main/util"
"os"
"testing"

Expand All @@ -13,7 +13,7 @@ import (
var testStore Store

func TestMain(m *testing.M) {
cfg := utils.LoadConfig("../../.env")
cfg := util.LoadConfig("../../.env")
connPool, err := pgxpool.New(context.Background(), cfg.DatabaseURL)
if err != nil {
log.Fatal("cannot connect to db:", err)
Expand Down
10 changes: 5 additions & 5 deletions database/db/movies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package db

import (
"context"
"main/utils"
"main/util"
"testing"

"github.com/stretchr/testify/require"
)

func createRandomMovie(t *testing.T) *Movie {
arg := &CreateMovieParams{
ID: utils.RandomString(8),
Title: utils.RandomString(8),
Description: utils.RandomString(16),
Director: utils.RandomString(8),
ID: util.RandomString(8),
Title: util.RandomString(8),
Description: util.RandomString(16),
Director: util.RandomString(8),
}

movie, err := testStore.CreateMovie(context.Background(), arg)
Expand Down
14 changes: 7 additions & 7 deletions database/db/ratings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package db

import (
"context"
"main/utils"
"main/util"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -12,8 +12,8 @@ func createRandomRating(t *testing.T, movieId, recordType string) *Rating {
arg := &CreateRatingParams{
MovieID: movieId,
RecordType: recordType,
UserID: utils.RandomString(8),
Value: int32(utils.RandomInt(0, 10)),
UserID: util.RandomString(8),
Value: int32(util.RandomInt(0, 10)),
}

rating, err := testStore.CreateRating(context.Background(), arg)
Expand All @@ -29,14 +29,14 @@ func createRandomRating(t *testing.T, movieId, recordType string) *Rating {
}

func TestCreateRating(t *testing.T) {
movieId := utils.RandomString(8)
recordType := utils.RandomString(8)
movieId := util.RandomString(8)
recordType := util.RandomString(8)
createRandomRating(t, movieId, recordType)
}

func TestListRatings(t *testing.T) {
movieId := utils.RandomString(8)
recordType := utils.RandomString(8)
movieId := util.RandomString(8)
recordType := util.RandomString(8)

var lastAccount *Rating
for i := 0; i < 10; i++ {
Expand Down
35 changes: 25 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
module main

go 1.21
go 1.21.5

require (
github.com/apache/pulsar-client-go v0.11.1
github.com/google/go-cmp v0.5.9
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.4.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/hashicorp/consul/api v1.26.1
github.com/ilyakaznacheev/cleanenv v1.5.0
github.com/jackc/pgx/v5 v5.5.0
github.com/stretchr/testify v1.8.3
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0
go.opentelemetry.io/otel/sdk v1.21.0
go.uber.org/mock v0.3.0
golang.org/x/time v0.5.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
)
Expand All @@ -25,15 +30,19 @@ require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.4.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down Expand Up @@ -63,21 +72,27 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)
Loading