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

fix: 🐛 go-testcontainer upgrade to latest version error #79

Merged
merged 9 commits into from
Aug 31, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Unit Tests
run: make unit-test

# # there are some problem with test-container library in the github-actions!! locally all tests will pass
# # there are some problem with test-container library in the github-actions!! locally all tests will pass
# - name: Integration Tests
# run: make integration-test

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require (
github.com/uptrace/bun/dialect/pgdialect v1.1.14
github.com/uptrace/bun/driver/pgdriver v1.1.14
go.mongodb.org/mongo-driver v1.12.1
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.43.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.43.0
go.opentelemetry.io/contrib/propagators/ot v1.18.0
go.opentelemetry.io/otel v1.17.0
Expand Down Expand Up @@ -133,7 +134,6 @@ require (
github.com/moby/term v0.5.0 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/onsi/gomega v1.27.10 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opencontainers/runc v1.1.9 // indirect
Expand Down
1,305 changes: 12 additions & 1,293 deletions internal/pkg/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/pkg/grpc/otel/tracing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tracing
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
"go.opentelemetry.io/otel/trace"

"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/grpc/grpcErrors"
Expand Down
32 changes: 16 additions & 16 deletions internal/pkg/http/custom_echo/echo_server.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package customEcho

import (
"context"
"fmt"
"strings"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"go.opentelemetry.io/otel/metric"

"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/constants"
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/config"
customHadnlers "github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/hadnlers"
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/middlewares/log"
otelMetrics "github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/middlewares/otel_metrics"
otelTracer "github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/middlewares/otel_tracer"
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/logger"
"context"
"fmt"
"strings"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho"
"go.opentelemetry.io/otel/metric"

"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/constants"
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/config"
customHadnlers "github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/hadnlers"
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/middlewares/log"
otelMetrics "github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/custom_echo/middlewares/otel_metrics"
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/logger"
)

type echoHttpServer struct {
Expand Down Expand Up @@ -113,7 +113,7 @@ func (s *echoHttpServer) SetupDefaultMiddlewares() {

// log errors and information
s.echo.Use(log.EchoLogger(s.log))
s.echo.Use(otelTracer.Middleware(s.config.Name))
s.echo.Use(otelecho.Middleware(s.config.Name))
// Because we use metrics server middleware, if it is not available, our echo will not work.
if s.meter != nil {
s.echo.Use(otelMetrics.Middleware(s.meter, s.config.Name))
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions internal/pkg/http/custom_echo/otel/tracing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
"go.opentelemetry.io/otel/trace"

customErrors "github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/http/http_errors/custom_errors"
Expand All @@ -21,7 +21,7 @@ func TraceHttpErrFromSpan(span trace.Span, err error) error {
span.SetAttributes(attribute.String(HttpErrorMessage, stackTraceError))
if customErrors.IsCustomError(err) {
httpError := problemDetails.ParseError(err)
span.SetAttributes(semconv.HTTPAttributesFromHTTPStatusCode(httpError.GetStatus())...)
span.SetAttributes(semconv.HTTPStatusCode(httpError.GetStatus()))
}
span.RecordError(err)
}
Expand All @@ -34,7 +34,7 @@ func TraceHttpErrFromSpanWithCode(span trace.Span, err error, code int) error {
if err != nil {
stackTraceError := errorUtils.ErrorsWithStack(err)
span.SetStatus(codes.Error, "")
span.SetAttributes(semconv.HTTPAttributesFromHTTPStatusCode(code)...)
span.SetAttributes(semconv.HTTPStatusCode(code))
span.SetAttributes(attribute.String(HttpErrorMessage, stackTraceError))
span.RecordError(err)
}
Expand Down
9 changes: 4 additions & 5 deletions internal/pkg/messaging/otel/tracing/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
"go.opentelemetry.io/otel/trace"

"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/core/metadata"
Expand Down Expand Up @@ -85,7 +85,7 @@ func getTraceOptions(
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/messaging.md#batch-receiving
attrs := []attribute.KeyValue{
semconv.MessageIDKey.String(messageHeader.GetMessageId(*meta)),
semconv.MessagingConversationIDKey.String(correlationId),
semconv.MessagingMessageConversationID(correlationId),
semconv.MessagingOperationReceive,
attribute.Key(tracing.TraceId).String(tracingHeaders.GetTracingTraceId(*meta)),
attribute.Key(tracing.Traceparent).String(tracingHeaders.GetTracingTraceparent(*meta)),
Expand All @@ -95,9 +95,8 @@ func getTraceOptions(
attribute.Key(messageTracing.MessageName).String(messageHeader.GetMessageName(*meta)),
attribute.Key(messageTracing.Payload).String(payload),
attribute.String(messageTracing.Headers, meta.ToJson()),
semconv.MessagingDestinationKey.String(consumerTracingOptions.Destination),
semconv.MessagingDestinationName(consumerTracingOptions.Destination),
semconv.MessagingSystemKey.String(consumerTracingOptions.MessagingSystem),
semconv.MessagingDestinationKindKey.String(consumerTracingOptions.DestinationKind),
}

if consumerTracingOptions.OtherAttributes != nil && len(consumerTracingOptions.OtherAttributes) > 0 {
Expand All @@ -114,7 +113,7 @@ func getTraceOptions(
func addAfterBaggage(ctx context.Context, meta *metadata.Metadata) context.Context {
correlationId := messageHeader.GetCorrelationId(*meta)

correlationIdBag, _ := baggage.NewMember(string(semconv.MessagingConversationIDKey), correlationId)
correlationIdBag, _ := baggage.NewMember(string(semconv.MessagingMessageConversationIDKey), correlationId)
messageIdBag, _ := baggage.NewMember(string(semconv.MessageIDKey), messageHeader.GetMessageId(*meta))
b, _ := baggage.New(correlationIdBag, messageIdBag)
ctx = baggage.ContextWithBaggage(ctx, b)
Expand Down
9 changes: 4 additions & 5 deletions internal/pkg/messaging/otel/tracing/producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
"go.opentelemetry.io/otel/trace"

"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/core/metadata"
Expand Down Expand Up @@ -88,15 +88,14 @@ func getTraceOptions(
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/messaging.md#batch-receiving
attrs := []attribute.KeyValue{
semconv.MessageIDKey.String(message.GeMessageId()),
semconv.MessagingConversationIDKey.String(correlationId),
semconv.MessagingMessageConversationID(correlationId),
attribute.Key(messageTracing.MessageType).String(message.GetEventTypeName()),
attribute.Key(messageTracing.MessageName).String(messageHeader.GetMessageName(*meta)),
attribute.Key(messageTracing.Payload).String(payload),
attribute.String(messageTracing.Headers, meta.ToJson()),
attribute.Key(tracing.Timestamp).Int64(time.Now().UnixMilli()),
semconv.MessagingDestinationKey.String(producerTracingOptions.Destination),
semconv.MessagingDestinationName(producerTracingOptions.Destination),
semconv.MessagingSystemKey.String(producerTracingOptions.MessagingSystem),
semconv.MessagingDestinationKindKey.String(producerTracingOptions.DestinationKind),
semconv.MessagingOperationKey.String("send"),
}

Expand All @@ -114,7 +113,7 @@ func getTraceOptions(
func addAfterBaggage(ctx context.Context, message types.IMessage, meta *metadata.Metadata) context.Context {
correlationId := messageHeader.GetCorrelationId(*meta)

correlationIdBag, _ := baggage.NewMember(string(semconv.MessagingConversationIDKey), correlationId)
correlationIdBag, _ := baggage.NewMember(string(semconv.MessagingMessageConversationIDKey), correlationId)
messageIdBag, _ := baggage.NewMember(string(semconv.MessageIDKey), message.GeMessageId())
b, _ := baggage.New(correlationIdBag, messageIdBag)
ctx = baggage.ContextWithBaggage(ctx, b)
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/otel/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"

"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/config/environemnt"
config2 "github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/otel/config"
Expand Down Expand Up @@ -92,7 +92,7 @@ func (o *TracingOpenTelemetry) configTracerProvider() error {
sampler = tracesdk.NeverSample()
}

// https://github.com/open-telemetry/opentelemetry-go/blob/b2246d58650bc6db04459353843250ee3bba77fc/example/fib/main.go#L45
// https://github.com/open-telemetry/opentelemetry-go/blob/main/example/fib/main.go#L44
// Ensure default SDK resources and the required service name are set.
r, err := resource.Merge(
resource.Default(),
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/rabbitmq/consumer/rabbitmq_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/avast/retry-go"
"github.com/rabbitmq/amqp091-go"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"

"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/core/metadata"
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/core/serializer"
Expand Down Expand Up @@ -291,7 +291,7 @@ func (r *rabbitMQConsumer) handleReceived(ctx context.Context, delivery amqp091.
DestinationKind: "queue",
Destination: r.rabbitmqConsumerOptions.QueueOptions.Name,
OtherAttributes: []attribute.KeyValue{
semconv.MessagingRabbitmqRoutingKeyKey.String(delivery.RoutingKey),
semconv.MessagingRabbitmqDestinationRoutingKey(delivery.RoutingKey),
},
}
ctx, beforeConsumeSpan := consumeTracing.StartConsumerSpan(
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/rabbitmq/producer/rabbitmq_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/rabbitmq/amqp091-go"
uuid "github.com/satori/go.uuid"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"

"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/core/metadata"
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/core/serializer"
Expand Down Expand Up @@ -117,7 +117,7 @@ func (r *rabbitMQProducer) PublishMessageWithTopicName(
DestinationKind: "exchange",
Destination: exchange,
OtherAttributes: []attribute.KeyValue{
semconv.MessagingRabbitmqRoutingKeyKey.String(routingKey),
semconv.MessagingRabbitmqDestinationRoutingKey(routingKey),
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/EventStore/EventStore-Client-Go/esdb"
"github.com/docker/go-connections/nat"
Expand Down Expand Up @@ -77,7 +78,9 @@ func (g *eventstoredbTestContainers) CreatingContainerOptions(

// Clean up the container after the test is complete
t.Cleanup(func() {
_ = dbContainer.Terminate(ctx)
if err := dbContainer.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})

option := &config.EventStoreDbOptions{
Expand Down Expand Up @@ -127,7 +130,7 @@ func (g *eventstoredbTestContainers) getRunOptions(
containerReq := testcontainers.ContainerRequest{
Image: fmt.Sprintf("%s:%s", g.defaultOptions.ImageName, g.defaultOptions.Tag),
ExposedPorts: g.defaultOptions.Ports,
WaitingFor: wait.ForListeningPort(nat.Port(g.defaultOptions.Ports[0])),
WaitingFor: wait.ForListeningPort(nat.Port(g.defaultOptions.Ports[0])).WithPollInterval(2 * time.Second),
Hostname: g.defaultOptions.Host,
SkipReaper: true,
// we use `EVENTSTORE_IN_MEM` for use eventstoredb in-memory mode in tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/docker/go-connections/nat"
"github.com/testcontainers/testcontainers-go"
Expand Down Expand Up @@ -72,7 +73,9 @@ func (g *gormTestContainers) CreatingContainerOptions(

// Clean up the container after the test is complete
t.Cleanup(func() {
_ = dbContainer.Terminate(ctx)
if err := dbContainer.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})

gormOptions := &gormPostgres.GormOptions{
Expand Down Expand Up @@ -139,7 +142,7 @@ func (g *gormTestContainers) getRunOptions(
containerReq := testcontainers.ContainerRequest{
Image: fmt.Sprintf("%s:%s", g.defaultOptions.ImageName, g.defaultOptions.Tag),
ExposedPorts: []string{g.defaultOptions.Port},
WaitingFor: wait.ForListeningPort(nat.Port(g.defaultOptions.Port)),
WaitingFor: wait.ForListeningPort(nat.Port(g.defaultOptions.Port)).WithPollInterval(2 * time.Second),
Hostname: g.defaultOptions.Host,
SkipReaper: true,
Env: map[string]string{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/docker/go-connections/nat"
"github.com/testcontainers/testcontainers-go"
Expand Down Expand Up @@ -69,7 +70,11 @@ func (g *mongoTestContainers) CreatingContainerOptions(
g.container = dbContainer

// Clean up the container after the test is complete
t.Cleanup(func() { _ = dbContainer.Terminate(ctx) })
t.Cleanup(func() {
if err := dbContainer.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})
option := &mongodb.MongoDbOptions{
User: g.defaultOptions.UserName,
Password: g.defaultOptions.Password,
Expand Down Expand Up @@ -132,7 +137,7 @@ func (g *mongoTestContainers) getRunOptions(
containerReq := testcontainers.ContainerRequest{
Image: fmt.Sprintf("%s:%s", g.defaultOptions.ImageName, g.defaultOptions.Tag),
ExposedPorts: []string{g.defaultOptions.Port},
WaitingFor: wait.ForListeningPort(nat.Port(g.defaultOptions.Port)),
WaitingFor: wait.ForListeningPort(nat.Port(g.defaultOptions.Port)).WithPollInterval(2 * time.Second),
Hostname: g.defaultOptions.Host,
SkipReaper: true,
Env: map[string]string{
Expand Down
Loading
Loading